Skip to content

Instantly share code, notes, and snippets.

@frank-dspeed
Forked from garima33/rollup-config.js
Last active December 31, 2018 01:30
Show Gist options
  • Select an option

  • Save frank-dspeed/becd0939598d59240c1df96ddfd7b19d to your computer and use it in GitHub Desktop.

Select an option

Save frank-dspeed/becd0939598d59240c1df96ddfd7b19d to your computer and use it in GitHub Desktop.
iife rollup
// this is the rollup plugin that adds babel as a compilation stage.
import babel from 'rollup-plugin-babel';
//Convert CommonJS modules to ES6,
// so they can be included in a Rollup bundle
import commonjs from 'rollup-plugin-commonjs';
// Locate modules using the Node resolution algorithm,
// for using third party modules in node_modules
import nodeResolve from 'rollup-plugin-node-resolve';
// Rollup plugin to minify generated bundle.
import uglify from 'rollup-plugin-uglify';
// Replace strings in files while bundling them.
import replace from 'rollup-plugin-replace';
// Serve your rolled up bundle like webpack-dev-server
// without hot reload
import serve from 'rollup-plugin-serve';
// this will refresh the browser when detect changes in bundle.
import livereload from 'rollup-plugin-livereload';
// this will create index.html file dynamically
// with the script tag pointing to bundle.
import htmlTemplate from 'rollup-plugin-generate-html-template';
// this will insert the styles into style tag in html
import postcss from 'rollup-plugin-postcss';
const baseSettings = {
experimentalCodeSplitting: true,
experimentalDynamicImport: true,
//experimentalPreserveModules: true,
input: './src/index.js',
output: {
file: './dist/bundle.js',
format: 'iife',
},
};
const plugins = [
postcss({
extensions: ['.css'],
}),
babel({
exclude: 'node_modules/**'
}),
nodeResolve({
jsnext: true
}),
commonjs({
include: 'node_modules/**',
namedExports: {
'./node_modules/react/react.js': [
'cloneElement',
'createElement',
'PropTypes',
'Children',
'Component',
],
},
}),
];
const productionConfig = Object.assign({
plugins: [
...plugins,
replace({
'process.env.NODE_ENV': JSON.stringify('production')
}),
uglify({
compress: {
screw_ie8: true,
warnings: false
},
output: {
comments: false
},
sourceMap: false
}),
]
}, baseSettings);
export const developmentConfig = Object.assign({
plugins: [
...plugins,
replace({
'process.env.NODE_ENV': JSON.stringify('development')
}),
serve({
contentBase: 'dist',
open: true
}),
htmlTemplate({
template: 'src/index.html',
target: 'dist/index.html',
}),
livereload({ watch: 'dist', }),
]
}, baseSettings);
export default developmentConfig;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment