-
Notifications
You must be signed in to change notification settings - Fork 29
Authoring libraries
Drew Machat edited this page Aug 6, 2016
·
1 revision
Webpack can be handy for packaging your library for general consumption. You can use it to output UMD, a format that's compatible with various module loaders (CommonJS, AMD) and globals.
Especially if you are creating a library, it can be useful to output an UMD version of your library. This can be achieved using the following snippet:
output: {
path: './dist',
filename: 'mylibrary.js',
libraryTarget: 'umd',
library: 'MyLibrary',
},
In order to avoid bundling big dependencies like Angular, you'll want to use a configuration like this in addition:
externals: {
angular: 'angular',
},
Here's the basic idea:
output: {
path: './dist',
filename: 'awesomemular.min.js',
libraryTarget: 'umd',
library: 'Awesomemular',
},
plugins: [
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
},
}),
]