2023-05-06 03:10:27 +00:00
|
|
|
const webpack = require('webpack');
|
2023-05-26 16:47:05 +00:00
|
|
|
const path = require('path');
|
2023-04-21 06:07:09 +00:00
|
|
|
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
|
|
|
|
2023-04-21 06:07:09 +00:00
|
|
|
const buildMode = process.env.NODE_ENV;
|
|
|
|
const isDev = buildMode === 'development';
|
2022-10-17 02:52:44 +00:00
|
|
|
|
2023-05-26 16:47:05 +00:00
|
|
|
// Entry points
|
|
|
|
webpackConfig.entry = {
|
|
|
|
main: path.resolve(path.join('src', 'main')),
|
|
|
|
admin: path.resolve(path.join('src', 'admin')),
|
2023-05-26 18:05:44 +00:00
|
|
|
'hooks-clear-cache': path.resolve(path.join('src', 'hooks', 'clear-cache')),
|
2023-05-26 16:47:05 +00:00
|
|
|
};
|
|
|
|
|
2023-10-12 03:54:06 +00:00
|
|
|
// 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$/],
|
|
|
|
},
|
2023-04-21 06:07:09 +00:00
|
|
|
},
|
2023-10-12 03:54:06 +00:00
|
|
|
];
|
2022-08-14 20:54:18 +00:00
|
|
|
|
2023-05-26 16:47:05 +00:00
|
|
|
// Exclude node_modules from watch
|
2022-10-15 19:21:53 +00:00
|
|
|
webpackConfig.watchOptions = {
|
2023-04-21 06:07:09 +00:00
|
|
|
ignored: /node_modules/,
|
|
|
|
aggregateTimeout: 300,
|
2022-10-15 19:21:53 +00:00
|
|
|
};
|
|
|
|
|
2023-05-26 16:47:05 +00:00
|
|
|
// Bundle service worker
|
2022-12-07 20:25:19 +00:00
|
|
|
webpackConfig.plugins.push(
|
2023-04-21 06:07:09 +00:00
|
|
|
new WorkboxPlugin.InjectManifest({
|
|
|
|
swSrc: path.resolve(path.join('src', 'service-worker.js')),
|
|
|
|
swDest: 'memories-service-worker.js',
|
2023-10-15 02:39:29 +00:00
|
|
|
}),
|
2022-12-07 20:25:19 +00:00
|
|
|
);
|
2022-10-17 02:52:44 +00:00
|
|
|
|
2023-10-15 02:39:29 +00:00
|
|
|
// Minification
|
|
|
|
webpackConfig.optimization.minimizer = [
|
|
|
|
new TerserPlugin({
|
|
|
|
exclude: [/filerobot-image-editor/],
|
|
|
|
terserOptions: {
|
|
|
|
output: {
|
|
|
|
comments: false,
|
|
|
|
},
|
2023-04-21 06:07:09 +00:00
|
|
|
},
|
2023-10-15 02:39:29 +00:00
|
|
|
extractComments: true,
|
|
|
|
}),
|
|
|
|
];
|
2023-04-17 05:28:56 +00:00
|
|
|
|
2023-04-21 06:07:24 +00:00
|
|
|
// Disable source maps in production
|
|
|
|
webpackConfig.devtool = isDev ? 'cheap-source-map' : false;
|
|
|
|
|
2023-05-06 03:10:27 +00:00
|
|
|
// Configure source map public path
|
|
|
|
webpackConfig.plugins.push(
|
|
|
|
new webpack.SourceMapDevToolPlugin({
|
|
|
|
filename: '[file].map',
|
|
|
|
publicPath: path.join('/apps/', process.env.npm_package_name, '/js/'),
|
2023-10-15 02:39:29 +00:00
|
|
|
}),
|
2023-05-06 03:10:27 +00:00
|
|
|
);
|
|
|
|
|
2023-05-06 01:36:45 +00:00
|
|
|
// Enable caching
|
|
|
|
webpackConfig.cache = true;
|
|
|
|
|
2023-10-15 02:43:21 +00:00
|
|
|
// Bundle analyzer (npm i --no-save webpack-bundle-analyzer)
|
|
|
|
// webpackConfig.plugins.push(new (require('webpack-bundle-analyzer').BundleAnalyzerPlugin)());
|
|
|
|
|
2023-04-21 06:07:09 +00:00
|
|
|
module.exports = webpackConfig;
|