Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix lab build prod #6907

Merged
merged 4 commits into from Aug 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion dev_mode/package.json
Expand Up @@ -4,8 +4,11 @@
"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: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
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
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: true,
sourceMap: true,
terserOptions: {
compress: false,
ecma: 6,
mangle: true,
output: {
beautify: false,
comments: false
},
safari10: true
},
cache: process.platform !== 'win32'
})
]
}
});

module.exports = config;
14 changes: 12 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 Expand Up @@ -990,6 +999,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
19 changes: 15 additions & 4 deletions 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 @@ -61,14 +62,24 @@ class LabBuildApp(JupyterApp, DebugLogFileMixin):
version = Unicode('', config=True,
help="The version of the built application")

dev_build = Bool(True, config=True,
help="Whether to build in dev mode (defaults to dev 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.")

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'
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)
with self.debug_logging():
Expand All @@ -77,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(True, config=True,
help="Whether to build in dev mode (defaults to dev 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
5 changes: 4 additions & 1 deletion jupyterlab/staging/package.json
Expand Up @@ -4,8 +4,11 @@
"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: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
19 changes: 1 addition & 18 deletions jupyterlab/staging/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
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: true,
sourceMap: true,
terserOptions: {
compress: false,
ecma: 6,
mangle: true,
output: {
beautify: false,
comments: false
},
safari10: true
},
cache: process.platform !== 'win32'
})
]
}
});

module.exports = config;