salix/webpack.config.js

104 lines
2.8 KiB
JavaScript

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: {
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$/,
use: [
{loader: 'style-loader'},
{loader: 'css-loader'},
{
loader: 'sass-loader',
options: {
includePaths: [
path.resolve(__dirname, 'client/salix/src/styles')
]
}
}
]
}, {
test: /\.(svg|png|ttf|woff|woff2)$/,
loader: 'file-loader'
}
]
},
resolve: {
modules: [
`${__dirname}/client`,
__dirname,
'node_modules'
],
alias: {
'vn-loopback': `${__dirname}/services/loopback`
}
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({
names: ['vendor', 'manifest']
})
],
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);