From 8c0e500d6bc50849c47f05644dd9e21787114159 Mon Sep 17 00:00:00 2001 From: Mehanig Date: Wed, 24 May 2017 15:18:27 -0700 Subject: [PATCH] webpack: Migrate api and katex js files to Webpack bundler. This also injects the dev webpack sockets to katex, since that's part of the main web app bundle. --- package.json | 1 + templates/zerver/api_endpoints.html | 3 +-- templates/zerver/base.html | 2 +- tools/webpack.assets.json | 4 +++- tools/webpack.config.js | 9 +++++++-- tools/webpack.dev.config.js | 4 +++- version.py | 2 +- zproject/settings.py | 10 ---------- 8 files changed, 17 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index 8f575e4850..da37749c40 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "moment": "2.18.1", "moment-timezone": "0.5.12", "plotly.js": "1.19.2", + "script-loader": "0.7.0", "source-map-loader": "0.2.1", "string.prototype.codepointat": "0.2.0", "ts-loader": "2.1.0", diff --git a/templates/zerver/api_endpoints.html b/templates/zerver/api_endpoints.html index 8142829c6f..d904e686c5 100644 --- a/templates/zerver/api_endpoints.html +++ b/templates/zerver/api_endpoints.html @@ -4,10 +4,9 @@ {% block customhead %} {{ super() }} -{{ minified_js('api')|safe }} +{{ render_bundle('api') }} {% endblock %} - {% block portico_content %}

API endpoints documentation

diff --git a/templates/zerver/base.html b/templates/zerver/base.html index e7a8388ed9..3d6e3f330b 100644 --- a/templates/zerver/base.html +++ b/templates/zerver/base.html @@ -28,7 +28,7 @@ {% endblock %} {{ minified_js('common')|safe }} - {{ minified_js('katex')|safe }} + {{ render_bundle('katex') }} {% block customhead %} {% endblock %} diff --git a/tools/webpack.assets.json b/tools/webpack.assets.json index 87627193fc..86ee778e87 100644 --- a/tools/webpack.assets.json +++ b/tools/webpack.assets.json @@ -1,3 +1,5 @@ { - "translations": ["./static/js/translations.js"] + "api": "./static/js/portico/api.js", + "katex": ["./node_modules/katex/dist/katex.min.js"], + "translations": "./static/js/translations.js" } diff --git a/tools/webpack.config.js b/tools/webpack.config.js index acd9d7e33d..3f9e9804ce 100644 --- a/tools/webpack.config.js +++ b/tools/webpack.config.js @@ -5,7 +5,6 @@ module.exports = { context: path.resolve(__dirname, "../"), entry: assets, module: { - noParse: /(min)\.js/, rules: [ // Run the typescript compilier on .ts files before webpack { @@ -25,8 +24,14 @@ module.exports = { test: /\.tsx?$/, use: "source-map-loader", }, + // Uses script-loader on minified files so we don't change global variables in them. + // Also has the effect of making processing these files fast + { + test: /(min)\.js/, + use: [ 'script-loader' ], + }, ], - }, + }, output: { path: path.resolve(__dirname, '../static/webpack-bundles'), filename: '[name].js', diff --git a/tools/webpack.dev.config.js b/tools/webpack.dev.config.js index 1eb2b96b1a..96c381b0db 100644 --- a/tools/webpack.dev.config.js +++ b/tools/webpack.dev.config.js @@ -1,7 +1,9 @@ var config = require('./webpack.config.js'); var BundleTracker = require('webpack-bundle-tracker'); -config.entry.translations.unshift('webpack-dev-server/client?sockjs-node'); +// katex should be an array, to inject webpack dependencies in dev config +// better to be moved to common.js when common.js is added to assets +config.entry.katex.unshift('webpack-dev-server/client?/sockjs-node'); config.devtool = 'eval'; config.output.publicPath = '/webpack/'; config.plugins.push(new BundleTracker({filename: 'static/webpack-bundles/webpack-stats-dev.json'})); diff --git a/version.py b/version.py index 4b44bae8bf..6ccabab456 100644 --- a/version.py +++ b/version.py @@ -1,2 +1,2 @@ ZULIP_VERSION = "1.6.0+git" -PROVISION_VERSION = '5.4' +PROVISION_VERSION = '5.5' diff --git a/zproject/settings.py b/zproject/settings.py index fc689a11ff..a22e248a30 100644 --- a/zproject/settings.py +++ b/zproject/settings.py @@ -841,10 +841,6 @@ JS_SPECS = { ], 'output_filename': 'min/zxcvbn.js' }, - 'api': { - 'source_filenames': ['js/portico/api.js'], - 'output_filename': 'min/api.js' - }, 'app_debug': { 'source_filenames': ['js/debug.js'], 'output_filename': 'min/app_debug.js' @@ -1023,12 +1019,6 @@ JS_SPECS = { 'sockjs': { 'source_filenames': ['third/sockjs/sockjs-0.3.4.js'], 'output_filename': 'min/sockjs-0.3.4.min.js' - }, - 'katex': { - 'source_filenames': [ - 'node_modules/katex/dist/katex.js', - ], - 'output_filename': 'min/katex.js' } }