Skip to content

Instantly share code, notes, and snippets.

@dmorosinotto
Created September 21, 2016 13:56
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dmorosinotto/85f5928e6720378285e3ec1930b0a8ca to your computer and use it in GitHub Desktop.
Save dmorosinotto/85f5928e6720378285e3ec1930b0a8ca to your computer and use it in GitHub Desktop.
Roolup configuration for Typescript + CommonJS + production Uglify
// Rollup plugins to install as npm --save-dev
import typescript from "rollup-plugin-typescript";//used for typescript compilation
import resolve from "rollup-plugin-node-resolve"; //used for enabel NPM modules +
import commonjs from "rollup-plugin-commonjs"; //with probably use commonjs
import replace from "rollup-plugin-replace"; //used for replacing ENV varible in code
import uglify from "rollup-plugin-uglify"; //used for production minification
// import angular from "rollup-plugin-angular"; //used for Angular2 application see https://www.npmjs.com/package/rollup-plugin-angular
// Rollup configuration inspired by https://www.youtube.com/watch?v=ICYLOZuFMz8
export default {
entry: "path/to/main.ts", //entrypoint to traverse app
dest: "path/to/dist/bundle.min.js", //destination file
format: "iife", //format output wrapping all function into a single IIFE
sourceMap: "inline", //produce sourceMap and inline or maybe set sourceMap: true, sourceMapFile: 'path/for/dist/bundle.js.map'
plugins: [
typescript({
//default use tsconfig.json but can be ovverride here
//typescript: require('some-typescript-fork') //default use TS 1.8.9 but can use other specific compiler version/fork
}),
resolve({ //used to resolve NPM module reading from packages.json those entrypoint (ES6 - Main or Browser specific)
jsnext: true,
main: true,
browser: true
}),
commonjs(), //translate commonjs module to ES6 module to be handle from Rollup and tree-shake
replace({ //enable find-replacing variable in JS code to use ENV varibale for conditional code
ENV: JSON.stringify(process.env.NODE_ENV || "development") // key = var name, value = replace
}),
(process.env.NODE_ENV === "production" && uglify())
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment