-
Notifications
You must be signed in to change notification settings - Fork 36
/
webpack.config.js
188 lines (170 loc) · 4.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
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
const webpack = require("webpack");
const merge = require("webpack-merge");
const {CleanWebpackPlugin} = require("clean-webpack-plugin");
const babelLoader = {
loader: "babel-loader",
options: {
presets: [
["@babel/preset-env", {
targets: {
ie: 11
}
}]
]
}
};
// Configuration shared by Storybook's build and the app's build
const storybook = developmentMode => ({
mode: developmentMode ? "development" : "production",
module: {
rules: [
{
test: /\.s[ac]ss$/i,
sideEffects: true,
use: [
"style-loader",
{
loader: "css-loader",
options: {
sourceMap: developmentMode
}
},
{
loader: "sass-loader",
options: {
sourceMap: developmentMode,
sassOptions: {
// Other files have imports like @import "@carbon/icons/...".
includePaths: [
// Carbon-components has its own copies of the @carbon projects. Since it's using
// those copies we might as well use them too.
"node_modules/carbon-components/scss/globals/scss/vendor",
// Normal path for third party includes.
"node_modules"
]
}
}
}
]
},
{
test: /\.less$/i,
sideEffects: true,
use: [
"style-loader",
{
loader: "css-loader",
options: {
sourceMap: developmentMode
}
},
{
loader: "less-loader",
options: {
sourceMap: developmentMode
}
}
]
},
{
enforce: "pre",
test: /\.js$/,
exclude: /node_modules/,
loader: "eslint-loader",
options: {
cache: false
}
},
{
test: /\.js$/,
use: babelLoader
}
]
},
resolve: {
modules: [
"node_modules"
],
alias: {
// myself (exception because not in node_modules)
/* global __dirname */
"deliteful": __dirname,
// fix issues when dstore/Request tries to load dojo/request
"dojo/request": "dojo/request/xhr",
// third party aliases
"dcl": "dcl/amd"
}
},
resolveLoader: {
modules: [
"node_modules",
"webpackLoaders"
],
alias: {
"requirejs-dplugins/i18n": "amdi18n-loader",
"requirejs-text/text": "raw-loader",
// custom loaders
"delite/handlebars": "handlebars-loader"
}
},
plugins: [
// Get dojo (accessed via dstore) to work.
new webpack.NormalModuleReplacementPlugin(/has!.*dom-addeventlistener\?\:/,
resource => { resource.request = "empty-module"; } ),
new webpack.NormalModuleReplacementPlugin(/has!config-deferredInstrumentation\?.\/promise\/instrumentation/,
resource => { resource.request = "dojo/promise/instrumentation"; } ),
new webpack.NormalModuleReplacementPlugin(/has!dom\?..\/selector\/_loader/,
resource => { resource.request = "empty-module"; } ),
new webpack.NormalModuleReplacementPlugin(/host-browser\?..\/_base\/window/,
resource => { resource.request = "dojo/_base/window"; } ),
// Get decor/Observable to load. TODO: remove the "object-observe-api" check; it's always false.
// Or, just remove support for ObservableArray altogether.
new webpack.NormalModuleReplacementPlugin(/features!object-observe-api/,
resource => { resource.request = "ibm-decor/schedule"; } ),
// Convert "requirejs-dplugins/css!foo.css" into just "foo.css".
new webpack.NormalModuleReplacementPlugin(/^requirejs-dplugins[\\\/]css!/, function (resource) {
resource.request = resource.request.replace(/.*css!/, "");
})
],
node: {
setImmediate: false,
process: false
}
});
// Main configuration for the app, unit tests, etc.
const main = developmentMode => merge(storybook(developmentMode), {
entry: {
// Bundle to run the unit tests.
"unit-tests": "./tests/unit/bundle.js",
// Bundle for the samples and functional tests.
"functional-tests": "./tests/functional/bundle.js"
},
output: {
// To make webpack-runtime-require work.
pathinfo: true
},
module: {
rules: [
{
// Storybook adds its own rule for CSS files, so this is not part of Storybook's config above.
test: /\.css$/i,
sideEffects: true,
use: [
"style-loader",
{
loader: "css-loader",
options: {
sourceMap: developmentMode
}
}
]
}
]
},
plugins: [
// CleanWebpackPlugin breaks the Storybook build, so put it here instead.
new CleanWebpackPlugin()
],
devtool: developmentMode ? "eval-source-map" : false
});
module.exports = main(true);