-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.config.js
74 lines (68 loc) · 1.97 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
const webpack = require("webpack");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const path = require("path");
const pkg = require("./package.json");
const mode = process.env.NODE_ENV;
const dev = mode === "development";
const prod = !dev;
const alias = { svelte: path.resolve("node_modules", "svelte") };
const extensions = [".mjs", ".js", ".json", ".svelte", ".html"];
const mainFields = ["svelte", "module", "browser", "main"];
module.exports = {
entry: { client: __dirname + "/src/client.js" },
output: {
path: __dirname + "/static/build",
filename: "[name].js",
chunkFilename: "[name].[id].js",
publicPath: "/",
},
resolve: { alias, extensions, mainFields },
module: {
rules: [
{
test: /\.(svelte|html)$/,
use: {
loader: "svelte-loader",
options: {
dev,
hydratable: true,
hotReload: false,
},
},
},
{
test: /\.css$/,
use: ["style-loader", "css-loader"],
},
],
},
mode,
plugins: [
new webpack.DefinePlugin({
"process.browser": true,
"process.env.NODE_ENV": JSON.stringify(mode),
}),
].filter(Boolean),
devtool: dev && "inline-source-map",
devServer: {
contentBase: "./static",
publicPath: "/build",
hot: true,
liveReload: true,
before: (app, server, compiler) => {
const { get: get_schemas } = require("./src/routes/schemas.json.js");
const schema_dir =
process.env.JSONSCHEMATIC_DIR || process.cwd() + "/examples";
process.env.JSONSCHEMATIC_DIR = schema_dir; // for the schemas route
app.get("/schemas.json", (req, res, next) => {
get_schemas(req, res);
});
const sirv = require("sirv");
const schemas = sirv(schema_dir, { dev: true });
app.use("/schemas/", (req, res, next) => {
req.path = req.path.substring(8); // remove "/assets" prefix
schemas(req, res, next);
});
},
},
};