Automatically minify js files for distribution

This commit is contained in:
Dominik Perpeet 2017-07-25 12:08:13 +02:00
parent 0fff29e6cb
commit f90fd688bf
2 changed files with 26 additions and 2 deletions

View file

@ -1,5 +1,5 @@
all:
npm run build
NODE_ENV=$(NODE_ENV) npm run build
clean:
rm -rf dist/
@ -9,7 +9,9 @@ install: all
mkdir -p /usr/share/cockpit/subscription-manager
cp -r dist/* /usr/share/cockpit/subscription-manager
dist-gzip: all
# when building a distribution tarball, call webpack with a 'production' environment
dist-gzip: NODE_ENV=production
dist-gzip: clean all
mkdir -p _install/usr/share/cockpit
cp -r dist/ _install/usr/share/cockpit/subscription-manager
mkdir -p _install/usr/share/metainfo/

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,