|
1 | 1 | import path from "path"; |
| 2 | +import { ROOT_PATH, OUTPUT_PATH, OUTPUT_PUBLIC_PATH } from "../common/paths"; |
| 3 | +import resolveAliases from "./resolveAliases"; |
2 | 4 | import resolveExternals from "./resolveExternals"; |
3 | 5 | import resolveModuleRules from "./resolveModuleRules"; |
4 | 6 | import resolvePlugins from "./resolvePlugins"; |
5 | 7 | import resolveVersion from "./resolveVersion"; |
6 | | -import { ROOT_PATH, OUTPUT_PATH, OUTPUT_PUBLIC_PATH } from "../common/paths"; |
| 8 | + |
7 | 9 | import type webpack from "webpack"; |
8 | 10 |
|
9 | 11 | const isDevelopment = process.env.NODE_ENV === "development" || process.env.NODE_ENV === "dev"; |
10 | 12 | const version = resolveVersion(isDevelopment); |
11 | 13 |
|
12 | 14 | const webpackConfig: webpack.Configuration = { |
| 15 | + devServer: isDevelopment |
| 16 | + ? { |
| 17 | + https: true, |
| 18 | + inline: true, |
| 19 | + hot: true, |
| 20 | + contentBase: [OUTPUT_PATH, ROOT_PATH], |
| 21 | + publicPath: OUTPUT_PUBLIC_PATH, |
| 22 | + historyApiFallback: true, |
| 23 | + } |
| 24 | + : undefined, |
| 25 | + |
| 26 | + // See https://webpack.js.org/configuration/devtool/ |
| 27 | + devtool: isDevelopment ? "cheap-module-eval-source-map" : "source-map", |
| 28 | + |
| 29 | + externals: resolveExternals(false), |
| 30 | + |
13 | 31 | mode: isDevelopment ? "development" : "production", |
14 | 32 |
|
15 | 33 | entry: path.resolve(ROOT_PATH, "./src/index.tsx"), |
| 34 | + |
16 | 35 | output: { |
17 | 36 | filename: "bundle.[hash:5].min.js", |
18 | 37 | path: OUTPUT_PATH, |
19 | 38 | publicPath: OUTPUT_PUBLIC_PATH, |
20 | 39 | }, |
21 | 40 |
|
22 | | - devServer: { |
23 | | - https: true, |
24 | | - inline: true, |
25 | | - hot: true, |
26 | | - contentBase: [OUTPUT_PATH, ROOT_PATH], |
27 | | - publicPath: OUTPUT_PUBLIC_PATH, |
28 | | - historyApiFallback: true, |
29 | | - }, |
30 | | - |
31 | | - // See https://webpack.js.org/configuration/devtool/ |
32 | | - devtool: isDevelopment ? "cheap-module-eval-source-map" : "source-map", |
33 | | - |
34 | 41 | resolve: { |
35 | | - // Add resolvable extensions. |
| 42 | + alias: resolveAliases(), |
36 | 43 | extensions: [".ts", ".tsx", ".scss", ".js", ".jsx", ".json"], |
37 | 44 | }, |
38 | 45 |
|
39 | | - // When importing a module whose path matches one of the following, just |
40 | | - // assume a corresponding global variable exists and use that instead. |
41 | | - // This is important because it allows us to avoid bundling all of our |
42 | | - // dependencies, which allows browsers to cache those libraries between builds. |
43 | | - externals: resolveExternals(isDevelopment), |
44 | | - |
45 | 46 | module: { |
46 | | - rules: resolveModuleRules(isDevelopment), |
| 47 | + rules: resolveModuleRules(isDevelopment, false), |
47 | 48 | }, |
48 | 49 |
|
49 | | - plugins: resolvePlugins(isDevelopment, version), |
| 50 | + plugins: resolvePlugins(isDevelopment, false, version), |
50 | 51 | }; |
51 | 52 |
|
52 | 53 | export default webpackConfig; |
0 commit comments