salix/webpack.config.js

119 lines
2.9 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 mode = process.env.NODE_ENV;
mode = mode == 'production' ? mode : 'development';
let outputPath = path.join(__dirname, wpConfig.buildDir);
let baseConfig = {
entry: wpConfig.entry,
mode: mode,
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: ['@babel/preset-env']
}
}, {
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')
]
}
}
]
}, {
2017-02-21 11:49:41 +00:00
test: /\.(svg|png|ttf|woff|woff2)$/,
loader: 'file-loader'
}
]
},
optimization: {
splitChunks: {
chunks: 'all',
},
runtimeChunk: true
},
resolve: {
modules: [
2018-02-08 12:47:54 +00:00
`${__dirname}/client`,
__dirname,
2018-02-08 12:47:54 +00:00
'node_modules'
2018-09-13 13:19:50 +00:00
],
alias: {
'vn-loopback': `${__dirname}/services/loopback`
}
},
plugins: [
new AssetsWebpackPlugin({
path: outputPath
2017-05-16 10:37:48 +00:00
})
],
devtool: 'source-map',
stats: {
modules: false,
colors: true
}
};
let prodConfig = {
output: {
filename: '[name].[chunkhash].js',
chunkFilename: '[id].[chunkhash].js'
},
plugins: [
new webpack.HashedModuleIdsPlugin()
],
performance: {
maxEntrypointSize: 2000000,
maxAssetSize: 2000000
}
};
let devConfig = {
output: {
filename: '[name].js',
chunkFilename: '[id].js'
},
devServer: {
host: '127.0.0.1',
port: wpConfig.devServerPort,
publicPath: '/',
contentBase: wpConfig.buildDir,
quiet: false,
noInfo: false,
// hot: true,
stats: baseConfig.stats
}
};
let mrgConfig = mode === 'production' ? prodConfig : devConfig;
module.exports = merge(baseConfig, mrgConfig);