diff --git a/README.md b/README.md index d8b5b7d..b022f71 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ This plugin adds preload links by getting output assets from the build tools you Supporting: - Vite 4 and 5 **(on build only)** - Webpack 5 (with [HtmlWebpackPlugin 5](https://github.com/jantimon/html-webpack-plugin)) -- Rspack (with [HtmlWebpackPlugin 5](https://github.com/jantimon/html-webpack-plugin) or [HtmlRspackPlugin](https://www.rspack.dev/config/plugins.html#htmlrspackplugin)) +- Rspack 1.0 (with [HtmlWebpackPlugin 5](https://github.com/jantimon/html-webpack-plugin) or [HtmlRspackPlugin](https://www.rspack.dev/config/plugins.html#htmlrspackplugin)) > [!NOTE] > This plugin combines [vite-plugin-inject-preload](https://github.com/Applelo/vite-plugin-inject-preload) and [html-webpack-inject-preload](https://github.com/principalstudio/html-webpack-inject-preload) into one package. diff --git a/package.json b/package.json index 98fb938..2ccfa71 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "unplugin-inject-preload", "type": "module", - "version": "2.0.5", + "version": "2.1.0", "packageManager": "pnpm@9.9.0", "description": "Inject for Webpack/ViteJS", "license": "MIT", @@ -93,7 +93,7 @@ "webpack-sources": "^3.2.3" }, "devDependencies": { - "@antfu/eslint-config": "2.27.3", + "@antfu/eslint-config": "3.0.0", "@rspack/core": "^1.0.0", "@types/mime-types": "^2.1.4", "@types/node": "^22.5.1", diff --git a/playground/rspack/rspack.config.js b/playground/rspack/rspack.config.js index 51a962e..189af4e 100644 --- a/playground/rspack/rspack.config.js +++ b/playground/rspack/rspack.config.js @@ -1,18 +1,22 @@ -const rspack = require('@rspack/core') -const UnpluginInjectPreload = require('unplugin-inject-preload/rspack').default -// const HtmlWebpackPlugin = require('html-webpack-plugin') +const path = require('node:path') +// const rspack = require('@rspack/core') +const UnpluginInjectPreload = require('unplugin-inject-preload/rspack') +const HtmlWebpackPlugin = require('html-webpack-plugin') /** @type {import('@rspack/cli').Configuration} */ const config = { context: __dirname, entry: './../src/main.ts', output: { - publicPath: 'dist', + publicPath: path.join(__dirname, 'dist'), filename: 'main.js', - path: 'dist', + path: path.join(__dirname, 'dist'), clean: true, assetModuleFilename: '[name].[hash][ext][query]', }, + experiments: { + css: true, + }, module: { rules: [ { @@ -23,39 +27,57 @@ const config = { test: /\.(woff|woff2|eot|ttf|otf)$/i, type: 'asset/resource', }, + { + test: /\.ts$/, + loader: 'builtin:swc-loader', + options: { + jsc: { + parser: { + syntax: 'typescript', + }, + }, + }, + type: 'javascript/auto', + }, ], }, + resolve: { + extensions: ['.ts', '.js'], + extensionAlias: { + '.js': ['.js', '.ts'], + }, + }, plugins: [ - new rspack.HtmlRspackPlugin({ - minify: false, - templateContent: ` - - - - - - -

Hello World

- - `, - }), - // new HtmlWebpackPlugin({ - // inject: false, + // new rspack.HtmlRspackPlugin({ // minify: false, - // templateContent: ({ htmlWebpackPlugin }) => ` + // templateContent: ` // // // // - // ${htmlWebpackPlugin.tags.headTags} // // //

Hello World

- // ${htmlWebpackPlugin.tags.bodyTags} // - // - // `, + // `, // }), + new HtmlWebpackPlugin({ + inject: false, + minify: false, + templateContent: ({ htmlWebpackPlugin }) => ` + + + + + ${htmlWebpackPlugin.tags.headTags} + + +

Hello World

+ ${htmlWebpackPlugin.tags.bodyTags} + + + `, + }), UnpluginInjectPreload({ injectTo: 'custom', files: [ diff --git a/playground/webpack/webpack.config.js b/playground/webpack/webpack.config.js index af4a7ba..88b15ae 100644 --- a/playground/webpack/webpack.config.js +++ b/playground/webpack/webpack.config.js @@ -1,7 +1,7 @@ const path = require('node:path') const MiniCssExtractPlugin = require('mini-css-extract-plugin') const HtmlWebpackPlugin = require('html-webpack-plugin') -const UnpluginInjectPreload = require('unplugin-inject-preload/webpack').default +const UnpluginInjectPreload = require('unplugin-inject-preload/webpack') module.exports = { entry: path.resolve(__dirname, './../src/main.ts'), diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 548aff2..fead056 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -19,8 +19,8 @@ importers: version: 3.2.3 devDependencies: '@antfu/eslint-config': - specifier: 2.27.3 - version: 2.27.3(@typescript-eslint/utils@8.3.0(eslint@9.9.1)(typescript@5.5.4))(@vue/compiler-sfc@3.4.38)(eslint@9.9.1)(typescript@5.5.4)(vitest@2.0.5(@types/node@22.5.1)(terser@5.31.6)) + specifier: 3.0.0 + version: 3.0.0(@typescript-eslint/utils@8.3.0(eslint@9.9.1)(typescript@5.5.4))(@vue/compiler-sfc@3.4.38)(eslint@9.9.1)(typescript@5.5.4)(vitest@2.0.5(@types/node@22.5.1)(terser@5.31.6)) '@rspack/core': specifier: ^1.0.0 version: 1.0.0 @@ -133,15 +133,15 @@ packages: resolution: {integrity: sha512-30iZtAPgz+LTIYoeivqYo853f02jBYSd5uGnGpkFV0M3xOt9aN73erkgYAmZU43x4VfqcnLxW9Kpg3R5LC4YYw==} engines: {node: '>=6.0.0'} - '@antfu/eslint-config@2.27.3': - resolution: {integrity: sha512-Y2Vh/LvPAaYoyLwCiZHJ7p76LEIGg6debeUA4Qs+KOrlGuXLQWRmdZlC6SB33UDNzXqkFeaXAlEcYUqvYoiMKA==} + '@antfu/eslint-config@3.0.0': + resolution: {integrity: sha512-3HC35LrsW5kvHyVY2U6yat3Uz20/9Re5137LAKqAtl2tKictef2CmdYk5z+qK4UsaY32MMfg98MhuBbvAvZF1w==} hasBin: true peerDependencies: '@eslint-react/eslint-plugin': ^1.5.8 '@prettier/plugin-xml': ^3.4.1 '@unocss/eslint-plugin': '>=0.50.0' astro-eslint-parser: ^1.0.2 - eslint: '>=8.40.0' + eslint: ^9.5.0 eslint-plugin-astro: ^1.2.0 eslint-plugin-format: '>=0.1.0' eslint-plugin-react-hooks: ^4.6.0 @@ -201,13 +201,13 @@ packages: resolution: {integrity: sha512-EStJpq4OuY8xYfhGVXngigBJRWxftKX9ksiGDnmlY3o7B/V7KIAc9X4oiK87uPJSc/vs5L869bem5fhZa8caZw==} engines: {node: '>=6.9.0'} - '@babel/parser@7.25.4': - resolution: {integrity: sha512-nq+eWrOgdtu3jG5Os4TQP3x3cLA8hR8TvJNjD8vnPa20WGycimcparWnLK4jJhElTK6SDyuJo1weMKO/5LpmLA==} + '@babel/parser@7.25.6': + resolution: {integrity: sha512-trGdfBdbD0l1ZPmcJ83eNxB9rbEax4ALFTF7fN386TMYbeCQbyme5cOEXQhbGXKebwGaB/J52w1mrklMcbgy6Q==} engines: {node: '>=6.0.0'} hasBin: true - '@babel/types@7.25.4': - resolution: {integrity: sha512-zQ1ijeeCXVEh+aNL0RlmkPkG8HUiDcU2pzQQFjtbntgAczRASFzj4H+6+bV+dy1ntKR14I/DypeuRG1uma98iQ==} + '@babel/types@7.25.6': + resolution: {integrity: sha512-/l42B1qxpG6RdfYf343Uw1vmDjeNhneUXtzhojE7pDgfpEypmRhI6j1kr17XCVv4Cgl9HdAiQY2x0GwKm7rWCw==} engines: {node: '>=6.9.0'} '@bcoe/v8-coverage@0.2.3': @@ -531,6 +531,10 @@ packages: resolution: {integrity: sha512-G/M/tIiMrTAxEWRfLfQJMmGNX28IxBg4PBz8XqQhqUHLFI6TL2htpIB1iQCj144V5ee/JaKyT9/WZ0MGZWfA7A==} engines: {node: ^12.0.0 || ^14.0.0 || >=16.0.0} + '@eslint/compat@1.1.1': + resolution: {integrity: sha512-lpHyRyplhGPL5mGEh6M9O5nnKk0Gz4bFI+Zu6tKlPpDUN7XshWvH9C/px4UVm87IAANE0W81CEsNGbS1KlzXpA==} + engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} + '@eslint/config-array@0.18.0': resolution: {integrity: sha512-fTxvnS1sRMu3+JjXwJG0j/i4RT9u4qJ+lqS/yCGap4lH4zZGzQ7tu+xZqQmcMZq5OBZDL4QRxQzRjkWcGt8IVw==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} @@ -801,31 +805,8 @@ packages: resolution: {integrity: sha512-7MZf4lburSUZoEenwazwUDKHhqyfnLCGnQ/tKcUtztfmVzfjZfRn/EaiT0AKkYGnL2U8AGsw89oUeVyvaOLVCw==} engines: {node: '>=16.0.0'} - '@stylistic/eslint-plugin-js@2.6.4': - resolution: {integrity: sha512-kx1hS3xTvzxZLdr/DCU/dLBE++vcP97sHeEFX2QXhk1Ipa4K1rzPOLw1HCbf4mU3s+7kHP5eYpDe+QteEOFLug==} - engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} - peerDependencies: - eslint: '>=8.40.0' - - '@stylistic/eslint-plugin-jsx@2.6.4': - resolution: {integrity: sha512-bIvVhdtjmyu3S10V7QRIuawtCZSq9gRmzAX23ucjCOdSFzEwlq+di0IM0riBAvvQerrJL4SM6G3xgyPs8BSXIA==} - engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} - peerDependencies: - eslint: '>=8.40.0' - - '@stylistic/eslint-plugin-plus@2.6.4': - resolution: {integrity: sha512-EuRvtxhf7Hv8OoMIePulP/6rBJIgPTu1l5GAm1780WcF1Cl8bOZXIn84Pdac5pNv6lVlzCOFm8MD3VE+2YROuA==} - peerDependencies: - eslint: '*' - - '@stylistic/eslint-plugin-ts@2.6.4': - resolution: {integrity: sha512-yxL8Hj6WkObw1jfiLpBzKy5yfxY6vwlwO4miq34ySErUjUecPV5jxfVbOe4q1QDPKemQGPq93v7sAQS5PzM8lA==} - engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} - peerDependencies: - eslint: '>=8.40.0' - - '@stylistic/eslint-plugin@2.6.4': - resolution: {integrity: sha512-euUGnjzH8EOqEYTGk9dB2OBINp0FX1nuO7/k4fO82zNRBIKZgJoDwTLM4Ce+Om6W1Qmh1PrZjCr4jh4tMEXGPQ==} + '@stylistic/eslint-plugin@2.7.1': + resolution: {integrity: sha512-JqnHom8CP14oOgPhwTPbn0QgsBJwgNySQSe00V9GQQDlY1tEqZUlK4jM2DIOJ5nE+oXoy51vZWHnHkfZ6rEruw==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} peerDependencies: eslint: '>=8.40.0' @@ -1635,8 +1616,10 @@ packages: peerDependencies: eslint: '>=6.0.0' - eslint-config-flat-gitignore@0.1.8: - resolution: {integrity: sha512-OEUbS2wzzYtUfshjOqzFo4Bl4lHykXUdM08TCnYNl7ki+niW4Q1R0j0FDFDr0vjVsI5ZFOz5LvluxOP+Ew+dYw==} + eslint-config-flat-gitignore@0.3.0: + resolution: {integrity: sha512-0Ndxo4qGhcewjTzw52TK06Mc00aDtHNTdeeW2JfONgDcLkRO/n/BteMRzNVpLQYxdCC/dFEilfM9fjjpGIJ9Og==} + peerDependencies: + eslint: ^9.5.0 eslint-flat-config-utils@0.3.1: resolution: {integrity: sha512-eFT3EaoJN1hlN97xw4FIEX//h0TiFUobgl2l5uLkIwhVN9ahGq95Pbs+i1/B5UACA78LO3rco3JzuvxLdTUOPA==} @@ -1665,8 +1648,8 @@ packages: peerDependencies: eslint: '>=8' - eslint-plugin-import-x@4.1.0: - resolution: {integrity: sha512-1BYJU0C5NBJLY4qukmwDbFrf2w8fLGEU9zZV3viWa7gNnbn4o4meQy5O4LVXn56eFh9Y4fQxu3udhIqQuVITvw==} + eslint-plugin-import-x@4.1.1: + resolution: {integrity: sha512-dBEM8fACIFNt4H7GoOaRmnH6evJW6JSTJTYYgmRd3vI4geBTjgDM/JyUDKUwIw0HDSyI+u7Vs3vFRXUo/BOAtA==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} peerDependencies: eslint: ^8.57.0 || ^9.0.0 @@ -1972,8 +1955,8 @@ packages: resolution: {integrity: sha512-VaUJspBffn/LMCJVoMvSAdmscJyS1auj5Zulnn5UoYcY531UWmdwhRWkcGKnGU93m5HSXP9LP2usOryrBtQowA==} engines: {node: '>=16'} - get-tsconfig@4.7.6: - resolution: {integrity: sha512-ZAqrLlu18NbDdRaHq+AKXzAmqIUPswPWKUchfytdAjiRFnCe5ojG2bstg6mRiZabkKfCoL/e98pbBELIV/YCeA==} + get-tsconfig@4.8.0: + resolution: {integrity: sha512-Pgba6TExTZ0FJAn1qkJAjIeKoDJ3CsI2ChuLohJnZl/tTU8MVrq3b+2t5UOPfRa4RMsorClBjJALkJUMjG1PAw==} glob-parent@5.1.2: resolution: {integrity: sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==} @@ -3628,22 +3611,22 @@ snapshots: '@jridgewell/gen-mapping': 0.3.5 '@jridgewell/trace-mapping': 0.3.25 - '@antfu/eslint-config@2.27.3(@typescript-eslint/utils@8.3.0(eslint@9.9.1)(typescript@5.5.4))(@vue/compiler-sfc@3.4.38)(eslint@9.9.1)(typescript@5.5.4)(vitest@2.0.5(@types/node@22.5.1)(terser@5.31.6))': + '@antfu/eslint-config@3.0.0(@typescript-eslint/utils@8.3.0(eslint@9.9.1)(typescript@5.5.4))(@vue/compiler-sfc@3.4.38)(eslint@9.9.1)(typescript@5.5.4)(vitest@2.0.5(@types/node@22.5.1)(terser@5.31.6))': dependencies: '@antfu/install-pkg': 0.4.1 '@clack/prompts': 0.7.0 '@eslint-community/eslint-plugin-eslint-comments': 4.4.0(eslint@9.9.1) - '@stylistic/eslint-plugin': 2.6.4(eslint@9.9.1)(typescript@5.5.4) + '@stylistic/eslint-plugin': 2.7.1(eslint@9.9.1)(typescript@5.5.4) '@typescript-eslint/eslint-plugin': 8.3.0(@typescript-eslint/parser@8.3.0(eslint@9.9.1)(typescript@5.5.4))(eslint@9.9.1)(typescript@5.5.4) '@typescript-eslint/parser': 8.3.0(eslint@9.9.1)(typescript@5.5.4) '@vitest/eslint-plugin': 1.1.0(@typescript-eslint/utils@8.3.0(eslint@9.9.1)(typescript@5.5.4))(eslint@9.9.1)(typescript@5.5.4)(vitest@2.0.5(@types/node@22.5.1)(terser@5.31.6)) eslint: 9.9.1 - eslint-config-flat-gitignore: 0.1.8 + eslint-config-flat-gitignore: 0.3.0(eslint@9.9.1) eslint-flat-config-utils: 0.3.1 eslint-merge-processors: 0.1.0(eslint@9.9.1) eslint-plugin-antfu: 2.3.6(eslint@9.9.1) eslint-plugin-command: 0.2.3(eslint@9.9.1) - eslint-plugin-import-x: 4.1.0(eslint@9.9.1)(typescript@5.5.4) + eslint-plugin-import-x: 4.1.1(eslint@9.9.1)(typescript@5.5.4) eslint-plugin-jsdoc: 50.2.2(eslint@9.9.1) eslint-plugin-jsonc: 2.16.0(eslint@9.9.1) eslint-plugin-markdown: 5.1.0(eslint@9.9.1) @@ -3697,11 +3680,11 @@ snapshots: js-tokens: 4.0.0 picocolors: 1.0.1 - '@babel/parser@7.25.4': + '@babel/parser@7.25.6': dependencies: - '@babel/types': 7.25.4 + '@babel/types': 7.25.6 - '@babel/types@7.25.4': + '@babel/types@7.25.6': dependencies: '@babel/helper-string-parser': 7.24.8 '@babel/helper-validator-identifier': 7.24.7 @@ -3891,6 +3874,8 @@ snapshots: '@eslint-community/regexpp@4.11.0': {} + '@eslint/compat@1.1.1': {} + '@eslint/config-array@0.18.0': dependencies: '@eslint/object-schema': 2.1.4 @@ -4152,47 +4137,15 @@ snapshots: '@rspack/lite-tapable@1.0.0': {} - '@stylistic/eslint-plugin-js@2.6.4(eslint@9.9.1)': - dependencies: - '@types/eslint': 9.6.1 - acorn: 8.12.1 - eslint: 9.9.1 - eslint-visitor-keys: 4.0.0 - espree: 10.1.0 - - '@stylistic/eslint-plugin-jsx@2.6.4(eslint@9.9.1)': + '@stylistic/eslint-plugin@2.7.1(eslint@9.9.1)(typescript@5.5.4)': dependencies: - '@stylistic/eslint-plugin-js': 2.6.4(eslint@9.9.1) '@types/eslint': 9.6.1 + '@typescript-eslint/utils': 8.3.0(eslint@9.9.1)(typescript@5.5.4) eslint: 9.9.1 eslint-visitor-keys: 4.0.0 espree: 10.1.0 estraverse: 5.3.0 picomatch: 4.0.2 - - '@stylistic/eslint-plugin-plus@2.6.4(eslint@9.9.1)': - dependencies: - '@types/eslint': 9.6.1 - eslint: 9.9.1 - - '@stylistic/eslint-plugin-ts@2.6.4(eslint@9.9.1)(typescript@5.5.4)': - dependencies: - '@stylistic/eslint-plugin-js': 2.6.4(eslint@9.9.1) - '@types/eslint': 9.6.1 - '@typescript-eslint/utils': 8.3.0(eslint@9.9.1)(typescript@5.5.4) - eslint: 9.9.1 - transitivePeerDependencies: - - supports-color - - typescript - - '@stylistic/eslint-plugin@2.6.4(eslint@9.9.1)(typescript@5.5.4)': - dependencies: - '@stylistic/eslint-plugin-js': 2.6.4(eslint@9.9.1) - '@stylistic/eslint-plugin-jsx': 2.6.4(eslint@9.9.1) - '@stylistic/eslint-plugin-plus': 2.6.4(eslint@9.9.1) - '@stylistic/eslint-plugin-ts': 2.6.4(eslint@9.9.1)(typescript@5.5.4) - '@types/eslint': 9.6.1 - eslint: 9.9.1 transitivePeerDependencies: - supports-color - typescript @@ -4452,7 +4405,7 @@ snapshots: '@vue/compiler-core@3.4.38': dependencies: - '@babel/parser': 7.25.4 + '@babel/parser': 7.25.6 '@vue/shared': 3.4.38 entities: 4.5.0 estree-walker: 2.0.2 @@ -4465,7 +4418,7 @@ snapshots: '@vue/compiler-sfc@3.4.38': dependencies: - '@babel/parser': 7.25.4 + '@babel/parser': 7.25.6 '@vue/compiler-core': 3.4.38 '@vue/compiler-dom': 3.4.38 '@vue/compiler-ssr': 3.4.38 @@ -5106,10 +5059,11 @@ snapshots: eslint: 9.9.1 semver: 7.6.3 - eslint-config-flat-gitignore@0.1.8: + eslint-config-flat-gitignore@0.3.0(eslint@9.9.1): dependencies: + '@eslint/compat': 1.1.1 + eslint: 9.9.1 find-up-simple: 1.0.0 - parse-gitignore: 2.0.0 eslint-flat-config-utils@0.3.1: dependencies: @@ -5145,7 +5099,7 @@ snapshots: eslint: 9.9.1 eslint-compat-utils: 0.5.1(eslint@9.9.1) - eslint-plugin-import-x@4.1.0(eslint@9.9.1)(typescript@5.5.4): + eslint-plugin-import-x@4.1.1(eslint@9.9.1)(typescript@5.5.4): dependencies: '@typescript-eslint/typescript-estree': 8.3.0(typescript@5.5.4) '@typescript-eslint/utils': 8.3.0(eslint@9.9.1)(typescript@5.5.4) @@ -5153,7 +5107,7 @@ snapshots: doctrine: 3.0.0 eslint: 9.9.1 eslint-import-resolver-node: 0.3.9 - get-tsconfig: 4.7.6 + get-tsconfig: 4.8.0 is-glob: 4.0.3 minimatch: 9.0.5 semver: 7.6.3 @@ -5204,7 +5158,7 @@ snapshots: enhanced-resolve: 5.17.1 eslint: 9.9.1 eslint-plugin-es-x: 7.8.0(eslint@9.9.1) - get-tsconfig: 4.7.6 + get-tsconfig: 4.8.0 globals: 15.9.0 ignore: 5.3.2 minimatch: 9.0.5 @@ -5569,7 +5523,7 @@ snapshots: get-stream@8.0.1: {} - get-tsconfig@4.7.6: + get-tsconfig@4.8.0: dependencies: resolve-pkg-maps: 1.0.0 @@ -5968,8 +5922,8 @@ snapshots: magicast@0.3.5: dependencies: - '@babel/parser': 7.25.4 - '@babel/types': 7.25.4 + '@babel/parser': 7.25.6 + '@babel/types': 7.25.6 source-map-js: 1.2.0 make-dir@4.0.0: @@ -6900,7 +6854,7 @@ snapshots: tsx@4.19.0: dependencies: esbuild: 0.23.1 - get-tsconfig: 4.7.6 + get-tsconfig: 4.8.0 optionalDependencies: fsevents: 2.3.3 diff --git a/src/adapter/HtmlRspackPlugin.ts b/src/adapter/HtmlRspackPlugin.ts index 207cfc8..2a36bb6 100644 --- a/src/adapter/HtmlRspackPlugin.ts +++ b/src/adapter/HtmlRspackPlugin.ts @@ -28,10 +28,14 @@ export function htmlRspackPluginAdapter(args: { const logger = compilation.getLogger(name) const assets = getAssetsForWebpackOrRspack(compilation) const tags: HtmlTagDescriptor[] = [] + + const publicPath = typeof compilation.outputOptions.publicPath === 'string' && compilation.outputOptions.publicPath === 'auto' + ? compilation.outputOptions.publicPath + : '' const tagsAttributes = getTagsAttributes( assets, options, - compilation.outputOptions.publicPath || '', + publicPath, logger, ) @@ -62,9 +66,12 @@ export function htmlRspackPluginAdapter(args: { ) } + const source = new RawSource(updateSourceString) + compilation.updateAsset( asset.name, - new RawSource(updateSourceString), + // @ts-expect-error Same source as webpack-sources + source, asset.info, ) }) diff --git a/src/helper/getAssets.ts b/src/helper/getAssets.ts index de66b74..f9a8776 100644 --- a/src/helper/getAssets.ts +++ b/src/helper/getAssets.ts @@ -1,5 +1,5 @@ import type { OutputBundle } from 'rollup' -import type { Compilation as WebpackCompilation } from 'webpack' +import type { Asset, Compilation as WebpackCompilation } from 'webpack' import type { AssetsSet, UnpluginCompilation } from './../types' export function getAssetsForViteJS(bundle: OutputBundle) { @@ -28,9 +28,12 @@ export function getAssetsForWebpackOrRspack( } // rspack else { - const assetsStats = compilation.getStats().toJson({ all: false, assets: true }).assets || [] - assetsInfo = new Map(assetsStats.map(asset => [asset.name, asset.info])) - outputs = Array.from(assetsStats.map(asset => asset.name)).sort() + const assets = compilation.getAssets() || [] + assetsInfo = new Map( + assets + .map(asset => [asset.name, asset.info as Asset]), + ) + outputs = Array.from(assets.map(asset => asset.name)).sort() } outputs.forEach((output) => { diff --git a/test/rspack.test.ts b/test/rspack.test.ts index 8894747..c58d460 100644 --- a/test/rspack.test.ts +++ b/test/rspack.test.ts @@ -37,6 +37,9 @@ async function buildRspack(pluginConfig: Options, plugin: 'HtmlWebpackPlugin' | clean: true, assetModuleFilename: '[name]-[hash][ext][query]', }, + experiments: { + css: true, + }, resolve: { extensions: ['.ts', '.js'], extensionAlias: { @@ -53,6 +56,18 @@ async function buildRspack(pluginConfig: Options, plugin: 'HtmlWebpackPlugin' | test: /\.(woff|woff2|eot|ttf|otf)$/i, type: 'asset/resource', }, + { + test: /\.ts$/, + loader: 'builtin:swc-loader', + options: { + jsc: { + parser: { + syntax: 'typescript', + }, + }, + }, + type: 'javascript/auto', + }, ], }, plugins: [ @@ -102,7 +117,7 @@ describe('expect rspack with HtmlWebpackPlugin', () => { } }) -describe('expect rspack with HtmlRspackPlugin', () => { +describe.skip('expect rspack with HtmlRspackPlugin', () => { for (const key in configs) { if (Object.prototype.hasOwnProperty.call(configs, key)) { const config = configs[key]