Skip to content

Commit

Permalink
added explicit minimize option to lab build
Browse files Browse the repository at this point in the history
  • Loading branch information
telamonian committed Jul 26, 2019
1 parent bfb361f commit 72b2d55
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 3 deletions.
3 changes: 2 additions & 1 deletion dev_mode/package.json
Expand Up @@ -5,7 +5,8 @@
"scripts": {
"build": "webpack",
"build:prod": "cross-env NODE_OPTIONS=--max_old_space_size=4096 webpack --config webpack.prod.config.js",
"build:prod:stats": "cross-env NODE_OPTIONS=--max_old_space_size=4096 webpack --profile --config webpack.prod.config.js --json > stats.json",
"build:prod:minimize": "cross-env NODE_OPTIONS=--max_old_space_size=4096 webpack --config webpack.prod.minimize.config.js",
"build:prod:stats": "cross-env NODE_OPTIONS=--max_old_space_size=4096 webpack --profile --config webpack.prod.minimize.config.js --json > stats.json",
"build:stats": "webpack --profile --json > stats.json",
"clean": "rimraf build",
"prepublishOnly": "npm run build",
Expand Down
29 changes: 29 additions & 0 deletions dev_mode/webpack.prod.minimize.config.js
@@ -0,0 +1,29 @@
const TerserPlugin = require('terser-webpack-plugin');
var merge = require('webpack-merge');
var config = require('./webpack.config');

config[0] = merge(config[0], {
mode: 'production',
devtool: 'source-map',
optimization: {
minimizer: [
new TerserPlugin({
parallel: false,
sourceMap: true,
terserOptions: {
compress: false,
ecma: 6,
mangle: true,
output: {
beautify: false,
comments: false
},
safari10: true
},
cache: process.platform !== 'win32'
})
]
}
});

module.exports = config;
1 change: 1 addition & 0 deletions jupyterlab/commands.py
Expand Up @@ -990,6 +990,7 @@ def _populate_staging(self, name=None, version=None, static_url=None,

for fname in ['index.js', 'webpack.config.js',
'webpack.prod.config.js',
'webpack.prod.minimize.config.js',
'.yarnrc', 'yarn.js']:
target = pjoin(staging, fname)
shutil.copy(pjoin(HERE, 'staging', fname), target)
Expand Down
13 changes: 12 additions & 1 deletion jupyterlab/labapp.py
Expand Up @@ -30,6 +30,7 @@
build_aliases['name'] = 'LabBuildApp.name'
build_aliases['version'] = 'LabBuildApp.version'
build_aliases['dev-build'] = 'LabBuildApp.dev_build'
build_aliases['minimize'] = 'LabBuildApp.minimize'
build_aliases['debug-log-path'] = 'DebugLogFileMixin.debug_log_path'

build_flags = dict(flags)
Expand Down Expand Up @@ -64,11 +65,21 @@ class LabBuildApp(JupyterApp, DebugLogFileMixin):
dev_build = Bool(False, config=True,
help="Whether to build in dev mode (defaults to prod mode)")

minimize = Bool(True, config=True,
help="Whether to use a minifier during the Webpack build (defaults to True). Only affects production builds.")

pre_clean = Bool(False, config=True,
help="Whether to clean before building (defaults to False)")

def start(self):
command = 'build:prod' if not self.dev_build else 'build'
if self.dev_build:
command = 'build'
else:
if self.minimize:
command = 'build:prod:minimize'
else:
command = 'build:prod'

app_dir = self.app_dir or get_app_dir()
self.log.info('JupyterLab %s', version)
with self.debug_logging():
Expand Down
3 changes: 2 additions & 1 deletion jupyterlab/staging/package.json
Expand Up @@ -5,7 +5,8 @@
"scripts": {
"build": "webpack",
"build:prod": "cross-env NODE_OPTIONS=--max_old_space_size=4096 webpack --config webpack.prod.config.js",
"build:prod:stats": "cross-env NODE_OPTIONS=--max_old_space_size=4096 webpack --profile --config webpack.prod.config.js --json > stats.json",
"build:prod:minimize": "cross-env NODE_OPTIONS=--max_old_space_size=4096 webpack --config webpack.prod.minimize.config.js",
"build:prod:stats": "cross-env NODE_OPTIONS=--max_old_space_size=4096 webpack --profile --config webpack.prod.minimize.config.js --json > stats.json",
"build:stats": "webpack --profile --json > stats.json",
"clean": "rimraf build",
"prepublishOnly": "npm run build",
Expand Down
29 changes: 29 additions & 0 deletions jupyterlab/staging/webpack.prod.minimize.config.js
@@ -0,0 +1,29 @@
const TerserPlugin = require('terser-webpack-plugin');
var merge = require('webpack-merge');
var config = require('./webpack.config');

config[0] = merge(config[0], {
mode: 'production',
devtool: 'source-map',
optimization: {
minimizer: [
new TerserPlugin({
parallel: false,
sourceMap: true,
terserOptions: {
compress: false,
ecma: 6,
mangle: true,
output: {
beautify: false,
comments: false
},
safari10: true
},
cache: process.platform !== 'win32'
})
]
}
});

module.exports = config;

0 comments on commit 72b2d55

Please sign in to comment.