-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.js
123 lines (118 loc) · 3.58 KB
/
webpack.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
"use strict";
const path = require("path");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const WasmPackPlugin = require("@wasm-tool/wasm-pack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const webpack = require("webpack");
const dotenv = require("dotenv");
/**
* TODO:
* - Builds are not cached, one change triggers a full rebuild
*/
dotenv.config({ path: path.resolve(__dirname, `.env`) });
const SUBSCRIPTION_PUBLIC_KEY = JSON.stringify(process.env.SUBSCRIPTION_PUBLIC_KEY);
const VIEWS = [
{ js: `homeView`, rust: `home_view` },
{ js: `loginView`, rust: `login_view` },
{ js: `movieView`, rust: `movie_view` },
{ js: `profileView`, rust: `profile_view` },
{ js: `recentlyRentedView`, rust: `recently_rented_view` },
{ js: `searchView`, rust: `search_view` },
{ js: `topTenView`, rust: `top_ten_view` },
];
const IS_PROD = process.env.NODE_ENV === `production`;
module.exports = {
entry: {
...VIEWS.reduce(
(all, { js, rust }) => ({
...all,
[js]: path.resolve(__dirname, `./views/${rust}/${js}.ts`),
}),
{},
),
index: path.resolve(__dirname, `./assets/scripts/index.ts`),
serviceWorker: path.resolve(__dirname, `./assets/scripts/serviceWorker.ts`),
},
experiments: {
asyncWebAssembly: true,
},
output: {
path: path.resolve(__dirname, `./server/assets`),
},
mode: process.env.NODE_ENV,
module: {
rules: [
{
test: /\.(ts|tsx|js|jsx)$/,
exclude: /(node_modules)/,
use: `swc-loader`,
},
{
test: /\.(png|svg|jpg|jpeg|gif)$/i,
type: "asset/resource",
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/i,
type: "asset/resource",
},
{
test: /\.(s|c)ss$/,
use: ["style-loader", MiniCssExtractPlugin.loader, "css-loader", "postcss-loader", "sass-loader"],
},
],
},
plugins: [
new CopyWebpackPlugin({
patterns: [
{
from: "node_modules/bootstrap/dist/js/bootstrap.bundle.min.js",
to: path.resolve(__dirname, "./server/assets/bootstrap.js"),
},
!IS_PROD && {
from: "node_modules/bootstrap/dist/js/bootstrap.bundle.min.js.map",
to: path.resolve(__dirname, "./server/assets/bootstrap.min.js.map"),
},
{
from: "node_modules/bootstrap/dist/css/bootstrap.css",
to: path.resolve(__dirname, "./server/assets/bootstrap.css"),
},
{
from: `./manifest.json`,
to: path.resolve(__dirname, `./server/assets/manifest.json`),
},
{
from: `./assets/logo.svg`,
to: path.resolve(__dirname, `./server/assets/logo.svg`),
},
!IS_PROD && {
from: "node_modules/bootstrap/dist/css/bootstrap.css.map",
to: path.resolve(__dirname, "./server/assets/bootstrap.css.map"),
},
].filter(Boolean),
}),
new MiniCssExtractPlugin({
filename: "[name].css",
}),
new webpack.DefinePlugin({
SUBSCRIPTION_PUBLIC_KEY,
}),
...VIEWS.map(
({ rust }) =>
new WasmPackPlugin({
crateDirectory: path.resolve(__dirname, `./views/${rust}`),
outName: `index`,
args: "--log-level warn",
extraArgs: IS_PROD ? "--no-typescript" : ``,
mode: process.env.NODE_ENV,
target: `web`,
watchDirectories: [
path.resolve(__dirname, `./views/${rust}/src`),
path.resolve(__dirname, `./views/components`),
],
}),
),
],
resolve: {
extensions: [".js", ".jsx", ".ts", ".tsx"],
},
};