-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
92 lines (88 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
const path = require("path")
const {
InjectManifest,
} = require("workbox-webpack-plugin")
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,
}
}
module.exports = {
mode: "production",
entry: [
"./app.sass", "./app.js",
],
output: {
filename: "bundle.js",
path: __dirname,
},
module: {
rules: [{
test: /\.sass$/,
use: [{
loader: "file-loader",
options: {
name: "bundle.css",
},
}, {
loader: "extract-loader",
}, {
loader: "css-loader",
}, {
loader: "postcss-loader",
},
{
loader: "sass-loader",
options: {
importer: materialImporter,
},
},
],
}],
},
plugins: [
new InjectManifest({
globDirectory: ".",
globPatterns: ["**/*.*"],
importWorkboxFrom: "local",
swSrc: "sw.js",
swDest: "service-worker.js",
globIgnores: [
"node_modules/**/*",
"+(workbox-|webpack.|postcss.)config.js",
"app.+(js|sass)",
"yarn.lock",
"package.json",
"_config.yml",
"sw.js",
"README.md",
"pinterest-c16e1.html",
"*.log",
],
}),
],
}