78 lines
1.8 KiB
JavaScript
78 lines
1.8 KiB
JavaScript
const path = require('path');
|
|
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
|
|
const webpack = require('webpack');
|
|
|
|
module.exports = (config) => {
|
|
|
|
if ('production' === config.mode) {
|
|
return [config, module.exports.webpackConfig()];
|
|
}
|
|
else {
|
|
return config;
|
|
}
|
|
};
|
|
|
|
const SOURCE_PATH = process.env.SOURCE_PATH || '/var/node/src';
|
|
const OUTPUT_PATH = process.env.OUTPUT_PATH || '/var/node/dist';
|
|
|
|
module.exports.webpackConfig = function() {
|
|
|
|
const config = {
|
|
mode: 'production' !== process.env.NODE_ENV ? 'development' : 'production',
|
|
entry: [
|
|
'@babel/polyfill',
|
|
path.join(SOURCE_PATH, 'frontend', 'index.js'),
|
|
],
|
|
optimization: {},
|
|
module: {
|
|
rules: [
|
|
{
|
|
test: /\.js$/,
|
|
exclude: /(node_modules|bower_components)/,
|
|
use: {
|
|
loader: 'babel-loader',
|
|
options: {
|
|
babelrcRoots: [
|
|
OUTPUT_PATH,
|
|
],
|
|
plugins: [
|
|
'@babel/plugin-proposal-object-rest-spread',
|
|
],
|
|
presets: [
|
|
'@babel/preset-react',
|
|
'@babel/preset-env',
|
|
],
|
|
},
|
|
},
|
|
},
|
|
],
|
|
},
|
|
output: {
|
|
filename: 'index.js',
|
|
path: path.join(OUTPUT_PATH, 'frontend'),
|
|
},
|
|
plugins: [
|
|
new HtmlWebpackPlugin({
|
|
title: 'Truss',
|
|
template: path.join(SOURCE_PATH, 'frontend', 'index.html'),
|
|
}),
|
|
],
|
|
resolve: {
|
|
modules: [path.join(OUTPUT_PATH, 'node_modules')],
|
|
}
|
|
};
|
|
|
|
if ('production' === config.mode) {
|
|
config.optimization.minimizer = [
|
|
new UglifyJsPlugin({cache: false})
|
|
];
|
|
}
|
|
else {
|
|
config.plugins.push(new webpack.HotModuleReplacementPlugin());
|
|
}
|
|
|
|
return config;
|
|
}
|