2018-02-13 22:01:28 +00:00
|
|
|
require('require-yaml');
|
|
|
|
const webpack = require('webpack');
|
|
|
|
const path = require('path');
|
|
|
|
const merge = require('webpack-merge');
|
|
|
|
const AssetsWebpackPlugin = require('assets-webpack-plugin');
|
|
|
|
const wpConfig = require('./webpack.config.yml');
|
2017-01-31 13:13:06 +00:00
|
|
|
|
2018-02-13 22:01:28 +00:00
|
|
|
let env = process.env.NODE_ENV ? process.env.NODE_ENV : 'development';
|
|
|
|
let devMode = env === 'development';
|
|
|
|
let outputPath = path.join(__dirname, wpConfig.buildDir);
|
2017-01-31 13:13:06 +00:00
|
|
|
|
2018-02-13 22:01:28 +00:00
|
|
|
let baseConfig = {
|
|
|
|
entry: wpConfig.entry,
|
2017-01-31 13:13:06 +00:00
|
|
|
output: {
|
2018-02-13 22:01:28 +00:00
|
|
|
path: outputPath,
|
|
|
|
publicPath: `${wpConfig.publicPath}/`
|
2017-01-31 13:13:06 +00:00
|
|
|
},
|
|
|
|
module: {
|
2018-02-08 12:47:54 +00:00
|
|
|
rules: [
|
2017-01-31 13:13:06 +00:00
|
|
|
{
|
|
|
|
test: /\.js$/,
|
|
|
|
loader: 'babel-loader',
|
|
|
|
exclude: /node_modules/,
|
|
|
|
query: {
|
|
|
|
presets: ['es2015']
|
|
|
|
}
|
2018-02-04 18:39:56 +00:00
|
|
|
}, {
|
|
|
|
test: /\.yml$/,
|
|
|
|
loader: 'json-loader!yaml-loader'
|
|
|
|
}, {
|
2017-01-31 13:13:06 +00:00
|
|
|
test: /\.html$/,
|
|
|
|
loader: 'html-loader'
|
2018-02-04 18:39:56 +00:00
|
|
|
}, {
|
2017-01-31 13:13:06 +00:00
|
|
|
test: /\.css$/,
|
|
|
|
loader: 'style-loader!css-loader'
|
2018-02-04 18:39:56 +00:00
|
|
|
}, {
|
2017-01-31 13:13:06 +00:00
|
|
|
test: /\.scss$/,
|
|
|
|
loader: 'style-loader!css-loader!sass-loader'
|
2018-02-04 18:39:56 +00:00
|
|
|
}, {
|
2017-02-21 11:49:41 +00:00
|
|
|
test: /\.(svg|png|ttf|woff|woff2)$/,
|
2017-01-31 13:13:06 +00:00
|
|
|
loader: 'file-loader'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
resolve: {
|
|
|
|
modules: [
|
2018-02-08 12:47:54 +00:00
|
|
|
`${__dirname}/client`,
|
2017-01-31 13:13:06 +00:00
|
|
|
__dirname,
|
2018-02-08 12:47:54 +00:00
|
|
|
'node_modules'
|
2017-01-31 13:13:06 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
plugins: [
|
2017-05-16 10:37:48 +00:00
|
|
|
new webpack.optimize.CommonsChunkPlugin({
|
2018-02-13 22:01:28 +00:00
|
|
|
names: ['vendor', 'manifest']
|
2017-05-16 10:37:48 +00:00
|
|
|
})
|
2017-01-31 13:13:06 +00:00
|
|
|
],
|
2017-06-05 07:01:21 +00:00
|
|
|
devtool: 'source-map'
|
2017-01-31 13:13:06 +00:00
|
|
|
};
|
2018-01-29 11:37:54 +00:00
|
|
|
|
2018-02-13 22:01:28 +00:00
|
|
|
let prodConfig = {
|
|
|
|
output: {
|
|
|
|
filename: '[name].[chunkhash].js',
|
|
|
|
chunkFilename: 'chunk.[id].[chunkhash].js'
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
// FIXME: https://github.com/webpack-contrib/uglifyjs-webpack-plugin/issues/132
|
|
|
|
new webpack.optimize.UglifyJsPlugin({
|
|
|
|
minimize: true,
|
|
|
|
compress: {warnings: false}
|
|
|
|
}),
|
|
|
|
new AssetsWebpackPlugin({
|
|
|
|
path: outputPath
|
|
|
|
}),
|
|
|
|
new webpack.HashedModuleIdsPlugin()
|
|
|
|
],
|
|
|
|
devtool: 'source-map'
|
|
|
|
};
|
|
|
|
|
|
|
|
let devConfig = {
|
|
|
|
output: {
|
|
|
|
filename: '[name].js',
|
|
|
|
chunkFilename: 'chunk.[id].js'
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
new webpack.NamedModulesPlugin()
|
|
|
|
],
|
|
|
|
devtool: 'eval'
|
|
|
|
};
|
2017-01-31 13:13:06 +00:00
|
|
|
|
2018-02-13 22:01:28 +00:00
|
|
|
let mrgConfig = devMode ? devConfig : prodConfig;
|
|
|
|
module.exports = merge(baseConfig, mrgConfig);
|