-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.ts
More file actions
81 lines (76 loc) · 2.86 KB
/
webpack.config.ts
File metadata and controls
81 lines (76 loc) · 2.86 KB
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
76
77
78
79
80
81
import path from 'path';
import webpack from 'webpack';
import "webpack-dev-server";
const CLIENT_OUTPUT_PATH = 'src/main/resources/META-INF/resources/static';
const SERVER_OUTPUT_PATH = 'src/main/resources/public';
const ASSETS_PATH = 'assets';
const JS_ASSETS_PATH = `${ASSETS_PATH}/javascripts`;
const CSS_ASSETS_PATH = `${ASSETS_PATH}/stylesheets`;
function jsConfig(
mode: webpack.Configuration["mode"] = "development",
side: "client" | "server" = "client"
): webpack.Configuration {
return {
mode: mode,
entry: `./${JS_ASSETS_PATH}/${side}.ts`,
target: side === "client" ? "web" : "node",
output: {
filename: `${side}.js`,
path: path.resolve(__dirname, side === "client" ? CLIENT_OUTPUT_PATH : SERVER_OUTPUT_PATH),
},
watch: side === "server" && mode === "development" || undefined,
devServer: side === "client" ? {
//liveReload: false, => see how to do hot reload for solid, not working at all
hot: true,
open: false,
watchFiles: [`./${JS_ASSETS_PATH}/**/*.{tsx,jsx,ts,js}`],
historyApiFallback: true,
allowedHosts: "all",
devMiddleware: {
writeToDisk: (path) => path.includes("client.js"),
},
port: 8081,
proxy: {
"/": {
target: {
host: "localhost",
protocol: 'http:',
port: 8080,
},
},
ignorePath: true,
changeOrigin: true,
secure: false,
},
} : undefined,
devtool: mode === "development" ? "inline-source-map" : undefined,
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'babel-loader',
exclude: /node_modules/,
options: {
presets: [
"@babel/preset-typescript",
["solid", { "generate": side === "client" ? "dom" : "ssr", "hydratable": true }]
],
env: side === "client" ? {
development: {
plugins: ["solid-refresh/babel"],
},
} : undefined,
}
},
],
},
plugins: side === "client" ? [
new webpack.HotModuleReplacementPlugin(),
] : undefined,
}
}
const env = (process.env.NODE_ENV || "development") as webpack.Configuration["mode"];
const side = (process.env.SIDE || "client") as "client" | "server";
console.log(`Building ${side} in ${env} mode`);
const config: webpack.Configuration = jsConfig(env, side)
export default config;