salix/webpack.config.js

90 lines
2.3 KiB
JavaScript
Raw Normal View History

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');
let env = process.env.NODE_ENV ? process.env.NODE_ENV : 'development';
let devMode = env === 'development';
let outputPath = path.join(__dirname, wpConfig.buildDir);
let baseConfig = {
entry: wpConfig.entry,
output: {
path: outputPath,
publicPath: `${wpConfig.publicPath}/`
},
module: {
2018-02-08 12:47:54 +00:00
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/,
query: {
presets: ['es2015']
}
}, {
test: /\.yml$/,
loader: 'json-loader!yaml-loader'
}, {
test: /\.html$/,
loader: 'html-loader'
}, {
test: /\.css$/,
loader: 'style-loader!css-loader'
}, {
test: /\.scss$/,
loader: 'style-loader!css-loader!sass-loader'
}, {
2017-02-21 11:49:41 +00:00
test: /\.(svg|png|ttf|woff|woff2)$/,
loader: 'file-loader'
}
]
},
resolve: {
modules: [
2018-02-08 12:47:54 +00:00
`${__dirname}/client`,
__dirname,
2018-02-08 12:47:54 +00:00
'node_modules'
]
},
plugins: [
2017-05-16 10:37:48 +00:00
new webpack.optimize.CommonsChunkPlugin({
names: ['vendor', 'manifest']
2017-05-16 10:37:48 +00:00
})
],
devtool: 'source-map'
};
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()
]
};
let devConfig = {
output: {
filename: '[name].js',
chunkFilename: 'chunk.[id].js'
},
plugins: [
new webpack.NamedModulesPlugin()
]
};
let mrgConfig = devMode ? devConfig : prodConfig;
module.exports = merge(baseConfig, mrgConfig);