-
Notifications
You must be signed in to change notification settings - Fork 88
/
webpack.config.js
109 lines (94 loc) · 2.22 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
/**
* 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 md5 = require('md5')
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 = md5(appVersion).slice(0, 7)
const SCOPE_VERSION = JSON.stringify(versionHash)
webpackConfig.devtool = isDev ? false : 'source-map'
const sassLoader = {
loader: 'sass-loader',
options: {
additionalData: `@use 'sass:math'; $scope_version:${SCOPE_VERSION}; @import 'variables'; @import 'material-icons';`,
/**
* ! needed for resolve-url-loader
*/
sourceMap: true,
sassOptions: {
sourceMapContents: false,
includePaths: [
path.resolve(__dirname, './src/assets'),
],
},
},
}
webpackRules.RULE_TS = {
test: /\.tsx?$/,
use: [
'babel-loader',
],
}
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_JS.exclude = BabelLoaderExcludeNodeModulesExcept([
'tributejs',
])
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,
}))
return webpackConfig
}