-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathwebpack.config.js
287 lines (278 loc) · 12.3 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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
const path = require("path");
const webpack = require("webpack");
const {CleanWebpackPlugin} = require("clean-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const HtmlReplaceWebpackPlugin = require("html-replace-webpack-plugin");
// const StringReplacePlugin = require("string-replace-webpack-plugin"); webpack 2
const EsmWebpackPlugin = require("@purtuga/esm-webpack-plugin");
const PluginProposalExportDefaultFrom = require("@babel/plugin-proposal-export-default-from"); // Allows `export .. from` syntax in the entry point
const MergeIntoSingleFilePlugin = require("webpack-merge-and-include-globally");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const TerserPlugin = require("terser-webpack-plugin");
const ESLintPlugin = require("eslint-webpack-plugin");
const packageJson = require("./package.json");
const DIST_PATH = path.resolve(__dirname, "build/");
const revision = require("./rev-info.js");
const tpl = path => ({
img: `<img alt="${path}" src="${path}" />`,
css: `<link rel="stylesheet" type="text/css" href="${path}">`,
js: `<script type="text/javascript" src="${path}"></script>`,
void: ""
});
// TODO add CSS loader and group all fonts in one directory rewriting urls
module.exports = {
mode: "production",
entry: {
"iva-app": "./src/iva-app.js"
},
output: {
filename: "[name][hash].js",
path: DIST_PATH
},
plugins: [
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
template: "./src/index.html",
minify: {
removeAttributeQuotes: true,
collapseWhitespace: true
// removeComments: true //cannot be uncommented because of HtmlReplaceWebpackPlugin depends on comments
}
}),
new HtmlReplaceWebpackPlugin([
{
// mimic the behaviour of Grunt processhtml (for the assets defined in MergeIntoSingleFilePlugin())
pattern: /<!-- build:([\s\S]*?)\[([\s\S]*?)] -->[\s\S]*?<!-- \/build -->/m,
replacement: function (match, type, path) {
return tpl(path)[type];
}
},
{
pattern: /\[build-signature\]/m,
replacement: function (match, type, path) {
return revision;
}
}
]
),
new MergeIntoSingleFilePlugin({
files: {
"assets/css/styles.css": [
"lib/jsorolla/styles/css/global.css",
"lib/jsorolla/styles/css/style.css",
"src/styles/toggle-switch.css",
"src/styles/magic-check.css",
"src/styles/global.css"
],
"assets/css/vendor.css": [
"./node_modules/bootstrap/dist/css/bootstrap.min.css",
"./node_modules/animate.css/animate.min.css",
"./node_modules/bootstrap-table/dist/bootstrap-table.min.css",
"./node_modules/bootstrap-select/dist/css/bootstrap-select.min.css",
"./node_modules/bootstrap-treeview/dist/bootstrap-treeview.min.css",
"./node_modules/bootstrap-colorpicker/dist/css/bootstrap-colorpicker.min.css",
"./node_modules/eonasdan-bootstrap-datetimepicker/build/css/bootstrap-datetimepicker.min.css",
"./node_modules/@fortawesome/fontawesome-free/css/all.min.css",
"./node_modules/qtip2/dist/jquery.qtip.min.css",
"./node_modules/jquery.json-viewer/json-viewer/jquery.json-viewer.css",
"./node_modules/tokenize2/dist/tokenize2.min.css",
"./node_modules/sweetalert2/dist/sweetalert2.css",
"./node_modules/select2/dist/css/select2.css",
"./node_modules/select2-bootstrap-theme/dist/select2-bootstrap.css"
],
"assets/js/vendor.js": [
"./node_modules/jquery/dist/jquery.js",
"./node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js",
"./node_modules/lodash/lodash.min.js",
"./node_modules/backbone/backbone-min.js",
"./node_modules/highcharts/highcharts.js",
"./node_modules/qtip2/dist/jquery.qtip.min.js",
"./node_modules/urijs/src/URI.min.js",
"./node_modules/cookies-js/dist/cookies.min.js",
"./node_modules/crypto-js/core.js",
"./node_modules/crypto-js/sha256.js",
"./node_modules/jquery.json-viewer/json-viewer/jquery.json-viewer.js",
"./node_modules/bootstrap/dist/js/bootstrap.min.js",
"./node_modules/bootstrap-table/dist/bootstrap-table.min.js",
"./node_modules/bootstrap-select/dist/js/bootstrap-select.js",
"./node_modules/bootstrap-treeview/dist/bootstrap-treeview.min.js",
"./node_modules/bootstrap-colorpicker/dist/js/bootstrap-colorpicker.min.js",
"./node_modules/bootstrap-validator/dist/validator.min.js",
"./node_modules/moment/min/moment.min.js",
"./node_modules/eonasdan-bootstrap-datetimepicker/build/js/bootstrap-datetimepicker.min.js",
"./node_modules/bootstrap-notify/bootstrap-notify.js",
"./node_modules/jwt-decode/build/jwt-decode.min.js",
"./node_modules/tokenize2/dist/tokenize2.min.js",
"./node_modules/bootstrap-3-typeahead/bootstrap3-typeahead.min.js",
"./node_modules/@svgdotjs/svg.js/dist/svg.min.js",
"./node_modules/sweetalert2/dist/sweetalert2.js",
"./node_modules/clipboard/dist/clipboard.min.js",
"./node_modules/select2/dist/js/select2.min.js"
]
},
transform: {
"assets/js/vendor.js": code => require("uglify-js").minify(code).code,
"assets/css/styles.css": code => require("uglifycss").processString(code)
}
}),
new CopyWebpackPlugin([
{
context: "./",
from: "LICENSE",
to: DIST_PATH
},
{
context: "./",
from: "README.md",
to: DIST_PATH
},
{
context: "./src/conf",
from: "**/*.js",
to: DIST_PATH + "/conf"
},
{
from: "./favicon.ico",
to: DIST_PATH + "/"
},
{
context: "./src/img",
from: "**/*",
to: DIST_PATH + "/img"
},
{
context: "./lib/jsorolla/styles/fonts",
from: "**/*",
to: DIST_PATH + "/assets/fonts"
},
{
context: "./node_modules/bootstrap/dist/fonts",
from: "**/*",
to: DIST_PATH + "/assets/fonts"
},
{
context: "node_modules/@webcomponents/webcomponentsjs",
from: "**/*.js",
to: DIST_PATH + "/webcomponents"
},
{
context: "node_modules/@fortawesome/fontawesome-free/webfonts",
from: "*",
to: DIST_PATH + "/assets/webfonts"
}
]),
/* new MethodExtractor({options: true, output: DIST_PATH + "/conf", components: [
"./lib/jsorolla/src/core/webcomponents/opencga/catalog/cohorts/opencga-cohort-browser.js"
]})*/
// ignore is not the best way to externalize a resource, but webpack don't support external ES modules yet.
// ignore makes sense because iva-app bundle will be an ES module on its own, so import X from "/jsorolla.min.js" won't be a problem if not processed by webpack
// why do whe need to bundle iva-app in webpack at all then? Because we need to process litElement imports
new webpack.IgnorePlugin({
checkResource(resource) {
// console.log("res", resource)
// if (resource === "./conf/opencga-variant-browser.config.js") return true;
// return false;
}
// resourceRegExp: /import [\s\S]+? from "\.\/\.\.\/lib\/jsorolla\/dist\/main\.js";/
// resourceRegExp: /import [\s\S]+? from "main\.js";/
// resourceRegExp: /^\.\/locale$/,
// contextRegExp: /moment$/
})
// new ESLintPlugin({fix:false})
],
optimization: {
minimize: true
/* minimizer: [
new TerserPlugin({
terserOptions: {
keep_classnames: true,
keep_fnames: true
}
})
]*/
},
/* externals: [
{
"externalConfig": "./conf/external-config.js"
}
],*/
module: {
rules: [
// es-lint check step
/* {
test: /\.js$/,
exclude: /node_modules/,
use: ["babel-loader", "eslint-loader"]
},*/
/* {
// Test for a polyfill (or any file) and it won't be included in your
// bundle
test: path.resolve(__dirname, "src/conf/external-config.js"),
use: "null-loader"
},*/
{
test: /\.html$/,
use: ["html-loader"] // rewrite html content (replace automatically <img src="img.jpg"/> in require("img.jpg"))
},
{
test: /\.m?js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: "babel-loader",
options: {
presets: [[
"@babel/preset-env",
{
// useBuiltIns: "usage",
// targets: ">20%, not dead, not ie 11" //browserslist query now defined in package.json
// corejs: 3
}
]],
plugins: [
"@babel/plugin-proposal-export-default-from",
// "@babel/regenerator-runtime/runtime",
"@babel/transform-runtime",
["@babel/plugin-proposal-class-properties", {"loose": true}]
]
}
}
},
{
test: /\.js$/,
loader: "string-replace-loader",
options: {
multiple: [
{
search: "/web_modules/lit-element.js",
replace: "lit-element"
},
{
search: "/web_modules/lit-html.js",
replace: "lit-html"
},
{
search: "/web_modules/lit-html/directives/class-map.js",
replace: "lit-html/directives/class-map.js"
},
{
search: "/web_modules/lit-html/directives/if-defined.js",
replace: "lit-html/directives/if-defined.js"
},
{
search: "/node_modules/countup.js/dist/countUp.min.js",
replace: "countup.js"
}
/* js string replacement
{
search: "// @dev\\[([\\s\\S]*?)\\][\\s\\S]*?// /@dev",
replace: (match, p1, offset, string) => `import ${p1} from "main.js";`,
//replace: (match, p1, offset, string) => `${p1}`,
flags: "gim",
strict: true
}*/
]
}
}
]
}
};