-
Notifications
You must be signed in to change notification settings - Fork 93
/
Copy pathwebpack.config.cjs
147 lines (130 loc) · 2.84 KB
/
webpack.config.cjs
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
/**
* 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 crypto = require('crypto')
const path = require('path')
const { DefinePlugin } = require('webpack')
const BabelLoaderExcludeNodeModulesExcept = require('babel-loader-exclude-node-modules-except')
const buildMode = process.env.NODE_ENV
const isDev = buildMode === 'development'
// scope variable
// fallback for cypress testing
const appVersion = JSON.stringify(process.env.npm_package_version || 'nextcloud-vue')
const versionHash = crypto.createHash('md5').update(appVersion).digest('hex').slice(0, 7)
const SCOPE_VERSION = JSON.stringify(versionHash)
webpackConfig.devtool = isDev ? false : 'source-map'
const sassLoader = {
loader: 'sass-loader',
options: {
additionalData: `$scope_version:${SCOPE_VERSION}; @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'),
],
},
},
}
webpackRules.RULE_SCSS = {
test: /\.scss$/,
oneOf: [
{
resourceQuery: /module/,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
modules: {
// Same as in Vite
localIdentName: '_[local]_[hash:base64:5]',
},
},
},
'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: {
modules: {
// Same as in Vite
localIdentName: '_[local]_[hash:base64:5]',
},
},
},
'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),
SCOPE_VERSION,
}))
webpackConfig.resolve.extensionAlias = {
'.js': ['.ts', '.js'],
'.mjs': ['.mts', '.mjs'],
}
return webpackConfig
}