This repository has been archived by the owner on May 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathwebpack.config.js
106 lines (99 loc) · 2.45 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
const webpack = require("webpack");
const autoprefixer = require('autoprefixer');
const path = require('path');
function tryResolve_(url, sourceFilename) {
// Put require.resolve in a try/catch to avoid node-sass failing with cryptic libsass errors
// when the importer throws
try {
return require.resolve(url, {paths: [path.dirname(sourceFilename)]});
} catch (e) {
return '';
}
}
function tryResolveScss(url, sourceFilename) {
// Support omission of .scss and leading _
const normalizedUrl = url.endsWith('.scss') ? url : `${url}.scss`;
return tryResolve_(normalizedUrl, sourceFilename) ||
tryResolve_(path.join(path.dirname(normalizedUrl), `_${path.basename(normalizedUrl)}`),
sourceFilename);
}
function materialImporter(url, prev) {
if (url.startsWith('@material')) {
const resolved = tryResolveScss(url, prev);
return {file: resolved || url};
}
return {file: url};
}
/**
Given a string `name`, returns a rule to bundle
RegExp(`${name}\.scss$`) to `biz-portal.bundle.${name}.css`
**/
function themeBundle(name) {
return {
test: new RegExp(`${name}\.scss$`),
use: [
{
loader: 'file-loader',
options: {
name: `biz-portal.bundle.${name}.css`,
},
},
{loader: 'extract-loader'},
{
loader: 'css-loader',
options: { sourceMap: true }
},
{
loader: 'postcss-loader',
options: {
plugins: () => [autoprefixer()],
sourceMap: true
}
},
{
loader: 'sass-loader',
options: {
importer: materialImporter,
sourceMap: true
},
}
],
}
}
module.exports = {
context: __dirname,
entry: [
// Entry for each theme
'./assets/scss/biz-portal-default.scss',
'./assets/scss/biz-portal-WC033.scss',
'./assets/js/html5-details-polyfill.js',
'./assets/js/biz-portal.js'
],
output: {
filename: 'biz-portal.bundle.js',
path: path.resolve('./assets/bundles'),
},
resolve: {
alias: {
jquery: "jquery/src/jquery"
}
},
plugins: [
new webpack.ProvidePlugin({ jQuery: 'jquery', $: 'jquery', "window.jQuery": "jquery" }),
],
module: {
rules: [
// Rule for each theme
themeBundle("WC033"),
themeBundle("default"),
{
test: /\.js$/,
loader: 'babel-loader',
query: {
presets: ['@babel/preset-env'],
},
}
],
},
devtool: 'source-map',
};