Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions packages/plugin-vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,40 @@
"main": "./dist/index.cjs",
"types": "./dist/index.d.ts",
"files": [
"dist"
"dist",
"compiled"
],
"scripts": {
"build": "rslib build",
"dev": "rslib build -w",
"bump": "pnpx bumpp --no-tag"
},
"dependencies": {
"vue-loader": "^17.4.2",
"webpack": "^5.102.1"
"chalk": "^4.1.0",
"hash-sum": "^2.0.0",
"webpack": "^5.102.1",
"watchpack": "^2.4.0"
},
"devDependencies": {
"@rsbuild/core": "workspace:*",
"@rslib/core": "0.15.1",
"@scripts/test-helper": "workspace:*",
"@types/node": "^22.18.11",
"typescript": "^5.9.3",
"vue": "^3.5.22"
"vue": "^3.5.22",
"vue-loader": "^17.4.2"
},
"peerDependencies": {
"@rsbuild/core": "1.x"
},
"peerDependenciesMeta": {
"@vue/compiler-sfc": {
"optional": true
},
"vue": {
"optional": true
}
},
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org/"
Expand Down
53 changes: 52 additions & 1 deletion packages/plugin-vue/rslib.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,54 @@
import fs from 'node:fs';
import path from 'node:path';
import { dualPackage } from '@rsbuild/config/rslib.config.ts';
import { defineConfig, rsbuild } from '@rslib/core';

export default dualPackage;
const pluginTrimVueLoaderPackageJson: rsbuild.RsbuildPlugin = {
name: 'trim-vue-loader-package-json',
setup(api) {
api.onBeforeBuild(() => {
const cwd = process.cwd();
const sourceRoot = path.join(cwd, 'node_modules/vue-loader');
const targetRoot = path.join(cwd, 'compiled/vue-loader');

fs.rmSync(targetRoot, { recursive: true, force: true });

fs.cpSync(path.join(sourceRoot, 'dist'), path.join(targetRoot, 'dist'), {
recursive: true,
});

for (const file of ['package.json', 'LICENSE']) {
fs.copyFileSync(
path.join(sourceRoot, file),
path.join(targetRoot, file),
);
}
});

api.onAfterBuild(() => {
const pkgPath = path.join(
process.cwd(),
'compiled/vue-loader/package.json',
);
const pkgJson = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
const fields = ['name', 'author', 'version', 'funding', 'license'];
const trimmed = Object.fromEntries(
fields
.filter((field) => field in pkgJson)
.map((field) => [field, pkgJson[field]]),
);
fs.writeFileSync(
pkgPath,
`${JSON.stringify(trimmed, null, 2)}\n`,
'utf8',
);
});
},
};

export default defineConfig(
rsbuild.mergeRsbuildConfig(dualPackage, {
lib: [],
plugins: [pluginTrimVueLoaderPackageJson],
}),
);
7 changes: 5 additions & 2 deletions packages/plugin-vue/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { createRequire } from 'node:module';
import type { EnvironmentConfig, RsbuildPlugin } from '@rsbuild/core';
import { type VueLoaderOptions, VueLoaderPlugin } from 'vue-loader';
import {
type VueLoaderOptions,
VueLoaderPlugin,
} from '../compiled/vue-loader/dist/index.js';
import { applySplitChunksRule } from './splitChunks.js';

const require = createRequire(import.meta.url);
Expand Down Expand Up @@ -90,7 +93,7 @@ export function pluginVue(options: PluginVueOptions = {}): RsbuildPlugin {
.rule(CHAIN_ID.RULE.VUE)
.test(VUE_REGEXP)
.use(CHAIN_ID.USE.VUE)
.loader(require.resolve('vue-loader'))
.loader(require.resolve('../compiled/vue-loader/dist/index.js'))
.options(vueLoaderOptions);

// Support for lang="postcss" and lang="pcss" in SFC
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-vue/tests/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ exports[`plugin-vue > should add vue-loader and VueLoaderPlugin correctly 1`] =
"test": /\\\\\\.vue\\$/,
"use": [
{
"loader": "<ROOT>/node_modules/<PNPM_INNER>/vue-loader/dist/index.js",
"loader": "<ROOT>/packages/plugin-vue/compiled/vue-loader/dist/index.js",
"options": {
"compilerOptions": {
"preserveWhitespace": false,
Expand Down Expand Up @@ -41,7 +41,7 @@ exports[`plugin-vue > should allow to configure vueLoader options 1`] = `
"test": /\\\\\\.vue\\$/,
"use": [
{
"loader": "<ROOT>/node_modules/<PNPM_INNER>/vue-loader/dist/index.js",
"loader": "<ROOT>/packages/plugin-vue/compiled/vue-loader/dist/index.js",
"options": {
"compilerOptions": {
"preserveWhitespace": false,
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-vue/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
"path": "../core"
}
],
"include": ["src"]
"include": ["src", "compiled"]
}
12 changes: 12 additions & 0 deletions patches/vue-loader.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/dist/pluginWebpack5.js b/dist/pluginWebpack5.js
index 7c5eadf2ad45157aed2fd23a83ae4b1a2fb4b8ac..b9cd4eb701c366fa7f7f4782a20d4e3568705a94 100644
--- a/dist/pluginWebpack5.js
+++ b/dist/pluginWebpack5.js
@@ -61,6 +61,7 @@ const ruleSetCompiler = new RuleSetCompiler([
new BasicEffectRulePlugin('resolve'),
new BasicEffectRulePlugin('generator'),
new BasicEffectRulePlugin('layer'),
+ new BasicEffectRulePlugin('with'),
new UseEffectRulePlugin(),
]);
class VueLoaderPlugin {
20 changes: 16 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ packages:
- '!**/create-rsbuild/template-*/**'
- '!**/test-temp-*/**'

engineStrict: true

hoistPattern: []

patchedDependencies:
Expand All @@ -18,6 +20,6 @@ patchedDependencies:
http-proxy@1.18.1: patches/http-proxy@1.18.1.patch
postcss-loader@8.2.0: patches/postcss-loader@8.2.0.patch
url-loader: patches/url-loader@4.1.1.patch
vue-loader: patches/vue-loader.patch

strictPeerDependencies: false
engineStrict: true
2 changes: 1 addition & 1 deletion rstest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default defineConfig({
alias,
},
output: {
externals: ['@rsbuild/core'],
externals: ['@rsbuild/core', /\/compiled\/vue-loader/],
},
name: 'node',
globals: true,
Expand Down
Loading