diff options
author | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2021-06-14 08:55:36 +0200 |
---|---|---|
committer | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2021-06-16 08:36:02 +0200 |
commit | e7a034d43d8b5ce84a51c73f9afaf894c5d10b90 (patch) | |
tree | 1e3e6dfe11bccad0bee02449b5224dadb1523ea3 /webpack.js | |
parent | 0a6791dc89da456306189e5634fd0e4f5999a5e6 (diff) |
Bump deps and use npm7
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'webpack.js')
-rw-r--r-- | webpack.js | 154 |
1 files changed, 65 insertions, 89 deletions
@@ -1,103 +1,79 @@ -const { merge } = require('webpack-merge') +const path = require('path') +const webpack = require('webpack') const webpackConfig = require('@nextcloud/webpack-vue-config') +const webpackRules = require('@nextcloud/webpack-vue-config/rules') -const SassGetGridConfig = require('./src/utils/SassGetGridConfig') -const ModuleReplaceWebpackPlugin = require('module-replace-webpack-plugin') +const SassGridConfig = require('./src/utils/SassGridConfig') const BabelLoaderExcludeNodeModulesExcept = require('babel-loader-exclude-node-modules-except') const WorkboxPlugin = require('workbox-webpack-plugin') -const config = { - module: { - rules: [ - { - test: /\.svg$/, - // illustrations - loader: 'raw-loader', - }, - { - test: /\.scss$/, - use: [ - 'style-loader', - 'css-loader', - 'postcss-loader', - { - loader: 'sass-loader', - options: { - sassOptions: { - functions: { - 'get($keys)': SassGetGridConfig, - }, - }, - }, - }, - ], - }, - { - test: /\.js$/, - loader: 'babel-loader', - exclude: BabelLoaderExcludeNodeModulesExcept([ - '@essentials/request-timeout', - '@nextcloud/event-bus', - 'camelcase', - 'hot-patcher', - 'semver', - 'vue-virtual-grid', - 'webdav', - ]), - }, - ], +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, + }, }, - plugins: [ - // patch webdav/dist/request.js - new ModuleReplaceWebpackPlugin({ - modules: [{ - test: /request.js/, - replace: './src/patchedRequest.js', - exclude: [/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: /^.*\/core\/preview\?fileId=.*/, +webpackConfig.module.rules = Object.values(webpackRules) +webpackConfig.module.rules.push({ + test: /\.svg$/, + // illustrations + loader: 'raw-loader', +}) - // Apply a strategy. - handler: 'CacheFirst', +webpackConfig.plugins.push( + // patch webdav/dist/request.js + new webpack.NormalModuleReplacementPlugin( + /request.js/, + function(resource) { + if (resource.context.indexOf('webdav/dist') > -1) { + 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, - options: { - // Use a custom cache name. - cacheName: 'images', + // Define runtime caching rules. + runtimeCaching: [{ + // Match any preview file request + urlPattern: /^.*\/core\/preview\?fileId=.*/, - // Only cache 10000 images. - expiration: { - maxAgeSeconds: 3600 * 24 * 7, // one week - maxEntries: 10000, - }, - }, - }], - }), - ], -} + // Apply a strategy. + handler: 'CacheFirst', -// Remove svg from default url-loader -const svgRule = webpackConfig.module.rules.find(rule => rule.test && rule.test.toString().indexOf('|svg') !== -1) -svgRule.test = new RegExp(svgRule.test.toString().replace('|svg', '')) + options: { + // Use a custom cache name. + cacheName: 'images', -// Merge configs -const mergedConfigs = merge(config, webpackConfig) - -// Remove duplicate rules by the `test` key -mergedConfigs.module.rules = mergedConfigs.module.rules - .filter((v, i, a) => a.findIndex(t => (t.test.toString() === v.test.toString())) === i) + // Only cache 10000 images. + expiration: { + maxAgeSeconds: 3600 * 24 * 7, // one week + maxEntries: 10000, + }, + }, + }], + }) +) -// Merge rules by replacing existing tests -module.exports = mergedConfigs +module.exports = webpackConfig |