-
Notifications
You must be signed in to change notification settings - Fork 88
/
webpack.config.js
171 lines (157 loc) · 4.21 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
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
const glob = require('glob')
const md5 = require('md5')
const path = require('path')
const { loadTranslations } = require('./resources/translations.js')
const { DefinePlugin } = require('webpack')
const { VueLoaderPlugin } = require('vue-loader')
const BabelLoaderExcludeNodeModulesExcept = require('babel-loader-exclude-node-modules-except')
const nodeExternals = require('webpack-node-externals')
const buildMode = process.env.NODE_ENV
const isDev = buildMode === 'development'
const libraryTarget = process.env.LIBRARY_TARGET ?? 'umd'
const { dependencies } = require('./package.json')
// 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)
console.info('This build version hash is', versionHash, '\n')
const config = {
mode: buildMode,
devtool: isDev ? false : 'source-map',
devServer: {
historyApiFallback: true,
noInfo: true,
overlay: true,
},
entry: {
ncvuecomponents: path.join(__dirname, 'src', 'index.js'),
install: path.join(__dirname, 'src', 'install.js'),
...glob.sync('src/components/*/index.js').reduce((acc, item) => {
const name = item
.replace('/index.js', '')
.replace('src/components/', 'Components/')
acc[name] = path.join(__dirname, item)
return acc
}, {}),
...glob.sync('src/directives/*/index.js').reduce((acc, item) => {
const name = item
.replace('/index.js', '')
.replace('src/directives/', 'Directives/')
acc[name] = path.join(__dirname, item)
return acc
}, {}),
...glob.sync('src/functions/*/index.js').reduce((acc, item) => {
const name = item
.replace('/index.js', '')
.replace('src/functions/', 'Functions/')
acc[name] = path.join(__dirname, item)
return acc
}, {}),
...glob.sync('src/mixins/*/index.js').reduce((acc, item) => {
const name = item
.replace('/index.js', '')
.replace('src/mixins/', 'Mixins/')
acc[name] = path.join(__dirname, item)
return acc
}, {}),
},
output: {
path: path.resolve(__dirname, './dist'),
publicPath: '/dist/',
filename: '[name].js',
library: {
type: libraryTarget,
name: ['NextcloudVue', '[name]'],
},
umdNamedDefine: true,
},
externals: [nodeExternals()],
module: {
rules: [
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
{
test: /\.scss$/,
use: [
'style-loader',
'css-loader',
'resolve-url-loader',
{
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'),
],
},
},
},
],
},
{
test: /\.vue$/,
loader: 'vue-loader',
},
{
test: /\.js$/,
loader: 'babel-loader',
exclude: BabelLoaderExcludeNodeModulesExcept([
'@nextcloud/calendar-js',
'tributejs',
]),
},
{
test: /\.(png|jpg|gif|eot|ttf|woff|woff2)$/i,
loader: 'url-loader',
},
{
test: /\.svg/,
type: 'asset/inline',
},
{
resourceQuery: /raw/,
type: 'asset/source',
},
],
},
plugins: [
new VueLoaderPlugin(),
],
resolve: {
extensions: ['*', '.js', '.vue'],
symlinks: false,
// Alias the default server assets path to link to local one
alias: {
'/core/css/../img': path.join(__dirname, 'styleguide/assets/img'),
'/core/css/../fonts': path.join(__dirname, 'styleguide/assets/fonts'),
},
},
}
module.exports = async () => {
const translations = await loadTranslations(path.resolve(__dirname, './l10n'))
config.plugins.push(new DefinePlugin({
SCOPE_VERSION,
TRANSLATIONS: JSON.stringify(translations),
}))
if (libraryTarget !== 'umd') {
config.experiments = {
outputModule: true,
}
config.entry = {
index: path.join(__dirname, 'src', 'index.js'),
}
config.output.filename = `[name].${libraryTarget}.js`
config.externals = [...config.externals, ...Object.keys(dependencies)]
delete config.output.library.name
}
return config
}