memories/webpack.js

72 lines
1.8 KiB
JavaScript
Raw Normal View History

const webpack = require('webpack');
const path = require('path');
const webpackConfig = require('@nextcloud/webpack-vue-config');
const WorkboxPlugin = require('workbox-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
2022-09-13 01:33:24 +00:00
const buildMode = process.env.NODE_ENV;
const isDev = buildMode === 'development';
2022-10-17 02:52:44 +00:00
// Entry points
webpackConfig.entry = {
main: path.resolve(path.join('src', 'main')),
admin: path.resolve(path.join('src', 'admin')),
'hooks-clear-cache': path.resolve(path.join('src', 'hooks', 'clear-cache')),
};
// Enable TypeScript for Vue
const tsRule = webpackConfig.module.rules.find((rule) => rule.use?.includes('ts-loader'));
console.assert(tsRule, 'Could not find ts-loader rule');
tsRule.use = [
{ loader: 'babel-loader' },
{
loader: 'ts-loader',
options: {
appendTsSuffixTo: [/\.vue$/],
},
},
];
2022-08-14 20:54:18 +00:00
// Exclude node_modules from watch
2022-10-15 19:21:53 +00:00
webpackConfig.watchOptions = {
ignored: /node_modules/,
aggregateTimeout: 300,
2022-10-15 19:21:53 +00:00
};
// Bundle service worker
2022-12-07 20:25:19 +00:00
webpackConfig.plugins.push(
new WorkboxPlugin.InjectManifest({
swSrc: path.resolve(path.join('src', 'service-worker.js')),
swDest: 'memories-service-worker.js',
})
2022-12-07 20:25:19 +00:00
);
2022-10-17 02:52:44 +00:00
// Exclusions from minification
const minifyExclude = [/filerobot-image-editor/];
webpackConfig.optimization.minimizer[0] = new TerserPlugin({
exclude: minifyExclude,
terserOptions: {
output: {
comments: false,
},
},
extractComments: true,
});
// Disable source maps in production
webpackConfig.devtool = isDev ? 'cheap-source-map' : false;
// Configure source map public path
webpackConfig.plugins.push(
new webpack.SourceMapDevToolPlugin({
filename: '[file].map',
publicPath: path.join('/apps/', process.env.npm_package_name, '/js/'),
})
);
// Enable caching
webpackConfig.cache = true;
module.exports = webpackConfig;