forked from carbon-design-system/carbon-components-svelte
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
70 lines (68 loc) · 1.86 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
const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const path = require("path");
const { optimizeImports } = require("carbon-preprocess-svelte");
const NODE_ENV = process.env.NODE_ENV || "development";
const PROD = NODE_ENV === "production";
module.exports = {
entry: { "build/bundle": ["./src/index.js"] },
resolve: {
alias: {
svelte: path.resolve("node_modules", "svelte/src/runtime"),
},
extensions: [".mjs", ".js", ".svelte"],
mainFields: ["svelte", "browser", "module", "main"],
conditionNames: ["svelte", "browser", "import"],
},
output: {
publicPath: "/",
path: path.join(__dirname, "/public"),
filename: PROD ? "[name].[contenthash].js" : "[name].js",
chunkFilename: "[name].[id].js",
clean: true,
},
module: {
rules: [
{
test: /\.svelte$/,
use: {
loader: "svelte-loader",
options: {
hotReload: !PROD,
preprocess: [optimizeImports()],
compilerOptions: { dev: !PROD },
},
},
},
{
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, "css-loader"],
},
{
test: /node_modules\/svelte\/.*\.mjs$/,
resolve: { fullySpecified: false },
},
],
},
mode: NODE_ENV,
plugins: [
new MiniCssExtractPlugin({
filename: PROD ? "[name].[chunkhash].css" : "[name].css",
}),
new HtmlWebpackPlugin({
templateContent: `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body></body>
</html>
`,
}),
],
stats: "errors-only",
devtool: PROD ? false : "source-map",
devServer: { hot: true, historyApiFallback: true },
};