-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathwebpack.config.js
147 lines (143 loc) · 4.04 KB
/
webpack.config.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
const path = require("path");
const dist = path.resolve(__dirname, "dist");
const WebpackBar = require("webpackbar");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const WasmPackPlugin = require("@wasm-tool/wasm-pack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
module.exports = (env, argv) => {
return {
performance: {
// Don't break compilation because of WASM file bigger than 244 KB.
hints: false
},
entry: {
// Bundle root with name `app.js`.
app: path.resolve(__dirname, "index.ts")
},
output: {
// You can change it to e.g. `/ui/`, but also edit `historyApiFallback` below and `<base href..`> in `index.hbs`.
publicPath: '/',
// You can deploy your site from this folder (after build with e.g. `yarn build:release`)
path: dist,
filename: '[name].[contenthash].js'
},
devServer: {
contentBase: dist,
// You can connect to dev server from devices in your network (e.g. 192.168.0.3:8000).
host: "0.0.0.0",
port: 8000,
// Route everything to index to support SPA. It should be the same like `publicPath` above.
historyApiFallback: {
index: '/'
},
noInfo: true,
stats: "errors-only",
overlay: {
// Commented to prevent error:
// `./crate/pkg/index_bg.js 382:14-53 Critical dependency: the request of a dependency is an expression`
// warnings: true,
errors: true
},
},
devtool: "eval",
experiments: {
asyncWebAssembly: true,
},
plugins: [
// Show compilation progress bar in console.
new WebpackBar(),
// Clean `dist` folder before compilation.
new CleanWebpackPlugin(),
// Extract CSS styles into a file.
new MiniCssExtractPlugin({
filename: '[name].[contenthash].css'
}),
// Add scripts, css, ... to html template.
new HtmlWebpackPlugin({
template: path.resolve(__dirname, "static/index.hbs")
}),
// Compile Rust.
new WasmPackPlugin({
crateDirectory: __dirname
}),
// You can find files from folder `../static` on url `http://my-site.com/static/`.
// And favicons in the root.
new CopyWebpackPlugin({
patterns: [
{
from: "static",
to: "static"
},
{
from: "favicons",
to: ""
}
]
}),
],
// Webpack try to guess how to resolve imports in this order:
resolve: {
extensions: [".ts", ".js", ".wasm"],
alias: {
crate: __dirname
}
},
module: {
rules: [
{
test: /\.hbs$/,
use: [
{
loader: "handlebars-loader",
options: {
rootRelative: './templates/'
}
}
]
},
{
test: /\.(jpg|jpeg|png|woff|woff2|eot|ttf|svg)$/,
use: [
{
loader: "file-loader",
options: {
// Don't copy files to `dist`, we do it through `CopyWebpackPlugin` (see above)
// - we only want to resolve urls to these files.
emitFile: false,
name: "[path][name].[ext]"
}
}
]
},
{
test: /\.ts$/,
use: [
{
loader: "ts-loader",
options: {
configFile: "tsconfig.css_classes.json"
}
}
]
},
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
"css-loader",
{
loader: "postcss-loader",
options: {
postcssOptions: {
config: path.resolve(__dirname, "postcss.config.js"),
}
},
},
]
}
]
}
};
};