Automatically minify js files for distribution
This commit is contained in:
parent
a01820e565
commit
23f2f16715
2 changed files with 26 additions and 2 deletions
6
Makefile
6
Makefile
|
|
@ -1,5 +1,5 @@
|
||||||
all:
|
all:
|
||||||
npm run build
|
NODE_ENV=$(NODE_ENV) npm run build
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf dist/
|
rm -rf dist/
|
||||||
|
|
@ -9,7 +9,9 @@ install: all
|
||||||
mkdir -p /usr/share/cockpit/subscription-manager
|
mkdir -p /usr/share/cockpit/subscription-manager
|
||||||
cp -r dist/* /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
|
mkdir -p _install/usr/share/cockpit
|
||||||
cp -r dist/ _install/usr/share/cockpit/subscription-manager
|
cp -r dist/ _install/usr/share/cockpit/subscription-manager
|
||||||
mkdir -p _install/usr/share/metainfo/
|
mkdir -p _install/usr/share/metainfo/
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const copy = require("copy-webpack-plugin");
|
const copy = require("copy-webpack-plugin");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
|
const webpack = require("webpack");
|
||||||
|
|
||||||
var externals = {
|
var externals = {
|
||||||
"cockpit": "cockpit",
|
"cockpit": "cockpit",
|
||||||
|
|
@ -13,6 +14,9 @@ const distdir = builddir + path.sep + "dist";
|
||||||
const section = process.env.ONLYDIR || null;
|
const section = process.env.ONLYDIR || null;
|
||||||
const nodedir = path.resolve((process.env.SRCDIR || __dirname), "node_modules");
|
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 = {
|
var info = {
|
||||||
entries: {
|
entries: {
|
||||||
"index": [
|
"index": [
|
||||||
|
|
@ -73,9 +77,27 @@ info.files.forEach(function(value) {
|
||||||
info.files = files;
|
info.files = files;
|
||||||
|
|
||||||
var plugins = [
|
var plugins = [
|
||||||
|
new webpack.DefinePlugin({
|
||||||
|
'process.env': {
|
||||||
|
'NODE_ENV': JSON.stringify(production ? 'production' : 'development')
|
||||||
|
}
|
||||||
|
}),
|
||||||
new copy(info.files)
|
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 = {
|
module.exports = {
|
||||||
entry: info.entries,
|
entry: info.entries,
|
||||||
externals: externals,
|
externals: externals,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue