-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.config.js
98 lines (94 loc) · 2.58 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
var webpack = require("webpack");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const path = require("path");
const sveltePath = path.resolve("node_modules", "svelte");
const mode = process.env.NODE_ENV || "production";
const prod = mode === "production";
module.exports = {
entry: {
widgets: ["./widgets/main.js"],
},
output: {
path: path.resolve("dist"),
filename: "widgets.js",
},
resolve: {
alias: {
svelte: path.resolve("node_modules", "svelte"),
},
extensions: [".mjs", ".js", ".svelte"],
mainFields: ["svelte", "browser", "module", "main"],
},
module: {
rules: [
// Rules are chained bottom to top. Babel rule must probably be one of
// the last of the chain, so it must come first in the array.
{
test: /\.(?:svelte|m?js)$/,
// Svelte internals, under node_modules MUST be included.
//
// Babel 7 ignores node_modules automatically, but not if they're
// explicitely included.
// see: https://github.com/babel/babel-loader/issues/171#issuecomment-486380160
//
include: [path.resolve("widgets"), path.dirname(sveltePath)],
use: {
loader: "babel-loader",
options: {
presets: [
[
"@babel/preset-env",
{
targets: "ie >= 9",
corejs: 3,
useBuiltIns: "entry",
},
],
],
},
},
},
{
test: /\.svelte$/,
use: {
loader: "svelte-loader",
options: {
emitCss: true,
hotReload: true,
},
},
},
{
test: /\.css$/,
use: [
/**
* MiniCssExtractPlugin doesn't support HMR.
* For developing, use 'style-loader' instead.
* */
prod ? MiniCssExtractPlugin.loader : "style-loader",
"css-loader",
],
},
{
test: /\.less$/,
use: [
prod ? MiniCssExtractPlugin.loader : "style-loader",
"css-loader",
"less-loader",
],
},
],
},
mode,
plugins: [
new MiniCssExtractPlugin({
filename: "[name].css",
}),
new HtmlWebpackPlugin({ template: "widgets/index.html" }),
new webpack.ProvidePlugin({
Promise: "es6-promise", // Thanks Aaron (https://gist.github.com/Couto/b29676dd1ab8714a818f#gistcomment-1584602)
}),
],
devtool: prod ? false : "source-map",
};