-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
118 lines (107 loc) · 2.34 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
const { readFileSync } = require("fs");
const { resolve } = require("path");
const rxPaths = require("rxjs/_esm5/path-mapping");
const { BannerPlugin, EnvironmentPlugin } = require("webpack");
const merge = require("webpack-merge");
const { argv: { mode } } = require("yargs");
const { name: filename, version } = require("./package.json");
const banner = readFileSync(resolve("./_includes/header.txt"), "utf-8");
const envConfig = (() => {
switch (mode) {
case "production":
return {
devtool: false,
plugins: [new BannerPlugin({ banner, raw: true }), new EnvironmentPlugin({ DEBUG: false })],
};
default:
return {
devtool: "source-map",
plugins: [new EnvironmentPlugin({ DEBUG: true })],
};
}
})()
const babelPresetLegacy = {
babelrc: false,
presets: [
[
"@babel/preset-env",
{
modules: false,
useBuiltIns: "entry",
corejs: 2,
},
],
],
}
const babelPresetModern = {
babelrc: false,
presets: [
[
"@babel/preset-env",
{
modules: false,
useBuiltIns: "entry",
corejs: 2,
targets: {
esmodules: true,
},
},
],
],
}
const sharedConfig = {
entry: resolve("./_js/src/entry.js"),
output: {
path: resolve("./assets/js"),
},
resolve: {
modules: [
resolve("./_js"),
resolve("./node_modules"),
...process.env.NODE_PATH ? [resolve(process.env.NODE_PATH)] : [],
],
extensions: [".json", ".js"],
symlinks: true,
alias: rxPaths(),
},
}
module.exports = [
merge(
envConfig,
sharedConfig,
{
output: {
filename: `${filename}-${version}.js`,
},
module: {
rules: [{
test: /(\.jsx|\.js)$/,
loader: "babel-loader",
options: babelPresetModern,
}, {
test: /modernizr-custom/,
use: 'null-loader'
}, {
test: /@webcomponents\/(template|url|webcomponents-platform)/,
use: 'null-loader'
}],
},
},
),
merge(
envConfig,
sharedConfig,
{
output: {
filename: `${filename}-legacy-${version}.js`,
},
module: {
rules: [{
test: /(\.jsx|\.js)$/,
loader: "babel-loader",
options: babelPresetLegacy,
}],
},
},
),
];