@rsbuild/plugin-vue2 1.0.1-beta.8 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2023-present Bytedance, Inc. and its affiliates.
3
+ Copyright (c) 2024 Rspack Contrib
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,19 +1,125 @@
1
- <p align="center">
2
- <a href="https://rsbuild.dev" target="blank"><img src="https://github.com/web-infra-dev/rsbuild/assets/7237365/84abc13e-b620-468f-a90b-dbf28e7e9427" alt="Rsbuild Logo" /></a>
1
+ # @rsbuild/plugin-vue2
2
+
3
+ Provides support for Vue 2 SFC (Single File Components). The plugin internally integrates [vue-loader](https://vue-loader.vuejs.org/) v15.
4
+
5
+ > @rsbuild/plugin-vue2 only supports Vue >= 2.7.0.
6
+
7
+ <p>
8
+ <a href="https://npmjs.com/package/@rsbuild/plugin-vue2">
9
+ <img src="https://img.shields.io/npm/v/@rsbuild/plugin-vue2?style=flat-square&colorA=564341&colorB=EDED91" alt="npm version" />
10
+ </a>
11
+ <img src="https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square&colorA=564341&colorB=EDED91" alt="license" />
3
12
  </p>
4
13
 
5
- # Rsbuild
14
+ ## Usage
15
+
16
+ Install:
17
+
18
+ ```bash
19
+ npm add @rsbuild/plugin-vue2 -D
20
+ ```
21
+
22
+ Add plugin to your `rsbuild.config.ts`:
23
+
24
+ ```ts
25
+ // rsbuild.config.ts
26
+ import { pluginVue2 } from "@rsbuild/plugin-vue2";
27
+
28
+ export default {
29
+ plugins: [pluginVue2()],
30
+ };
31
+ ```
32
+
33
+ After registering the plugin, you can import `*.vue` files in your code.
34
+
35
+ ## Options
36
+
37
+ If you need to customize the compilation behavior of Vue, you can use the following configs.
38
+
39
+ ### vueLoaderOptions
40
+
41
+ Options passed to `vue-loader`, please refer to the [vue-loader documentation](https://vue-loader.vuejs.org/) for detailed usage.
42
+
43
+ - **Type:** `VueLoaderOptions`
44
+ - **Default:**
45
+
46
+ ```js
47
+ const defaultOptions = {
48
+ compilerOptions: {
49
+ whitespace: "condense",
50
+ },
51
+ experimentalInlineMatchResource: true,
52
+ };
53
+ ```
54
+
55
+ - **Example:**
56
+
57
+ ```ts
58
+ pluginVue2({
59
+ vueLoaderOptions: {
60
+ hotReload: false,
61
+ },
62
+ });
63
+ ```
64
+
65
+ > The Vue 2 plugin is using the `vue-loader` v15. Please be aware that there may be configuration differences between v15 and the latest version.
66
+
67
+ ### splitChunks
68
+
69
+ When [chunkSplit.strategy](/config/performance/chunk-split) set to `split-by-experience`, Rsbuild will automatically split `vue` and `router` related packages into separate chunks by default:
70
+
71
+ - `lib-vue.js`: includes vue, vue-loader.
72
+ - `lib-router.js`: includes vue-router.
73
+
74
+ This option is used to control this behavior and determine whether the `vue` and `router` related packages need to be split into separate chunks.
75
+
76
+ - **Type:**
77
+
78
+ ```ts
79
+ type SplitVueChunkOptions = {
80
+ vue?: boolean;
81
+ router?: boolean;
82
+ };
83
+ ```
84
+
85
+ - **Default:**
86
+
87
+ ```ts
88
+ const defaultOptions = {
89
+ vue: true,
90
+ router: true,
91
+ };
92
+ ```
93
+
94
+ - **Example:**
95
+
96
+ ```ts
97
+ pluginVue({
98
+ splitChunks: {
99
+ vue: false,
100
+ router: false,
101
+ },
102
+ });
103
+ ```
104
+
105
+ ## FAQ
6
106
 
7
- The Rspack-based build tool. It's fast, out-of-the-box and extensible.
107
+ ### /deep/ selector causes compilation error
8
108
 
9
- ## Documentation
109
+ `/deep/` is a deprecated usage as of Vue v2.7. Since it is not a valid CSS syntax, CSS compilation tools like Lightning CSS will fail to compile it.
10
110
 
11
- https://rsbuild.dev/
111
+ You can use `:deep()` instead. See [Vue - Deep Selectors](https://vuejs.org/api/sfc-css-features.html#deep-selectors) for more details.
12
112
 
13
- ## Contributing
113
+ ```html
114
+ <style scoped>
115
+ .a :deep(.b) {
116
+ /* ... */
117
+ }
118
+ </style>
119
+ ```
14
120
 
15
- Please read the [Contributing Guide](https://github.com/web-infra-dev/rsbuild/blob/main/CONTRIBUTING.md).
121
+ > You can also refer to [Vue - RFC 0023](https://github.com/vuejs/rfcs/blob/master/active-rfcs/0023-scoped-styles-changes.md) for more details.
16
122
 
17
123
  ## License
18
124
 
19
- Rsbuild is [MIT licensed](https://github.com/web-infra-dev/rsbuild/blob/main/LICENSE).
125
+ [MIT](./LICENSE).
package/dist/index.cjs CHANGED
@@ -1,11 +1,8 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
6
  var __export = (target, all) => {
10
7
  for (var name in all)
11
8
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -18,19 +15,7 @@ var __copyProps = (to, from, except, desc) => {
18
15
  }
19
16
  return to;
20
17
  };
21
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
- // If the importer is in node compatibility mode or this is not an ESM
23
- // file that has been converted to a CommonJS file using a Babel-
24
- // compatible transform (i.e. "__esModule" has not been set), then set
25
- // "default" to the CommonJS "module.exports" for node compatibility.
26
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
- mod
28
- ));
29
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
- var __publicField = (obj, key, value) => {
31
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
32
- return value;
33
- };
34
19
 
35
20
  // src/index.ts
36
21
  var src_exports = {};
@@ -39,19 +24,25 @@ __export(src_exports, {
39
24
  pluginVue2: () => pluginVue2
40
25
  });
41
26
  module.exports = __toCommonJS(src_exports);
27
+
28
+ // node_modules/.pnpm/tsup@8.2.3_postcss@8.4.38_typescript@5.5.4/node_modules/tsup/assets/cjs_shims.js
29
+ var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
30
+ var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
31
+
32
+ // src/index.ts
33
+ var import_node_module = require("module");
42
34
  var import_vue_loader = require("vue-loader");
43
35
 
44
36
  // src/VueLoader15PitchFixPlugin.ts
45
37
  var VueLoader15PitchFixPlugin = class {
46
38
  constructor() {
47
- __publicField(this, "name", "VueLoader15PitchFixPlugin");
39
+ this.name = "VueLoader15PitchFixPlugin";
48
40
  }
49
41
  apply(compiler) {
50
42
  const { NormalModule } = compiler.webpack;
51
43
  compiler.hooks.compilation.tap(this.name, (compilation) => {
52
44
  const isExpCssOn = compilation.compiler.options?.experiments?.css;
53
- if (!isExpCssOn)
54
- return;
45
+ if (!isExpCssOn) return;
55
46
  NormalModule.getCompilationHooks(compilation).loader.tap(
56
47
  this.name,
57
48
  (loaderContext) => {
@@ -124,6 +115,7 @@ var applySplitChunksRule = (api, options = {
124
115
  };
125
116
 
126
117
  // src/index.ts
118
+ var require2 = (0, import_node_module.createRequire)(importMetaUrl);
127
119
  var PLUGIN_VUE2_NAME = "rsbuild:vue2";
128
120
  function pluginVue2(options = {}) {
129
121
  return {
@@ -159,7 +151,7 @@ function pluginVue2(options = {}) {
159
151
  compilerOptions
160
152
  };
161
153
  const rule = chain.module.rule(CHAIN_ID.RULE.VUE);
162
- rule.test(VUE_REGEXP).use(CHAIN_ID.USE.VUE).loader(require.resolve("vue-loader")).options(vueLoaderOptions);
154
+ rule.test(VUE_REGEXP).use(CHAIN_ID.USE.VUE).loader(require2.resolve("vue-loader")).options(vueLoaderOptions);
163
155
  if (chain.module.rules.has(CHAIN_ID.RULE.JS)) {
164
156
  applyResolveConfig(rule, chain.module.rule(CHAIN_ID.RULE.JS));
165
157
  }
@@ -0,0 +1,30 @@
1
+ import { RsbuildPlugin } from '@rsbuild/core';
2
+ import { VueLoaderOptions } from 'vue-loader';
3
+
4
+ type SplitVueChunkOptions = {
5
+ /**
6
+ * Whether to enable split chunking for Vue-related dependencies (e.g., vue, vue-loader).
7
+ * @default true
8
+ */
9
+ vue?: boolean;
10
+ /**
11
+ * Whether to enable split chunking for vue-router.
12
+ * @default true
13
+ */
14
+ router?: boolean;
15
+ };
16
+ type PluginVueOptions = {
17
+ /**
18
+ * Options passed to `vue-loader`.
19
+ * @see https://vue-loader.vuejs.org/
20
+ */
21
+ vueLoaderOptions?: VueLoaderOptions;
22
+ /**
23
+ * This option is used to control the split chunks behavior.
24
+ */
25
+ splitChunks?: SplitVueChunkOptions;
26
+ };
27
+ declare const PLUGIN_VUE2_NAME = "rsbuild:vue2";
28
+ declare function pluginVue2(options?: PluginVueOptions): RsbuildPlugin;
29
+
30
+ export { PLUGIN_VUE2_NAME, type PluginVueOptions, type SplitVueChunkOptions, pluginVue2 };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- import type { RsbuildPlugin } from '@rsbuild/core';
2
- import { type VueLoaderOptions } from 'vue-loader';
3
- export type SplitVueChunkOptions = {
1
+ import { RsbuildPlugin } from '@rsbuild/core';
2
+ import { VueLoaderOptions } from 'vue-loader';
3
+
4
+ type SplitVueChunkOptions = {
4
5
  /**
5
6
  * Whether to enable split chunking for Vue-related dependencies (e.g., vue, vue-loader).
6
7
  * @default true
@@ -12,7 +13,7 @@ export type SplitVueChunkOptions = {
12
13
  */
13
14
  router?: boolean;
14
15
  };
15
- export type PluginVueOptions = {
16
+ type PluginVueOptions = {
16
17
  /**
17
18
  * Options passed to `vue-loader`.
18
19
  * @see https://vue-loader.vuejs.org/
@@ -23,5 +24,7 @@ export type PluginVueOptions = {
23
24
  */
24
25
  splitChunks?: SplitVueChunkOptions;
25
26
  };
26
- export declare const PLUGIN_VUE2_NAME = "rsbuild:vue2";
27
- export declare function pluginVue2(options?: PluginVueOptions): RsbuildPlugin;
27
+ declare const PLUGIN_VUE2_NAME = "rsbuild:vue2";
28
+ declare function pluginVue2(options?: PluginVueOptions): RsbuildPlugin;
29
+
30
+ export { PLUGIN_VUE2_NAME, type PluginVueOptions, type SplitVueChunkOptions, pluginVue2 };
package/dist/index.js CHANGED
@@ -1,38 +1,17 @@
1
- import { createRequire } from 'module';
2
- var require = createRequire(import.meta['url']);
3
-
4
- var __defProp = Object.defineProperty;
5
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
7
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
8
- }) : x)(function(x) {
9
- if (typeof require !== "undefined")
10
- return require.apply(this, arguments);
11
- throw Error('Dynamic require of "' + x + '" is not supported');
12
- });
13
- var __publicField = (obj, key, value) => {
14
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
15
- return value;
16
- };
17
-
18
- // ../../node_modules/.pnpm/@modern-js+module-tools@2.56.2_typescript@5.5.2/node_modules/@modern-js/module-tools/shims/esm.js
19
- import { fileURLToPath } from "url";
20
- import path from "path";
21
-
22
1
  // src/index.ts
2
+ import { createRequire } from "node:module";
23
3
  import { VueLoaderPlugin } from "vue-loader";
24
4
 
25
5
  // src/VueLoader15PitchFixPlugin.ts
26
6
  var VueLoader15PitchFixPlugin = class {
27
7
  constructor() {
28
- __publicField(this, "name", "VueLoader15PitchFixPlugin");
8
+ this.name = "VueLoader15PitchFixPlugin";
29
9
  }
30
10
  apply(compiler) {
31
11
  const { NormalModule } = compiler.webpack;
32
12
  compiler.hooks.compilation.tap(this.name, (compilation) => {
33
13
  const isExpCssOn = compilation.compiler.options?.experiments?.css;
34
- if (!isExpCssOn)
35
- return;
14
+ if (!isExpCssOn) return;
36
15
  NormalModule.getCompilationHooks(compilation).loader.tap(
37
16
  this.name,
38
17
  (loaderContext) => {
@@ -105,6 +84,7 @@ var applySplitChunksRule = (api, options = {
105
84
  };
106
85
 
107
86
  // src/index.ts
87
+ var require2 = createRequire(import.meta.url);
108
88
  var PLUGIN_VUE2_NAME = "rsbuild:vue2";
109
89
  function pluginVue2(options = {}) {
110
90
  return {
@@ -114,11 +94,11 @@ function pluginVue2(options = {}) {
114
94
  const CSS_MODULES_REGEX = /\.modules?\.\w+$/i;
115
95
  api.modifyEnvironmentConfig((config) => {
116
96
  if (config.output.cssModules.auto === true) {
117
- config.output.cssModules.auto = (path2, query) => {
118
- if (VUE_REGEXP.test(path2)) {
97
+ config.output.cssModules.auto = (path, query) => {
98
+ if (VUE_REGEXP.test(path)) {
119
99
  return query.includes("type=style") && query.includes("module=true");
120
100
  }
121
- return CSS_MODULES_REGEX.test(path2);
101
+ return CSS_MODULES_REGEX.test(path);
122
102
  };
123
103
  }
124
104
  return config;
@@ -140,7 +120,7 @@ function pluginVue2(options = {}) {
140
120
  compilerOptions
141
121
  };
142
122
  const rule = chain.module.rule(CHAIN_ID.RULE.VUE);
143
- rule.test(VUE_REGEXP).use(CHAIN_ID.USE.VUE).loader(__require.resolve("vue-loader")).options(vueLoaderOptions);
123
+ rule.test(VUE_REGEXP).use(CHAIN_ID.USE.VUE).loader(require2.resolve("vue-loader")).options(vueLoaderOptions);
144
124
  if (chain.module.rules.has(CHAIN_ID.RULE.JS)) {
145
125
  applyResolveConfig(rule, chain.module.rule(CHAIN_ID.RULE.JS));
146
126
  }
package/package.json CHANGED
@@ -1,13 +1,7 @@
1
1
  {
2
2
  "name": "@rsbuild/plugin-vue2",
3
- "version": "1.0.1-beta.8",
4
- "description": "Vue 2 plugin of Rsbuild",
5
- "homepage": "https://rsbuild.dev",
6
- "repository": {
7
- "type": "git",
8
- "url": "https://github.com/web-infra-dev/rsbuild",
9
- "directory": "packages/plugin-vue2"
10
- },
3
+ "version": "1.0.1",
4
+ "repository": "https://github.com/rspack-contrib/rsbuild-plugin-vue2",
11
5
  "license": "MIT",
12
6
  "type": "module",
13
7
  "exports": {
@@ -17,31 +11,54 @@
17
11
  "require": "./dist/index.cjs"
18
12
  }
19
13
  },
20
- "main": "./dist/index.cjs",
14
+ "main": "./dist/index.js",
15
+ "module": "./dist/index.mjs",
21
16
  "types": "./dist/index.d.ts",
22
17
  "files": [
23
18
  "dist"
24
19
  ],
20
+ "simple-git-hooks": {
21
+ "pre-commit": "npx nano-staged"
22
+ },
23
+ "nano-staged": {
24
+ "*.{js,jsx,ts,tsx,mjs,cjs}": [
25
+ "biome check --write --no-errors-on-unmatched"
26
+ ]
27
+ },
25
28
  "dependencies": {
26
29
  "vue-loader": "^15.11.1",
27
30
  "webpack": "^5.93.0"
28
31
  },
29
32
  "devDependencies": {
30
- "typescript": "^5.5.2",
31
- "webpack": "^5.93.0",
32
- "@rsbuild/core": "1.0.1-beta.8",
33
- "@scripts/test-helper": "1.0.1-beta.8"
33
+ "@biomejs/biome": "^1.8.3",
34
+ "@playwright/test": "^1.45.3",
35
+ "@rsbuild/core": "^1.0.1-beta.16",
36
+ "@rsbuild/plugin-less": "1.0.1-beta.16",
37
+ "@types/node": "^20.14.13",
38
+ "nano-staged": "^0.8.0",
39
+ "playwright": "^1.45.3",
40
+ "simple-git-hooks": "^2.11.1",
41
+ "tsup": "^8.2.3",
42
+ "typescript": "^5.5.4",
43
+ "vue": "^2.7.14"
34
44
  },
35
45
  "peerDependencies": {
36
- "@rsbuild/core": "^1.0.1-beta.8"
46
+ "@rsbuild/core": "1.x || ^1.0.1-beta.0"
47
+ },
48
+ "peerDependenciesMeta": {
49
+ "@rsbuild/core": {
50
+ "optional": true
51
+ }
37
52
  },
38
53
  "publishConfig": {
39
54
  "access": "public",
40
- "provenance": true,
41
55
  "registry": "https://registry.npmjs.org/"
42
56
  },
43
57
  "scripts": {
44
- "build": "modern build",
45
- "dev": "modern build --watch"
58
+ "build": "tsup",
59
+ "dev": "tsup --watch",
60
+ "lint": "biome check .",
61
+ "lint:write": "biome check . --write",
62
+ "test": "playwright test"
46
63
  }
47
64
  }
@@ -1,8 +0,0 @@
1
- import type { Rspack } from '@rsbuild/core';
2
- /**
3
- * this plugin is a quick fix for issue https://github.com/web-infra-dev/rsbuild/issues/2093
4
- */
5
- export declare class VueLoader15PitchFixPlugin implements Rspack.RspackPluginInstance {
6
- readonly name = "VueLoader15PitchFixPlugin";
7
- apply(compiler: Rspack.Compiler): void;
8
- }
@@ -1,3 +0,0 @@
1
- import type { RsbuildPluginAPI } from '@rsbuild/core';
2
- import type { SplitVueChunkOptions } from '.';
3
- export declare const applySplitChunksRule: (api: RsbuildPluginAPI, options?: SplitVueChunkOptions) => void;