-
Notifications
You must be signed in to change notification settings - Fork 9
/
webpack.config.js
144 lines (142 loc) · 3.47 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
const path = require("path");
const Dotenv = require("dotenv-webpack");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const WorkerPlugin = require("worker-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
let publicUrl = process.env.PUBLIC_URL || "/";
if (!publicUrl.endsWith("/")) {
publicUrl += "/";
}
module.exports = {
entry: {
"web-component": path.resolve(__dirname, "./src/web-component.js"),
PyodideWorker: path.resolve(__dirname, "./src/PyodideWorker.js"),
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: ["babel-loader"],
},
{
test: /\.css$/,
use: ["css-loader"],
},
{
test: /\.s[ac]ss$/i,
exclude: [/node_modules/],
use: [
{
loader: "css-loader",
},
{
loader: "resolve-url-loader",
},
{
loader: "sass-loader",
options: {
sourceMap: true,
},
},
],
},
{
test: /\/src\/assets\/icons\/.*\.svg$/,
use: [
{
loader: "@svgr/webpack",
options: {
esModule: false,
limit: 10000,
},
},
],
},
{
test: /\.svg$/,
exclude: /\/src\/assets\/icons\/.*\.svg$/,
use: [
{
loader: "url-loader",
options: {
limit: 10000,
},
},
],
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/,
use: [
{
loader: "url-loader",
},
],
},
],
},
resolve: {
extensions: [".*", ".js", ".jsx", ".css"],
fallback: {
path: require.resolve("path-browserify"),
url: require.resolve("url/"),
},
},
output: {
path: path.resolve(__dirname, "./build"),
filename: "[name].js",
publicPath: publicUrl,
workerPublicPath: publicUrl,
},
devServer: {
host: "0.0.0.0",
allowedHosts: "all",
port: 3011,
liveReload: true,
hot: false,
static: {
directory: path.join(__dirname, "public"),
},
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
"Access-Control-Allow-Headers":
"X-Requested-With, content-type, Authorization",
// Pyodide - required for input and code interruption - needed on the host app
"Cross-Origin-Opener-Policy": "same-origin",
"Cross-Origin-Embedder-Policy": "require-corp",
},
setupMiddlewares: (middlewares, devServer) => {
devServer.app.use((req, res, next) => {
// PyodideWorker scripts - cross origin required on scripts needed for importScripts
if (
[
"/pyodide/shims/_internal_sense_hat.js",
"/pyodide/shims/pygal.js",
"/PyodideWorker.js",
].includes(req.url)
) {
res.setHeader("Cross-Origin-Resource-Policy", "cross-origin");
}
next();
});
return middlewares;
},
},
plugins: [
new WorkerPlugin(),
new Dotenv({
path: "./.env",
systemvars: true,
}),
new HtmlWebpackPlugin({
inject: "body",
template: "src/web-component.html",
filename: "web-component.html",
}),
new CopyWebpackPlugin({
patterns: [{ from: "public", to: "" }],
}),
],
stats: "minimal",
};