Skip to content

Commit

Permalink
jupyter lab build defaults to dev if any linked_packages or local_e…
Browse files Browse the repository at this point in the history
…xtensions

defaults to prod build otherwise
  • Loading branch information
telamonian committed Jul 26, 2019
1 parent 72b2d55 commit bd38818
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 43 deletions.
2 changes: 2 additions & 0 deletions dev_mode/package.json
Expand Up @@ -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",
Expand Down
19 changes: 1 addition & 18 deletions dev_mode/webpack.prod.config.js
@@ -1,28 +1,11 @@
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: true,
sourceMap: true,
terserOptions: {
compress: false,
ecma: 6,
mangle: true,
output: {
beautify: false,
comments: false
},
safari10: true
},
cache: process.platform !== 'win32'
})
]
minimize: false
}
});

Expand Down
2 changes: 1 addition & 1 deletion dev_mode/webpack.prod.minimize.config.js
Expand Up @@ -8,7 +8,7 @@ config[0] = merge(config[0], {
optimization: {
minimizer: [
new TerserPlugin({
parallel: false,
parallel: true,
sourceMap: true,
terserOptions: {
compress: false,
Expand Down
13 changes: 11 additions & 2 deletions jupyterlab/commands.py
Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions jupyterlab/labapp.py
Expand Up @@ -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.")
Expand All @@ -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)
Expand All @@ -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)
Expand Down
18 changes: 15 additions & 3 deletions jupyterlab/labextensions.py
Expand Up @@ -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()


Expand All @@ -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")
Expand All @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions jupyterlab/staging/package.json
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
3 changes: 0 additions & 3 deletions jupyterlab/staging/webpack.prod.config.js
Expand Up @@ -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
}
});
Expand Down
2 changes: 1 addition & 1 deletion jupyterlab/staging/webpack.prod.minimize.config.js
Expand Up @@ -8,7 +8,7 @@ config[0] = merge(config[0], {
optimization: {
minimizer: [
new TerserPlugin({
parallel: false,
parallel: true,
sourceMap: true,
terserOptions: {
compress: false,
Expand Down
20 changes: 15 additions & 5 deletions yarn.lock
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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==
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit bd38818

Please sign in to comment.