Choices/webpack.config.prod.js

64 lines
1.6 KiB
JavaScript
Raw Normal View History

const path = require('path');
const pkg = require('./package.json');
const webpack = require('webpack');
const wrapperPlugin = require('wrapper-webpack-plugin');
const banner = `/*! ${ pkg.name } v${ pkg.version } | (c) ${ new Date().getFullYear() } ${ pkg.author } | ${ pkg.homepage } */ \n`;
2016-03-15 23:42:10 +01:00
2017-11-06 23:06:38 +01:00
module.exports = (env) => {
const minimize = !!(env && env.minimize);
2016-08-23 08:24:45 +02:00
2017-11-06 23:06:38 +01:00
const config = {
devtool: minimize ? false : 'cheap-module-source-map',
entry: [
'./src/scripts/src/choices'
],
2016-09-15 22:04:15 +02:00
output: {
2017-11-06 23:06:38 +01:00
path: path.join(__dirname, '/src/scripts/dist'),
filename: minimize ? 'choices.min.js' : 'choices.js',
publicPath: '/src/scripts/dist/',
library: 'Choices',
libraryTarget: 'umd',
},
plugins: [
new webpack.optimize.ModuleConcatenationPlugin(),
new webpack.DefinePlugin({
'process.env': {
// This has effect on the react lib size
'NODE_ENV': JSON.stringify('production'),
}
}),
new wrapperPlugin({
header: banner,
}),
],
module: {
rules: [{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader',
include: path.join(__dirname, 'src/scripts/src'),
options: {
babelrc: false,
presets: [['es2015', { modules: false }], 'stage-2'],
},
}],
2016-09-15 22:04:15 +02:00
},
2017-11-06 23:06:38 +01:00
};
2016-08-23 08:24:45 +02:00
2017-11-06 23:06:38 +01:00
if (minimize) {
config.plugins.unshift(new webpack.optimize.UglifyJsPlugin({
sourceMap: false,
mangle: true,
output: {
comments: false
},
compress: {
warnings: false,
screw_ie8: true
}
}));
}
return config;
};