webpack: Move webpack.config.ts to top level.

We lost the war against top level configuration files many moons ago.
This is what developers and tools expect.  And it seems to be required
for eslint-import-resolver-webpack (there’s ostensibly a {"config":
"tools/webpack.config.ts"} option, but it doesn’t work correctly:
https://github.com/benmosher/eslint-plugin-import/issues/1861).

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2020-08-28 19:36:53 -07:00
committed by Tim Abbott
parent 8dc24e2a20
commit 10bd7a47c4
2 changed files with 12 additions and 14 deletions

View File

@@ -13,7 +13,7 @@ def build_for_prod_or_casper(quiet: bool) -> NoReturn:
"""Builds for production, writing the output to disk""" """Builds for production, writing the output to disk"""
webpack_args = ['node', 'node_modules/.bin/webpack-cli', webpack_args = ['node', 'node_modules/.bin/webpack-cli',
'--config', 'tools/webpack.config.ts', '-p', '-p',
'--env', 'production'] '--env', 'production']
if quiet: if quiet:
webpack_args += ['--display', 'errors-only'] webpack_args += ['--display', 'errors-only']
@@ -27,8 +27,6 @@ def build_for_dev_server(host: str, port: str, minify: bool, disable_host_check:
# files as devs make edits and serve new assets on the fly. # files as devs make edits and serve new assets on the fly.
webpack_args = ['node', 'node_modules/.bin/webpack-dev-server'] webpack_args = ['node', 'node_modules/.bin/webpack-dev-server']
webpack_args += [ webpack_args += [
'--config',
'tools/webpack.config.ts',
# webpack-cli has a bug where it ignores --watch-poll with # webpack-cli has a bug where it ignores --watch-poll with
# multi-config, and we don't need the katex-cli part anyway. # multi-config, and we don't need the katex-cli part anyway.
'--config-name', 'frontend', '--config-name', 'frontend',

View File

@@ -10,13 +10,13 @@ import TerserPlugin from "terser-webpack-plugin";
import webpack from "webpack"; import webpack from "webpack";
import BundleTracker from "webpack4-bundle-tracker"; import BundleTracker from "webpack4-bundle-tracker";
import DebugRequirePlugin from "./debug-require-webpack-plugin"; import DebugRequirePlugin from "./tools/debug-require-webpack-plugin";
import assets from "./webpack.assets.json"; import assets from "./tools/webpack.assets.json";
const cacheLoader: webpack.RuleSetUseItem = { const cacheLoader: webpack.RuleSetUseItem = {
loader: "cache-loader", loader: "cache-loader",
options: { options: {
cacheDirectory: resolve(__dirname, "../var/webpack-cache"), cacheDirectory: resolve(__dirname, "var/webpack-cache"),
}, },
}; };
@@ -25,12 +25,12 @@ export default (env?: string): webpack.Configuration[] => {
const config: webpack.Configuration = { const config: webpack.Configuration = {
name: "frontend", name: "frontend",
mode: production ? "production" : "development", mode: production ? "production" : "development",
context: resolve(__dirname, "../"), context: __dirname,
entry: assets, entry: assets,
module: { module: {
rules: [ rules: [
{ {
test: require.resolve("./debug-require"), test: require.resolve("./tools/debug-require"),
loader: "expose-loader", loader: "expose-loader",
options: {exposes: "require"}, options: {exposes: "require"},
}, },
@@ -65,8 +65,8 @@ export default (env?: string): webpack.Configuration[] => {
{ {
test: /\.(js|ts)$/, test: /\.(js|ts)$/,
include: [ include: [
resolve(__dirname, "../static/shared/js"), resolve(__dirname, "static/shared/js"),
resolve(__dirname, "../static/js"), resolve(__dirname, "static/js"),
], ],
use: [cacheLoader, "babel-loader"], use: [cacheLoader, "babel-loader"],
}, },
@@ -101,7 +101,7 @@ export default (env?: string): webpack.Configuration[] => {
// scss loader // scss loader
{ {
test: /\.scss$/, test: /\.scss$/,
include: resolve(__dirname, "../static/styles"), include: resolve(__dirname, "static/styles"),
use: [ use: [
{ {
loader: MiniCssExtractPlugin.loader, loader: MiniCssExtractPlugin.loader,
@@ -169,7 +169,7 @@ export default (env?: string): webpack.Configuration[] => {
], ],
}, },
output: { output: {
path: resolve(__dirname, "../static/webpack-bundles"), path: resolve(__dirname, "static/webpack-bundles"),
filename: production ? "[name].[contenthash].js" : "[name].js", filename: production ? "[name].[contenthash].js" : "[name].js",
chunkFilename: production ? "[contenthash].js" : "[id].js", chunkFilename: production ? "[contenthash].js" : "[id].js",
}, },
@@ -272,12 +272,12 @@ export default (env?: string): webpack.Configuration[] => {
const serverConfig: webpack.Configuration = { const serverConfig: webpack.Configuration = {
mode: production ? "production" : "development", mode: production ? "production" : "development",
target: "node", target: "node",
context: resolve(__dirname, "../"), context: __dirname,
entry: { entry: {
"katex-cli": "shebang-loader!katex/cli", "katex-cli": "shebang-loader!katex/cli",
}, },
output: { output: {
path: resolve(__dirname, "../static/webpack-bundles"), path: resolve(__dirname, "static/webpack-bundles"),
filename: "[name].js", filename: "[name].js",
}, },
}; };