From bd3881809e1976ffd593924801e2ed41fc5e4f53 Mon Sep 17 00:00:00 2001 From: telamonian Date: Mon, 22 Jul 2019 21:40:42 -0400 Subject: [PATCH] `jupyter lab build` defaults to dev if any linked_packages or local_extensions defaults to prod build otherwise --- dev_mode/package.json | 2 ++ dev_mode/webpack.prod.config.js | 19 +----------------- dev_mode/webpack.prod.minimize.config.js | 2 +- jupyterlab/commands.py | 13 ++++++++++-- jupyterlab/labapp.py | 20 +++++++++---------- jupyterlab/labextensions.py | 18 ++++++++++++++--- jupyterlab/staging/package.json | 3 +++ jupyterlab/staging/webpack.prod.config.js | 3 --- .../staging/webpack.prod.minimize.config.js | 2 +- yarn.lock | 20 ++++++++++++++----- 10 files changed, 59 insertions(+), 43 deletions(-) diff --git a/dev_mode/package.json b/dev_mode/package.json index de4b6f5d70c5..050bb0b06060 100644 --- a/dev_mode/package.json +++ b/dev_mode/package.json @@ -4,6 +4,8 @@ "private": true, "scripts": { "build": "webpack", + "build:dev": "jlpm run build", + "build:dev:minimize": "jlpm run build:dev", "build:prod": "cross-env NODE_OPTIONS=--max_old_space_size=4096 webpack --config webpack.prod.config.js", "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", diff --git a/dev_mode/webpack.prod.config.js b/dev_mode/webpack.prod.config.js index 9f91ed057c35..a48980bcdaeb 100644 --- a/dev_mode/webpack.prod.config.js +++ b/dev_mode/webpack.prod.config.js @@ -1,4 +1,3 @@ -const TerserPlugin = require('terser-webpack-plugin'); var merge = require('webpack-merge'); var config = require('./webpack.config'); @@ -6,23 +5,7 @@ config[0] = merge(config[0], { mode: 'production', devtool: 'source-map', optimization: { - minimizer: [ - new TerserPlugin({ - parallel: true, - sourceMap: true, - terserOptions: { - compress: false, - ecma: 6, - mangle: true, - output: { - beautify: false, - comments: false - }, - safari10: true - }, - cache: process.platform !== 'win32' - }) - ] + minimize: false } }); diff --git a/dev_mode/webpack.prod.minimize.config.js b/dev_mode/webpack.prod.minimize.config.js index a4aee1cc7575..9f91ed057c35 100644 --- a/dev_mode/webpack.prod.minimize.config.js +++ b/dev_mode/webpack.prod.minimize.config.js @@ -8,7 +8,7 @@ config[0] = merge(config[0], { optimization: { minimizer: [ new TerserPlugin({ - parallel: false, + parallel: true, sourceMap: true, terserOptions: { compress: false, diff --git a/jupyterlab/commands.py b/jupyterlab/commands.py index 36a7388099a2..62475396870f 100644 --- a/jupyterlab/commands.py +++ b/jupyterlab/commands.py @@ -534,10 +534,19 @@ def install_extension(self, extension, existing=None): return True def build(self, name=None, version=None, static_url=None, - command='build:prod', clean_staging=False): + command='build:prod:minimize', clean_staging=False): """Build the application. """ - self.logger.info('Building jupyterlab assets') + # resolve the build type + parts = command.split(':') + if len(parts) < 2: + parts.append('dev') + elif parts[1] == 'none': + parts[1] = ('dev' if self.info['linked_packages'] or self.info['local_extensions'] else + 'prod') + command = ':'.join(parts) + + self.logger.info(f'Building jupyterlab assets ({command})') # Set up the build directory. app_dir = self.app_dir diff --git a/jupyterlab/labapp.py b/jupyterlab/labapp.py index 9c7ce84c84c4..a79cf8ff7e7b 100644 --- a/jupyterlab/labapp.py +++ b/jupyterlab/labapp.py @@ -62,8 +62,8 @@ class LabBuildApp(JupyterApp, DebugLogFileMixin): version = Unicode('', config=True, help="The version of the built application") - dev_build = Bool(False, config=True, - help="Whether to build in dev mode (defaults to prod mode)") + dev_build = Bool(None, allow_none=True, config=True, + help="Whether to build in dev mode. Defaults to True (dev mode) if there are any locally linked extensions, else defaults to False (prod mode).") minimize = Bool(True, config=True, help="Whether to use a minifier during the Webpack build (defaults to True). Only affects production builds.") @@ -72,13 +72,13 @@ class LabBuildApp(JupyterApp, DebugLogFileMixin): help="Whether to clean before building (defaults to False)") def start(self): - if self.dev_build: - command = 'build' - else: - if self.minimize: - command = 'build:prod:minimize' - else: - command = 'build:prod' + parts = ['build'] + parts.append('none' if self.dev_build is None else + 'dev' if self.dev_build else + 'prod') + if self.minimize: + parts.append('minimize') + command = ':'.join(parts) app_dir = self.app_dir or get_app_dir() self.log.info('JupyterLab %s', version) @@ -88,7 +88,7 @@ def start(self): clean(self.app_dir) self.log.info('Building in %s', app_dir) build(app_dir=app_dir, name=self.name, version=self.version, - command=command, logger=self.log) + command=command, logger=self.log) clean_aliases = dict(base_aliases) diff --git a/jupyterlab/labextensions.py b/jupyterlab/labextensions.py index 54f8a654c0d9..bc5071a2c030 100644 --- a/jupyterlab/labextensions.py +++ b/jupyterlab/labextensions.py @@ -53,8 +53,10 @@ aliases = dict(base_aliases) aliases['app-dir'] = 'BaseExtensionApp.app_dir' aliases['dev-build'] = 'BaseExtensionApp.dev_build' +aliases['minimize'] = 'BaseExtensionApp.minimize' aliases['debug-log-path'] = 'DebugLogFileMixin.debug_log_path' + VERSION = get_app_version() @@ -69,8 +71,11 @@ class BaseExtensionApp(JupyterApp, DebugLogFileMixin): should_build = Bool(True, config=True, help="Whether to build the app after the action") - dev_build = Bool(False, config=True, - help="Whether to build in dev mode (defaults to prod mode)") + dev_build = Bool(None, allow_none=True, config=True, + help="Whether to build in dev mode. Defaults to True (dev mode) if there are any locally linked extensions, else defaults to False (prod mode).") + + minimize = Bool(True, config=True, + help="Whether to use a minifier during the Webpack build (defaults to True). Only affects production builds.") should_clean = Bool(False, config=True, help="Whether temporary files should be cleaned up after building jupyterlab") @@ -81,7 +86,14 @@ def start(self): with self.debug_logging(): ans = self.run_task() if ans and self.should_build: - command = 'build:prod' if not self.dev_build else 'build' + parts = ['build'] + parts.append('none' if self.dev_build is None else + 'dev' if self.dev_build else + 'prod') + if self.minimize: + parts.append('minimize') + command = ':'.join(parts) + build(app_dir=self.app_dir, clean_staging=self.should_clean, logger=self.log, command=command) diff --git a/jupyterlab/staging/package.json b/jupyterlab/staging/package.json index f500ccab6b7c..1cd520ac955b 100644 --- a/jupyterlab/staging/package.json +++ b/jupyterlab/staging/package.json @@ -4,6 +4,8 @@ "private": true, "scripts": { "build": "webpack", + "build:dev": "jlpm run build", + "build:dev:minimize": "jlpm run build:dev", "build:prod": "cross-env NODE_OPTIONS=--max_old_space_size=4096 webpack --config webpack.prod.config.js", "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", @@ -106,6 +108,7 @@ "svg-url-loader": "~2.3.2", "svgo": "~1.2.1", "svgo-loader": "~2.2.0", + "terser-webpack-plugin": "^1.3.0", "url-loader": "~1.1.2", "webpack": "^4.32.2", "webpack-cli": "^3.3.0", diff --git a/jupyterlab/staging/webpack.prod.config.js b/jupyterlab/staging/webpack.prod.config.js index c6892cffd3bf..a48980bcdaeb 100644 --- a/jupyterlab/staging/webpack.prod.config.js +++ b/jupyterlab/staging/webpack.prod.config.js @@ -5,9 +5,6 @@ config[0] = merge(config[0], { mode: 'production', devtool: 'source-map', optimization: { - // As of terser-webpack-plugin@1.3.0, - // the JupyterLab codebase plus its optional extensions is too big to be minified. - // Even with sourceMap and mangling disabled. And even with `node --max_old_space_size=4096`. minimize: false } }); diff --git a/jupyterlab/staging/webpack.prod.minimize.config.js b/jupyterlab/staging/webpack.prod.minimize.config.js index a4aee1cc7575..9f91ed057c35 100644 --- a/jupyterlab/staging/webpack.prod.minimize.config.js +++ b/jupyterlab/staging/webpack.prod.minimize.config.js @@ -8,7 +8,7 @@ config[0] = merge(config[0], { optimization: { minimizer: [ new TerserPlugin({ - parallel: false, + parallel: true, sourceMap: true, terserOptions: { compress: false, diff --git a/yarn.lock b/yarn.lock index 252bdcf304e0..fcf7e318b044 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5649,6 +5649,11 @@ fs.realpath@^1.0.0: resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" integrity sha1-FQStJSMVjKpA20onh8sBQRmU6k8= +fs@~0.0.1-security: + version "0.0.1-security" + resolved "https://registry.yarnpkg.com/fs/-/fs-0.0.1-security.tgz#8a7bd37186b6dddf3813f23858b57ecaaf5e41d4" + integrity sha1-invTcYa23d84E/I4WLV+yq9eQdQ= + fsevents@^1.2.7: version "1.2.9" resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-1.2.9.tgz#3f5ed66583ccd6f400b5a00db6f7e861363e388f" @@ -7617,7 +7622,7 @@ karma-ie-launcher@^1.0.0: resolved "https://registry.yarnpkg.com/karma-ie-launcher/-/karma-ie-launcher-1.0.0.tgz#497986842c490190346cd89f5494ca9830c6d59c" integrity sha1-SXmGhCxJAZA0bNifVJTKmDDG1Zw= dependencies: - lodash "^4.6.2" + lodash "^4.6.1" karma-mocha-reporter@^2.2.5: version "2.2.5" @@ -8027,9 +8032,9 @@ lodash.isstring@^4.0.1: resolved "https://registry.yarnpkg.com/lodash.isstring/-/lodash.isstring-4.0.1.tgz#d527dfb5456eca7cc9bb95d5daeaf88ba54a5451" integrity sha1-1SfftUVuynzJu5XV2ur4i6VKVFE= -lodash.mergewith@^4.6.2: +lodash.mergewith@^4.6.1: version "4.6.2" - resolved "https://registry.npmjs.org/lodash.mergewith/-/lodash.mergewith-4.6.2.tgz#617121f89ac55f59047c7aec1ccd6654c6590f55" + resolved "https://registry.yarnpkg.com/lodash.mergewith/-/lodash.mergewith-4.6.2.tgz#617121f89ac55f59047c7aec1ccd6654c6590f55" integrity sha512-GK3g5RPZWTRSeLSpgP8Xhra+pnjBC56q9FZYe1d5RN3TJ35dbkGy3YqBSMbyCrlbi+CM9Z3Jk5yTL7RCsqboyQ== lodash.set@^4.3.2: @@ -8062,7 +8067,7 @@ lodash.uniq@^4.5.0: resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773" integrity sha1-0CJTc662Uq3BvILklFM5qEJ1R3M= -lodash@^4.0.0, lodash@^4.17.0, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.3, lodash@^4.17.4, lodash@^4.17.5, lodash@^4.2.1, lodash@^4.6.2: +lodash@^4.0.0, lodash@^4.17.0, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.3, lodash@^4.17.4, lodash@^4.17.5, lodash@^4.2.1: version "4.17.11" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d" integrity sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg== @@ -8072,6 +8077,11 @@ lodash@^4.3.0: resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.13.tgz#0bdc3a6adc873d2f4e0c4bac285df91b64fc7b93" integrity sha512-vm3/XWXfWtRua0FkUyEHBZy8kCPjErNBT9fJx8Zvs+U6zjqPbTUOpkaoum3O5uiA8sm+yNMHXfYkTUHFoMxFNA== +lodash@^4.6.1: + version "4.17.15" + resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548" + integrity sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A== + log-symbols@2.2.0, log-symbols@^2.1.0, log-symbols@^2.2.0: version "2.2.0" resolved "https://registry.yarnpkg.com/log-symbols/-/log-symbols-2.2.0.tgz#5740e1c5d6f0dfda4ad9323b5332107ef6b4c40a" @@ -10689,7 +10699,7 @@ sanitize-html@~1.20.1: lodash.escaperegexp "^4.1.2" lodash.isplainobject "^4.0.6" lodash.isstring "^4.0.1" - lodash.mergewith "^4.6.2" + lodash.mergewith "^4.6.1" postcss "^7.0.5" srcset "^1.0.0" xtend "^4.0.1"