-
Notifications
You must be signed in to change notification settings - Fork 221
chore: implement rs pack #5632
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SebastianKrupinski
wants to merge
1
commit into
main
Choose a base branch
from
chore/rspack
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
chore: implement rs pack #5632
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,238 @@ | ||||||
| /* | ||||||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||||||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||||||
| */ | ||||||
|
|
||||||
| const browserslistConfig = require('@nextcloud/browserslist-config') | ||||||
| const { RsdoctorRspackPlugin } = require('@rsdoctor/rspack-plugin') | ||||||
| const { defineConfig } = require('@rspack/cli') | ||||||
| const { CssExtractRspackPlugin, LightningCssMinimizerRspackPlugin, DefinePlugin, ProgressPlugin, SwcJsMinimizerRspackPlugin, IgnorePlugin } = require('@rspack/core') | ||||||
| const NodePolyfillPlugin = require('@rspack/plugin-node-polyfill') | ||||||
| const browserslist = require('browserslist') | ||||||
| const path = require('node:path') | ||||||
| const { VueLoaderPlugin } = require('vue-loader') | ||||||
|
|
||||||
| // browserslist-rs does not support baseline queries yet | ||||||
| // Manually resolving the browserslist config to the list of browsers with minimal versions | ||||||
| // See: https://github.com/browserslist/browserslist-rs/issues/40 | ||||||
| const browsers = browserslist(browserslistConfig) | ||||||
| const minBrowserVersion = browsers | ||||||
| .map((str) => str.split(' ')) | ||||||
| .reduce((minVersion, [browser, version]) => { | ||||||
| minVersion[browser] = minVersion[browser] ? Math.min(minVersion[browser], parseFloat(version)) : parseFloat(version) | ||||||
| return minVersion | ||||||
| }, {}) | ||||||
| const targets = Object.entries(minBrowserVersion).map(([browser, version]) => `${browser} >=${version}`).join(',') | ||||||
|
|
||||||
| const transpilePackages = [ | ||||||
| 'p-limit', | ||||||
|
odzhychko marked this conversation as resolved.
|
||||||
| 'yocto-queue', | ||||||
| ] | ||||||
|
|
||||||
| const shouldExcludeFromJsTranspile = (resourcePath) => { | ||||||
| if (!resourcePath.includes(`${path.sep}node_modules${path.sep}`)) { | ||||||
| return false | ||||||
| } | ||||||
|
|
||||||
| return !transpilePackages.some((moduleName) => resourcePath.includes(`${path.sep}node_modules${path.sep}${moduleName}${path.sep}`)) | ||||||
| } | ||||||
|
|
||||||
| module.exports = defineConfig((env) => { | ||||||
| const appName = process.env.npm_package_name | ||||||
| const appVersion = process.env.npm_package_version | ||||||
|
|
||||||
| const mode = (env.development && 'development') || (env.production && 'production') || process.env.NODE_ENV || 'production' | ||||||
| const isDev = mode === 'development' | ||||||
| process.env.NODE_ENV = mode | ||||||
|
|
||||||
| console.info('Building', appName, appVersion, '\n') | ||||||
|
|
||||||
| return { | ||||||
| target: 'web', | ||||||
| mode, | ||||||
| devtool: isDev ? 'cheap-source-map' : 'source-map', | ||||||
| stats: 'normal', | ||||||
|
|
||||||
| entry: { | ||||||
| main: path.join(__dirname, 'src', 'main.js'), | ||||||
| 'files-action': path.join(__dirname, 'src', 'files-action.js'), | ||||||
| 'admin-settings': path.join(__dirname, 'src', 'admin-settings.js'), | ||||||
| oca: path.join(__dirname, 'src', 'oca.ts'), | ||||||
| }, | ||||||
|
|
||||||
| output: { | ||||||
| path: path.resolve('./js'), | ||||||
| filename: `${appName}-[name].js?v=[contenthash]`, | ||||||
| chunkFilename: `${appName}-[name].js?v=[contenthash]`, | ||||||
| publicPath: 'auto', | ||||||
| assetModuleFilename: '[name].[ext]?v=[contenthash]', | ||||||
| clean: true, | ||||||
| devtoolNamespace: appName, | ||||||
| devtoolModuleFilenameTemplate(info) { | ||||||
| const rootDir = process.cwd() | ||||||
| const rel = path.relative(rootDir, info.absoluteResourcePath) | ||||||
| return `webpack:///${appName}/${rel}` | ||||||
| }, | ||||||
| }, | ||||||
|
|
||||||
| optimization: { | ||||||
| chunkIds: 'named', | ||||||
| splitChunks: { | ||||||
| automaticNameDelimiter: '-', | ||||||
| cacheGroups: { | ||||||
| defaultVendors: { | ||||||
| reuseExistingChunk: true, | ||||||
| }, | ||||||
| }, | ||||||
| }, | ||||||
| minimize: !isDev, | ||||||
| minimizer: [ | ||||||
| new SwcJsMinimizerRspackPlugin({ | ||||||
| minimizerOptions: { | ||||||
| targets, | ||||||
| }, | ||||||
| }), | ||||||
| new LightningCssMinimizerRspackPlugin({ | ||||||
| minimizerOptions: { | ||||||
| targets, | ||||||
| }, | ||||||
| }), | ||||||
| ], | ||||||
| }, | ||||||
|
|
||||||
| module: { | ||||||
| rules: [ | ||||||
| { | ||||||
| test: /\.vue$/, | ||||||
| loader: 'vue-loader', | ||||||
| options: { | ||||||
| experimentalInlineMatchResource: true, | ||||||
| }, | ||||||
| }, | ||||||
| { | ||||||
| test: /\.css$/, | ||||||
| use: [ | ||||||
| { | ||||||
| loader: CssExtractRspackPlugin.loader, | ||||||
| }, | ||||||
| 'css-loader', | ||||||
| ], | ||||||
| }, | ||||||
| { | ||||||
| test: /\.scss$/, | ||||||
| use: [ | ||||||
| { | ||||||
| loader: CssExtractRspackPlugin.loader, | ||||||
| }, | ||||||
| 'css-loader', | ||||||
| { | ||||||
| loader: 'sass-loader', | ||||||
| options: { | ||||||
| sassOptions: { | ||||||
| // Sass emits a BOM for CSS files with non-ASCII characters in production builds by default. | ||||||
| // PostCSS (used by css-loader) >=8.5.24 stopped stripping it, so extracted stylesheets end up | ||||||
| // with a stray BOM between merged files, breaking the first selector of each one. | ||||||
| // Safe to disable since every page already sets <meta charset="utf-8">. | ||||||
| // See: https://github.com/nextcloud-libraries/webpack-vue-config/pull/798 | ||||||
| charset: false, | ||||||
| }, | ||||||
| }, | ||||||
| }, | ||||||
| ], | ||||||
| }, | ||||||
| { | ||||||
| test: /\.[cm]?js$/, | ||||||
| exclude: shouldExcludeFromJsTranspile, | ||||||
| loader: 'builtin:swc-loader', | ||||||
| options: { | ||||||
| jsc: { | ||||||
| parser: { | ||||||
| syntax: 'ecmascript', | ||||||
| }, | ||||||
| }, | ||||||
| env: { | ||||||
| targets, | ||||||
| }, | ||||||
| }, | ||||||
| type: 'javascript/auto', | ||||||
| }, | ||||||
| { | ||||||
| test: /\.ts$/, | ||||||
| exclude: [/node_modules/], | ||||||
| loader: 'builtin:swc-loader', | ||||||
| options: { | ||||||
| jsc: { | ||||||
| parser: { | ||||||
| syntax: 'typescript', | ||||||
| }, | ||||||
| }, | ||||||
| env: { | ||||||
| targets, | ||||||
| }, | ||||||
| }, | ||||||
| type: 'javascript/auto', | ||||||
| }, | ||||||
| { | ||||||
| test: /\.(png|jpe?g|gif|svg|webp)$/i, | ||||||
| type: 'asset', | ||||||
| }, | ||||||
| { | ||||||
| test: /\.(woff2?|eot|ttf|otf)$/i, | ||||||
| type: 'asset/resource', | ||||||
| }, | ||||||
| { | ||||||
| resourceQuery: /raw/, | ||||||
| type: 'asset/source', | ||||||
| }, | ||||||
| { | ||||||
| resourceQuery: /url$/, | ||||||
| type: 'asset/resource', | ||||||
| }, | ||||||
| ], | ||||||
| }, | ||||||
|
|
||||||
| plugins: [ | ||||||
| new ProgressPlugin(), | ||||||
| new VueLoaderPlugin(), | ||||||
| new NodePolyfillPlugin(), | ||||||
| new DefinePlugin({ | ||||||
| appName: JSON.stringify(appName), | ||||||
| appVersion: JSON.stringify(appVersion), | ||||||
| // Vue compile time flags | ||||||
| // See: https://vuejs.org/api/compile-time-flags.html#compile-time-flags | ||||||
| // See: https://github.com/vuejs/core/blob/v3.5.24/packages/vue/README.md#bundler-build-feature-flags | ||||||
| // > The build will work without configuring these flags, | ||||||
| // > however it is strongly recommended to properly configure them in order to get proper tree-shaking in the final bundle | ||||||
| // Unlike Vite plugin, vue-loader does not do this automatically for Webpack | ||||||
| // Although documentation says, it is optional, sometimes it breaks with: | ||||||
| // ReferenceError: __VUE_PROD_DEVTOOLS__ is not defined | ||||||
| __VUE_OPTIONS_API__: true, | ||||||
| __VUE_PROD_DEVTOOLS__: false, | ||||||
| __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: false, | ||||||
| }), | ||||||
| new IgnorePlugin({ | ||||||
| resourceRegExp: /^\.\/locale$/, | ||||||
| contextRegExp: /moment$/, | ||||||
| }), | ||||||
| new CssExtractRspackPlugin({ | ||||||
| filename: '../css/contacts-[name].css', | ||||||
| chunkFilename: '../css/[id].chunk.css', | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
nit(non-blocking): To be consistent with https://github.com/nextcloud/calendar/blob/fb819ae3762048fe6c5069b48dd2008bb311fd07/rspack.config.js#L233 |
||||||
| ignoreOrder: true, | ||||||
| }), | ||||||
| process.env.RSDOCTOR && new RsdoctorRspackPlugin(), | ||||||
| ], | ||||||
|
|
||||||
| resolve: { | ||||||
| extensions: ['*', '.tsx', '.ts', '.js', '.vue', '.json'], | ||||||
| symlinks: false, | ||||||
| alias: { | ||||||
| '@': path.resolve(__dirname, 'src'), | ||||||
| }, | ||||||
| fallback: { | ||||||
| fs: false, | ||||||
| }, | ||||||
| }, | ||||||
|
|
||||||
| cache: true, | ||||||
| } | ||||||
| }) | ||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: For some reason
resolvedandintegrityare missing.Maybe because private registry/cache/proxy where used when installing.
Can be fixed by running
npx npm-package-lock-add-resolved.Anyway conflicting package-lock.json