Choices/webpack.config.prod.js

79 lines
2 KiB
JavaScript
Raw Normal View History

const path = require('path');
const pkg = require('./package.json');
const webpack = require('webpack');
2017-11-15 07:51:53 +01:00
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/choices',
2017-11-06 23:06:38 +01:00
],
2016-09-15 22:04:15 +02:00
output: {
2018-05-25 15:00:27 +02:00
path: path.join(__dirname, '/public/assets/scripts'),
2017-11-06 23:06:38 +01:00
filename: minimize ? 'choices.min.js' : 'choices.js',
2018-05-25 15:00:27 +02:00
publicPath: '/public/assets/scripts/',
2017-11-06 23:06:38 +01:00
library: 'Choices',
libraryTarget: 'umd',
2017-11-15 07:51:53 +01:00
auxiliaryComment: {
root: 'Window',
commonjs: 'CommonJS',
commonjs2: 'CommonJS2',
amd: 'AMD',
},
2017-11-06 23:06:38 +01:00
},
plugins: [
new webpack.optimize.ModuleConcatenationPlugin(),
new webpack.DefinePlugin({
'process.env': {
// This has effect on the react lib size
2017-11-15 07:51:53 +01:00
NODE_ENV: JSON.stringify('production'),
},
2017-11-06 23:06:38 +01:00
}),
2017-11-15 07:51:53 +01:00
new WrapperPlugin({
2017-11-06 23:06:38 +01:00
header: banner,
}),
],
module: {
2017-11-15 07:51:53 +01:00
rules: [
{
enforce: 'pre',
test: /\.js?$/,
include: path.join(__dirname, 'src/scripts'),
2017-11-15 07:51:53 +01:00
exclude: /(node_modules|bower_components)/,
loader: 'eslint-loader',
query: {
configFile: '.eslintrc',
},
2017-11-06 23:06:38 +01:00
},
2017-11-15 07:51:53 +01:00
{
test: /\.js?$/,
include: path.join(__dirname, 'src/scripts'),
2017-11-15 07:51:53 +01:00
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader',
},
],
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: {
2017-11-15 07:51:53 +01:00
comments: false,
2017-11-06 23:06:38 +01:00
},
compress: {
warnings: false,
2017-11-15 07:51:53 +01:00
screw_ie8: true,
},
2017-11-06 23:06:38 +01:00
}));
}
return config;
};