-
Notifications
You must be signed in to change notification settings - Fork 11
/
webpack.config.js
100 lines (92 loc) · 2.37 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
const path = require("path")
const webpack = require("webpack")
const HtmlWebpackPlugin = require("html-webpack-plugin")
const MiniCssExtractPlugin = require("mini-css-extract-plugin")
const WebappWebpackPlugin = require("favicons-webpack-plugin")
const devMode = process.env.NODE_ENV !== "production"
const apiRoot = function (env) {
if (env === "production") {
return "https://api.mixin.one"
} else {
return "https://api.mixin.one"
}
}
const blazeRoot = function (env) {
if (env === "production") {
return "wss://blaze.mixin.one"
} else {
return "wss://blaze.mixin.one"
}
}
module.exports = {
entry: {
app: "./src/app.js",
},
output: {
publicPath: "/",
path: path.resolve(__dirname, "dist"),
filename: "[name]-[hash].js",
},
resolve: {
alias: {
handlebars: "handlebars/dist/handlebars.runtime",
},
},
module: {
rules: [
{
test: /\.html$/,
use: ["handlebars-loader?helperDirs[]=" + __dirname + "/src/helpers"],
},
{
test: /\.(scss|css)$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
esModule: true,
},
},
"css-loader",
"sass-loader",
],
},
{
test: /\.(woff|woff2|eot|ttf|otf|svg|png|jpg|gif|webp)$/,
type: "asset/resource",
},
],
},
plugins: [
new webpack.DefinePlugin({
PRODUCTION: process.env.NODE_ENV === "production",
API_ROOT: JSON.stringify(apiRoot(process.env.NODE_ENV)),
BLAZE_ROOT: JSON.stringify(blazeRoot(process.env.NODE_ENV)),
APP_NAME: JSON.stringify("Mixin"),
}),
new HtmlWebpackPlugin({
template: "./src/layout.html",
templateParameters: (compilation, assets, tags, options) => {
tags.headTags.forEach((tag) => {
if (tag.tagName === "script") {
tag.attributes.async = true
}
})
return {
htmlWebpackPlugin: { options },
}
},
}),
new WebappWebpackPlugin({
logo: "./src/assets/images/launcher.webp",
prefix: "icons/",
}),
new MiniCssExtractPlugin({
filename: devMode ? "[name].css" : "[name]-[hash].css",
chunkFilename: devMode ? "[id].css" : "[id]-[hash].css",
}),
new webpack.ProvidePlugin({
Buffer: ["buffer", "Buffer"],
}),
],
}