npm install --global rollup
"build": "rollup src/main.js -o dist/bundle.js -f cjs ",
"start": "node dist/bundle.js"
export default {
input: 'src/main.js',
output: {
file: 'dist/bundle.js',
format: 'cjs'
}
};
and to invoke it simple use
npm run build-with-config
remark - this is working is you add the following to package.json
"type": "module",
const { mul } = await import("./utils-b.js");
and on the other side . es is used because the format cjs can not handle it
"build1": "rollup src/main-with-dynamic-import.js -d dist1 -f es ",
the result is dist1 directory with two files : main-with-dynamic-import.js and utils-b-281616f2.js
this will re-bundle on changes
"build-with-config-watch": "rollup -c -w",
this is possible provided you will import using .js i.e. import {sum} from './utils.js' not import {sum} from './utils'
and add the following to package.json
"type": "module",
than invoke
npm run dev
add in rollup.config.js
external: ['dayjs']
note that this will NOT change dist directory . dayjs will be used fron regular node_modules directory. This may be good for development but not production