-
-
Notifications
You must be signed in to change notification settings - Fork 62
/
webpack.js
119 lines (104 loc) · 3.05 KB
/
webpack.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
const path = require('path')
const webpack = require('webpack')
const webpackConfig = require('@nextcloud/webpack-vue-config')
const TerserPlugin = require('terser-webpack-plugin')
const WebpackSPDXPlugin = require('./build-js/WebpackSPDXPlugin.js')
const webpackRules = require('@nextcloud/webpack-vue-config/rules')
const SassGridConfig = require('./src/utils/SassGridConfig')
const BabelLoaderExcludeNodeModulesExcept = require('babel-loader-exclude-node-modules-except')
const WorkboxPlugin = require('workbox-webpack-plugin')
const { basename } = require('path')
const isDev = process.env.NODE_ENV === 'development'
webpackConfig.entry = {
main: path.join(__dirname, 'src', 'main.js'),
public: path.join(__dirname, 'src', 'public.js'),
sidebar: path.join(__dirname, 'src', 'sidebar.js'),
dashboard: path.join(__dirname, 'src', 'dashboard.js'),
}
webpackRules.RULE_JS.exclude = BabelLoaderExcludeNodeModulesExcept([
'@essentials/request-timeout',
'@nextcloud/event-bus',
'camelcase',
'hot-patcher',
'semver',
'vue-virtual-grid',
'webdav',
])
webpackRules.RULE_SCSS.use = [
'style-loader',
'css-loader',
'postcss-loader',
{
loader: 'sass-loader',
options: {
additionalData: SassGridConfig,
},
},
]
// Load raw SVGs to be able to inject them via v-html
webpackRules.RULE_ASSETS.test = /\.(png|jpe?g|gif|woff2?|eot|ttf)$/
webpackRules.RULE_RAW_SVGS = {
test: /\.svg$/,
type: 'asset/source',
}
webpackConfig.module.rules = Object.values(webpackRules)
webpackConfig.plugins.push(
// patch webdav/dist/request.js
new webpack.NormalModuleReplacementPlugin(
/request(\.js)?/,
function (resource) {
if (resource.context.indexOf('webdav') > -1) {
console.debug('Patched request for webdav', basename(resource.contextInfo.issuer))
resource.request = path.join(__dirname, 'src/patchedRequest.js')
}
},
),
new WorkboxPlugin.GenerateSW({
swDest: 'photos-service-worker.js',
clientsClaim: true,
skipWaiting: true,
exclude: [new RegExp('.*')], // don't do precaching
inlineWorkboxRuntime: true,
sourcemap: false,
// Define runtime caching rules.
runtimeCaching: [{
// Match any preview file request
urlPattern: /^.*\/apps\/photos\/api\/v1\/preview\/.*/,
// Apply a strategy.
handler: 'CacheFirst',
options: {
// Use a custom cache name.
cacheName: 'images',
// Only cache 10000 images.
expiration: {
maxAgeSeconds: 3600 * 24 * 7, // one week
maxEntries: 10000,
},
},
}],
})
)
if (!isDev) {
// block creation of LICENSE.txt files now replaced with .license files
webpackConfig.optimization.minimizer = [new TerserPlugin({
extractComments: false,
terserOptions: {
format: {
comments: false,
},
},
})]
webpackConfig.plugins = [
...webpackConfig.plugins,
// Generate reuse license files
new WebpackSPDXPlugin({
override: {
// TODO: Remove if they fixed the license in the package.json
'@nextcloud/axios': 'GPL-3.0-or-later',
'@nextcloud/vue': 'AGPL-3.0-or-later',
'nextcloud-vue-collections': 'AGPL-3.0-or-later',
}
}),
]
}
module.exports = webpackConfig