2023-10-30 00:54:53 +00:00
|
|
|
const webpack = require('webpack');
|
|
|
|
const path = require('path');
|
2023-10-18 19:21:16 +00:00
|
|
|
|
2023-10-30 00:54:53 +00:00
|
|
|
const WorkboxPlugin = require('workbox-webpack-plugin');
|
|
|
|
const TerserPlugin = require('terser-webpack-plugin');
|
|
|
|
const { VueLoaderPlugin } = require('vue-loader');
|
2023-11-25 00:22:54 +00:00
|
|
|
const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');
|
2022-09-13 01:33:24 +00:00
|
|
|
|
2023-10-20 02:21:09 +00:00
|
|
|
const appName = process.env.npm_package_name!;
|
|
|
|
const appVersion = process.env.npm_package_version!;
|
2023-04-21 06:07:09 +00:00
|
|
|
const buildMode = process.env.NODE_ENV;
|
|
|
|
const isDev = buildMode === 'development';
|
2023-10-18 19:21:16 +00:00
|
|
|
console.info('Building', appName, appVersion, '\n');
|
2022-10-17 02:52:44 +00:00
|
|
|
|
2023-10-18 19:21:16 +00:00
|
|
|
module.exports = {
|
|
|
|
target: 'web',
|
|
|
|
mode: buildMode,
|
2023-10-18 19:55:12 +00:00
|
|
|
devtool: 'source-map',
|
2023-10-18 19:21:16 +00:00
|
|
|
cache: isDev,
|
|
|
|
|
2023-10-29 20:15:29 +00:00
|
|
|
context: path.resolve(__dirname, 'src'),
|
|
|
|
|
2023-10-18 19:21:16 +00:00
|
|
|
entry: {
|
2023-10-29 20:15:29 +00:00
|
|
|
main: './main',
|
|
|
|
admin: './admin',
|
|
|
|
'hooks-clear-cache': './hooks/clear-cache',
|
2023-10-18 19:21:16 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
output: {
|
|
|
|
path: path.resolve(__dirname, 'js'),
|
|
|
|
publicPath: path.join('/apps/', appName, '/js/'),
|
|
|
|
|
|
|
|
// Output file names
|
|
|
|
filename: `${appName}-[name].js?v=[contenthash]`,
|
|
|
|
chunkFilename: `${appName}-[name].js?v=[contenthash]`,
|
2023-05-26 16:47:05 +00:00
|
|
|
|
2023-10-18 19:21:16 +00:00
|
|
|
// Clean output before each build
|
|
|
|
clean: true,
|
|
|
|
|
|
|
|
// Make sure sourcemaps have a proper path and do not
|
|
|
|
// leak local paths https://github.com/webpack/webpack/issues/3603
|
|
|
|
devtoolNamespace: appName,
|
2023-10-20 02:21:09 +00:00
|
|
|
devtoolModuleFilenameTemplate(info: any) {
|
2023-10-18 19:21:16 +00:00
|
|
|
const rootDir = process.cwd();
|
|
|
|
const rel = path.relative(rootDir, info.absoluteResourcePath);
|
|
|
|
return `webpack:///${appName}/${rel}`;
|
2023-10-12 03:54:06 +00:00
|
|
|
},
|
2023-04-21 06:07:09 +00:00
|
|
|
},
|
2022-08-14 20:54:18 +00:00
|
|
|
|
2023-10-18 19:21:16 +00:00
|
|
|
watchOptions: {
|
|
|
|
ignored: /node_modules/,
|
|
|
|
aggregateTimeout: 300,
|
|
|
|
},
|
2022-10-15 19:21:53 +00:00
|
|
|
|
2023-10-18 19:21:16 +00:00
|
|
|
optimization: {
|
|
|
|
chunkIds: 'named',
|
|
|
|
splitChunks: {
|
|
|
|
automaticNameDelimiter: '-',
|
2023-04-21 06:07:09 +00:00
|
|
|
},
|
2023-10-18 19:21:16 +00:00
|
|
|
minimize: !isDev,
|
|
|
|
minimizer: [
|
|
|
|
new TerserPlugin({
|
|
|
|
exclude: [/filerobot-image-editor/],
|
|
|
|
terserOptions: {
|
|
|
|
output: {
|
|
|
|
comments: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
extractComments: true,
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
},
|
2023-04-17 05:28:56 +00:00
|
|
|
|
2023-10-18 19:21:16 +00:00
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.(png|jpe?g|gif|svg|woff2?|eot|ttf)$/,
|
|
|
|
type: 'asset/inline',
|
|
|
|
},
|
2023-11-25 00:22:54 +00:00
|
|
|
{
|
|
|
|
resourceQuery: /raw/,
|
|
|
|
type: 'asset/source',
|
|
|
|
},
|
2023-10-18 19:21:16 +00:00
|
|
|
{
|
|
|
|
test: /\.s?css$/,
|
|
|
|
use: ['style-loader', 'css-loader', 'sass-loader'],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.vue$/,
|
|
|
|
loader: 'vue-loader',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.tsx?$/,
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'ts-loader',
|
|
|
|
options: {
|
|
|
|
appendTsSuffixTo: [/\.vue$/],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
exclude: /node_modules/,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
|
|
|
|
plugins: [
|
|
|
|
new VueLoaderPlugin(),
|
2023-04-21 06:07:24 +00:00
|
|
|
|
2023-11-25 00:22:54 +00:00
|
|
|
// @nextcloud/dialogs depends on path
|
|
|
|
// This is really frustrating, but it's the only way
|
|
|
|
new NodePolyfillPlugin({
|
|
|
|
includeAliases: ['path', 'process'],
|
|
|
|
}),
|
|
|
|
|
2023-10-18 19:21:16 +00:00
|
|
|
// Bundle service worker
|
|
|
|
new WorkboxPlugin.InjectManifest({
|
2023-10-19 18:52:36 +00:00
|
|
|
swSrc: path.resolve(path.join('src', 'service-worker.ts')),
|
2023-10-18 19:21:16 +00:00
|
|
|
swDest: 'memories-service-worker.js',
|
2023-10-18 19:39:01 +00:00
|
|
|
maximumFileSizeToCacheInBytes: (isDev ? 10 : 4) * 1024 * 1024,
|
2023-10-18 19:21:16 +00:00
|
|
|
}),
|
2023-10-15 02:43:21 +00:00
|
|
|
|
2023-10-18 19:21:16 +00:00
|
|
|
// Make appName & appVersion available as a constant
|
|
|
|
new webpack.DefinePlugin({ appName: JSON.stringify(appName) }),
|
|
|
|
new webpack.DefinePlugin({ appVersion: JSON.stringify(appVersion) }),
|
|
|
|
|
|
|
|
// Bundle analyzer (npm i --no-save webpack-bundle-analyzer)
|
|
|
|
// new (require('webpack-bundle-analyzer').BundleAnalyzerPlugin)()
|
|
|
|
],
|
|
|
|
|
|
|
|
resolve: {
|
|
|
|
extensions: ['.ts', '.js', '.vue'],
|
|
|
|
symlinks: false,
|
|
|
|
alias: {
|
2023-10-29 20:14:28 +00:00
|
|
|
// Ensure npm does not duplicate vue dependency, and that npm link works for vue 3
|
|
|
|
// See https://github.com/vuejs/core/issues/1503
|
|
|
|
// See https://github.com/nextcloud/nextcloud-vue/issues/3281
|
|
|
|
vue$: path.resolve(__dirname, 'node_modules', 'vue'),
|
|
|
|
|
2023-10-29 21:10:56 +00:00
|
|
|
// You also need to update tsconfig.json
|
|
|
|
'@services': path.resolve(__dirname, 'src', 'services'),
|
|
|
|
'@assets': path.resolve(__dirname, 'src', 'assets'),
|
|
|
|
'@components': path.resolve(__dirname, 'src', 'components'),
|
|
|
|
'@mixins': path.resolve(__dirname, 'src', 'mixins'),
|
|
|
|
'@native': path.resolve(__dirname, 'src', 'native'),
|
2023-10-18 19:21:16 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|