This repository has been archived by the owner on Oct 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
101 lines (100 loc) · 3 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
const path = require("path");
const HTMLPlugin = require("html-webpack-plugin");
const CopyPlugin = require("copy-webpack-plugin")
const webpack = require('webpack')
module.exports = {
entry: {
index: path.resolve("./src/index.tsx"),
contentScript: path.resolve("./src/contentScript/contentScript.ts"),
backgroundScript: path.resolve("./src/backgroundScript/backgroundScript.ts"),
sandbox: path.resolve("./src/sandbox/sandbox.ts")
},
mode: "production",
module: {
rules: [
{
test: /\.tsx?$/,
use: [
{
loader: "ts-loader",
options: {
compilerOptions: { noEmit: false },
}
}],
exclude: /node_modules/,
},
{
exclude: /node_modules/,
test: /\.css$/i,
use: [
"style-loader",
"css-loader"
]
},
{
test: /\.(png|jpg|gif)$/i,
use: [
{
loader: 'url-loader',
options: {
limit: 8192
}
}
]
}
],
},
output: {
filename: "[name].js", // the file name would be my entry"s name with a ".bundle.js" suffix
path: path.resolve(__dirname, "dist") // put all of the build in a dist folder
},
resolve: {
extensions: [".tsx", ".ts", ".js"],
fallback: {
"os": false,
"fs": false,
"tls": false,
"net": false,
"path": false,
"zlib": false,
"http": false,
"https": false,
"crypto": false,
"crypto-browserify": require.resolve("crypto-browserify"),
"stream": require.resolve("stream-browserify"),
"process/browser": require.resolve("process/browser")
},
alias: {
process: "process/browser",
// snarkjs uses ejs which has unsafe-eval function constructor
ejs: path.resolve(__dirname, "src/config/ejsMock.js"),
}
},
plugins: [
// fix "process is not defined" error:
new webpack.ProvidePlugin({
process: 'process/browser',
}),
new webpack.DefinePlugin({
'process.env': JSON.stringify(process.env)
}),
new CopyPlugin({
patterns: [
{ from: "manifest.json", to: "manifest.json" },
{ from: path.resolve(__dirname, "./src/sandbox/sandbox.html"), to: path.resolve(__dirname, "./dist") },
],
}),
...getHtmlPlugins(["index"]),
]
}
function getHtmlPlugins(chunks) {
return chunks.map(
(chunk) =>
new HTMLPlugin({
inject: true,
title: "Plurality",
filename: `${chunk}.html`,
chunks: [chunk],
})
);
}