diff --git a/tools/run-dev.py b/tools/run-dev.py index 90d15d2d42..529b006324 100755 --- a/tools/run-dev.py +++ b/tools/run-dev.py @@ -55,6 +55,10 @@ parser.add_option('--test', action='store_true', dest='test', help='Use the testing database and ports') +parser.add_option('--minify', + action='store_true', dest='minify', + help='Minifies assets for testing in dev') + parser.add_option('--interface', action='store', dest='interface', default=None, help='Set the IP or hostname for the proxy to listen on') @@ -186,7 +190,10 @@ if options.test: # for the Casper tests. subprocess.check_call('./tools/webpack') else: - cmds += [['./tools/webpack', '--watch', '--port', str(webpack_port)]] + webpack_cmd = ['./tools/webpack', '--watch', '--port', str(webpack_port)] + if options.minify: + webpack_cmd.append('--minify') + cmds.append(webpack_cmd) for cmd in cmds: subprocess.Popen(cmd) diff --git a/tools/webpack b/tools/webpack index eb5063ed09..4a4302b6b5 100755 --- a/tools/webpack +++ b/tools/webpack @@ -25,11 +25,14 @@ def run(): subprocess.check_call(['node', 'node_modules/.bin/webpack'] + ['--config', 'tools/webpack.production.config.js', '-p']) -def run_watch(port): - # type: (str) -> None +def run_watch(port, minify): + # type: (str, bool) -> None """watches and rebuilds on changes, serving files from memory via webpack-dev-server""" - subprocess.Popen(['node', 'node_modules/.bin/webpack-dev-server'] + - ['--config', 'tools/webpack.dev.config.js', '--watch-poll', '--port', port]) + webpack_args = ['node', 'node_modules/.bin/webpack-dev-server'] + webpack_args += ['--config', 'tools/webpack.dev.config.js', '--watch-poll', '--port', port] + if minify: + webpack_args.append('--optimize-minimize') + subprocess.Popen(webpack_args) def run_test(): # type: () -> None @@ -63,11 +66,14 @@ parser.add_argument('--watch', parser.add_argument('--port', action='store', dest='port', default='9994', help='set the port for the webpack server to run on') +parser.add_argument('--minify', + action='store_true', dest='minify', default=False, + help='Minify and optimize the assets (for development)') args = parser.parse_args() if args.test: run_test() elif args.watch: - run_watch(args.port) + run_watch(args.port, args.minify) else: run() diff --git a/zproject/settings.py b/zproject/settings.py index b10675b4b7..88a6051c8a 100644 --- a/zproject/settings.py +++ b/zproject/settings.py @@ -67,7 +67,8 @@ ZULIP_ORG_KEY = get_secret("zulip_org_key") ZULIP_ORG_ID = get_secret("zulip_org_id") if 'DEBUG' not in globals(): - # Uncomment end of next line to test JS/CSS minification. + # Uncomment end of next line to test CSS minification. + # For webpack JS minification use tools/run_dev.py --minify DEBUG = DEVELOPMENT # and platform.node() != 'your-machine' if DEBUG: