Skip to content

workkk98/rollup-playground

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Motivation

Experiment with rollup. in particular create one file from few and also exclude.

Setup

According to the official docs it is recommended to install rollup globally
npm install --global rollup

build script

The following take all the files that main.js depend on and create using CommonJS module ('cjs') format a single file - dist/bundle.js ready to run for node application

"build": "rollup src/main.js -o dist/bundle.js -f cjs ",

start script

"start": "node dist/bundle.js"

build with rollup.config.js

some time using config file is easier

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",

using dynamic import

some time you do not want one bundle file instead you want code split. this can be done using dynamic import from side e.g.

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

watch mode : -w

this will re-bundle on changes

"build-with-config-watch": "rollup -c -w",

invoke main.js without bundle

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

Using import for npm package

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%