-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.dev.js
75 lines (71 loc) · 2.64 KB
/
webpack.dev.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { createModulePlugin, isLocal } from "wmfnext-shared/webpack.js";
import HtmlWebpackPlugin from "html-webpack-plugin";
import { getFileDirectory } from "wmfnext-remote-loader/webpack.js";
import path from "path";
import packageJson from "./package.json" assert { type: "json" };
const __dirname = getFileDirectory(import.meta);
/** @type {import("webpack").Configuration} */
export default {
mode: "development",
target: "web",
devtool: "inline-source-map",
devServer: {
port: 8081,
historyApiFallback: true,
// Otherwise hot reload in the host failed with a CORS error.
headers: {
"Access-Control-Allow-Origin": "*"
}
},
entry: isLocal ? "./src/index.tsx" : "./src/register.tsx",
output: {
// The trailing / is very important, otherwise paths will ne be resolved correctly.
publicPath: "http://localhost:8081/"
},
module: {
rules: [
{
test: /\.(ts|tsx)$/,
exclude: /node_modules/,
use: {
loader: "ts-loader",
options: {
transpileOnly: true,
configFile: path.resolve(__dirname, "tsconfig.dev.json")
}
}
},
{
// https://stackoverflow.com/questions/69427025/programmatic-webpack-jest-esm-cant-resolve-module-without-js-file-exten
test: /\.js/,
resolve: {
fullySpecified: false
}
},
{
test: /\.(css)$/,
use: ["style-loader", "css-loader"]
},
{
test: /\.(png|jpe?g|gif)$/i,
type: "asset/resource"
}
]
},
resolve: {
alias: {
// Without the aliases, at runtime an "Invalid hook call" is thrown, see https://stackoverflow.com/questions/64283813/invalid-hook-call-on-npm-link-library
"react": path.resolve(__dirname, "./node_modules/react"),
"react-dom": path.resolve(__dirname, "./node_modules/react-dom"),
// Without the alias, at runtime the index route doesn't render and we are stuck with a blank page.
"react-router-dom": path.resolve(__dirname, "./node_modules/react-router-dom")
},
// Must add ".js" for files imported from node_modules.
extensions: [".js", ".ts", ".tsx", ".css"]
},
plugins: [
isLocal
? new HtmlWebpackPlugin({ template: "./public/index.html" })
: createModulePlugin("remote1", packageJson)
]
};