Automatically minify js files for distribution

This commit is contained in:
Dominik Perpeet 2017-07-25 12:08:13 +02:00 committed by Lars Karlitski
parent a01820e565
commit 23f2f16715
2 changed files with 26 additions and 2 deletions

View file

@ -1,6 +1,7 @@
const path = require("path");
const copy = require("copy-webpack-plugin");
const fs = require("fs");
const webpack = require("webpack");
var externals = {
"cockpit": "cockpit",
@ -13,6 +14,9 @@ const distdir = builddir + path.sep + "dist";
const section = process.env.ONLYDIR || null;
const nodedir = path.resolve((process.env.SRCDIR || __dirname), "node_modules");
/* A standard nodejs and webpack pattern */
var production = process.env.NODE_ENV === 'production';
var info = {
entries: {
"index": [
@ -73,9 +77,27 @@ info.files.forEach(function(value) {
info.files = files;
var plugins = [
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify(production ? 'production' : 'development')
}
}),
new copy(info.files)
];
/* Only minimize when in production mode */
if (production) {
plugins.unshift(new webpack.optimize.UglifyJsPlugin({
beautify: true,
compress: {
warnings: false
},
}));
/* Rename output files when minimizing */
output.filename = "[name].min.js";
}
module.exports = {
entry: info.entries,
externals: externals,