Edit: Added plugins configuration for more clarity
I am using uuid
package in a rollup project. At first I was getting a warning for external dependency crypto. So I added external
and output.globals
in my rollup configuration:
export default [{
input: '/path/to/input.js',
external: ['crypto'],
output: {
file: '/path/to/output.esm.js',
format: 'esm',
...
globals: {
crypto: 'crypto'
}
},
plugins: [
resolve({
customResolveOptions: {
moduleDirectory: 'node_modules'
},
preferBuiltins: true
}),
commonjs({
namedExports: {
uuid: ['v4']
}
})
]
}];
The warning is gone, but now I have an import statement in my output file:
output.esm.js
import crypto from 'crypto';
...
My question is will this work if I include output.esm.js
in browser?
<script type="module" src="/path/to/output.esm.js"></script>
@rollup/plugin-node-resolve
? If yes, can you show its config? – Deloris