-
Notifications
You must be signed in to change notification settings - Fork 95
Expand file tree
/
Copy pathwebpack.config.cjs
More file actions
137 lines (122 loc) · 2.52 KB
/
webpack.config.cjs
File metadata and controls
137 lines (122 loc) · 2.52 KB
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
/**
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: CC0-1.0
*/
// config for the styleguide
const webpackConfig = require('@nextcloud/webpack-vue-config')
const webpackRules = require('@nextcloud/webpack-vue-config/rules')
const BabelLoaderExcludeNodeModulesExcept = require('babel-loader-exclude-node-modules-except')
const path = require('path')
const { DefinePlugin } = require('webpack')
const buildMode = process.env.NODE_ENV
const isDev = buildMode === 'development'
webpackConfig.devtool = isDev ? false : 'source-map'
const sassLoader = {
loader: 'sass-loader',
options: {
additionalData: '@use \'sass:math\'; @use \'variables\' as *; @use \'material-icons\' as *;',
/**
* ! needed for resolve-url-loader
*/
sourceMap: true,
sassOptions: {
sourceMapContents: false,
includePaths: [
path.resolve(__dirname, './src/assets'),
path.resolve(__dirname, 'node_modules'),
],
},
},
}
const cssLoaderOptions = {
modules: {
namedExport: false,
// Same as in Vite
localIdentName: '_[local]_[hash:base64:5]',
exportLocalsConvention: 'asIs',
},
}
webpackRules.RULE_SCSS = {
test: /\.scss$/,
oneOf: [
{
resourceQuery: /module/,
use: [
'style-loader',
{
loader: 'css-loader',
options: cssLoaderOptions,
},
'resolve-url-loader',
sassLoader,
],
},
{
use: [
'style-loader',
'css-loader',
'resolve-url-loader',
sassLoader,
],
},
],
}
webpackRules.RULE_CSS = {
test: /\.css$/,
oneOf: [
{
resourceQuery: /module/,
use: [
'style-loader',
{
loader: 'css-loader',
options: cssLoaderOptions,
},
'resolve-url-loader',
],
},
{
use: [
'style-loader',
'css-loader',
'resolve-url-loader',
],
},
],
}
webpackRules.RULE_JS.exclude = BabelLoaderExcludeNodeModulesExcept([
'tributejs',
])
// Speedup styleguide build
webpackRules.RULE_TS.use = [
'babel-loader',
{
loader: 'ts-loader',
options: {
transpileOnly: true,
},
},
]
webpackRules.RULE_RAW_SVG = {
resourceQuery: /raw/,
type: 'asset/source',
}
webpackRules.RULE_NODE_MJS = {
test: /\.m?js$/,
include: /node_modules/,
type: 'javascript/auto',
resolve: {
fullySpecified: false,
},
}
webpackConfig.module.rules = Object.values(webpackRules)
module.exports = () => {
webpackConfig.plugins.push(new DefinePlugin({
PRODUCTION: JSON.stringify(!isDev),
}))
webpackConfig.resolve.extensionAlias = {
'.js': ['.ts', '.js'],
'.mjs': ['.mts', '.mjs'],
}
return webpackConfig
}