rsbuild-plugin-virtual-module 0.1.1 → 0.1.2

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/README.md CHANGED
@@ -1,6 +1,8 @@
1
- # rsbuild-plugin-virtual-module
1
+ # rsbuild-plugin-virtual-module🧙
2
2
 
3
- Example plugin for Rsbuild.
3
+ The simplest and most flexible way to build with a compiling magic 🪄
4
+
5
+ An Rsbuild plugin that allows you to create virtual modules, the pro version of [rspack-plugin-virtual-module](https://github.com/rspack-contrib/rspack-plugin-virtual-module) with loader API.
4
6
 
5
7
  <p>
6
8
  <a href="https://npmjs.com/package/rsbuild-plugin-virtual-module">
@@ -52,7 +54,7 @@ Generate virtual modules, where the key is the name of the virtual module and th
52
54
  - Type:
53
55
 
54
56
  ```ts
55
- import type { RsbuildPlugin, TransformHandler } from '@rsbuild/core';
57
+ import type { TransformHandler } from '@rsbuild/core';
56
58
 
57
59
  type VirtualModules = Record<string, TransformHandler>;
58
60
  ```
@@ -89,6 +91,13 @@ import jsonList from 'virtual-json-list';
89
91
  console.log(jsonList);
90
92
  ```
91
93
 
94
+ ### tempDir
95
+
96
+ The name of the virtual module folder under `node_modules`.
97
+
98
+ - Type: `string`
99
+ - Default: `.rsbuild-virtual-module`
100
+
92
101
  ## License
93
102
 
94
103
  [MIT](./LICENSE).
package/dist/index.cjs CHANGED
@@ -33,8 +33,8 @@ const PLUGIN_VIRTUAL_MODULE_NAME = 'rsbuild:virtual-module';
33
33
  const pluginVirtualModule = (pluginOptions = {})=>({
34
34
  name: PLUGIN_VIRTUAL_MODULE_NAME,
35
35
  async setup (api) {
36
- const TEMP_DIR = (0, external_node_path_namespaceObject.join)(process.cwd(), 'node_modules/.rsbuild-virtual-module');
37
- const { virtualModules = {} } = pluginOptions;
36
+ const { virtualModules = {}, tempDir: virtualFolderName = '.rsbuild-virtual-module' } = pluginOptions;
37
+ const TEMP_DIR = (0, external_node_path_namespaceObject.join)(api.context.rootPath, 'node_modules', virtualFolderName);
38
38
  const virtualFileAbsolutePaths = Object.keys(virtualModules).map((i)=>{
39
39
  let absolutePath = (0, external_node_path_namespaceObject.join)(TEMP_DIR, i);
40
40
  if (!(0, external_node_path_namespaceObject.extname)(absolutePath)) absolutePath = `${absolutePath}.js`;
@@ -43,6 +43,13 @@ const pluginVirtualModule = (pluginOptions = {})=>({
43
43
  absolutePath
44
44
  ];
45
45
  });
46
+ api.modifyRsbuildConfig((config)=>{
47
+ if (!config.source) config.source = {};
48
+ config.source.include = [
49
+ ...config.source.include || [],
50
+ TEMP_DIR
51
+ ];
52
+ });
46
53
  api.onBeforeCreateCompiler(async ()=>{
47
54
  await (0, promises_namespaceObject.mkdir)(TEMP_DIR, {
48
55
  recursive: true
package/dist/index.d.ts CHANGED
@@ -1,7 +1,15 @@
1
1
  import type { RsbuildPlugin, TransformHandler } from '@rsbuild/core';
2
2
  type VirtualModules = Record<string, TransformHandler>;
3
3
  interface PluginVirtualModuleOptions {
4
+ /**
5
+ * Generate virtual modules, where the key is the name of the virtual module and the value is `TransformHandler`. See [Rsbuild - api.transform](https://rsbuild.dev/plugins/dev/core#apitransform)
6
+ */
4
7
  virtualModules?: VirtualModules;
8
+ /**
9
+ * The name of the virtual module folder under `node_modules`
10
+ * @default '.rsbuild-virtual-module'
11
+ */
12
+ tempDir?: string;
5
13
  }
6
14
  declare const PLUGIN_VIRTUAL_MODULE_NAME = "rsbuild:virtual-module";
7
15
  declare const pluginVirtualModule: (pluginOptions?: PluginVirtualModuleOptions) => RsbuildPlugin;
package/dist/index.js CHANGED
@@ -4,8 +4,8 @@ const PLUGIN_VIRTUAL_MODULE_NAME = 'rsbuild:virtual-module';
4
4
  const pluginVirtualModule = (pluginOptions = {})=>({
5
5
  name: PLUGIN_VIRTUAL_MODULE_NAME,
6
6
  async setup (api) {
7
- const TEMP_DIR = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(process.cwd(), 'node_modules/.rsbuild-virtual-module');
8
- const { virtualModules = {} } = pluginOptions;
7
+ const { virtualModules = {}, tempDir: virtualFolderName = '.rsbuild-virtual-module' } = pluginOptions;
8
+ const TEMP_DIR = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(api.context.rootPath, 'node_modules', virtualFolderName);
9
9
  const virtualFileAbsolutePaths = Object.keys(virtualModules).map((i)=>{
10
10
  let absolutePath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(TEMP_DIR, i);
11
11
  if (!(0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.extname)(absolutePath)) absolutePath = `${absolutePath}.js`;
@@ -14,6 +14,13 @@ const pluginVirtualModule = (pluginOptions = {})=>({
14
14
  absolutePath
15
15
  ];
16
16
  });
17
+ api.modifyRsbuildConfig((config)=>{
18
+ if (!config.source) config.source = {};
19
+ config.source.include = [
20
+ ...config.source.include || [],
21
+ TEMP_DIR
22
+ ];
23
+ });
17
24
  api.onBeforeCreateCompiler(async ()=>{
18
25
  await (0, __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__.mkdir)(TEMP_DIR, {
19
26
  recursive: true
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rsbuild-plugin-virtual-module",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/rspack-contrib/rsbuild-plugin-virtual-module"
@@ -17,22 +17,29 @@
17
17
  "main": "./dist/index.js",
18
18
  "module": "./dist/index.mjs",
19
19
  "types": "./dist/index.d.ts",
20
- "files": [
21
- "dist"
22
- ],
20
+ "files": ["dist"],
21
+ "scripts": {
22
+ "build": "rslib build",
23
+ "dev": "rslib build --watch",
24
+ "lint": "biome check .",
25
+ "lint:write": "biome check . --write",
26
+ "prepare": "simple-git-hooks && npm run build",
27
+ "test": "playwright test",
28
+ "bump": "npx bumpp"
29
+ },
23
30
  "simple-git-hooks": {
24
31
  "pre-commit": "npm run lint:write"
25
32
  },
26
33
  "devDependencies": {
27
34
  "@biomejs/biome": "^1.9.4",
28
35
  "@playwright/test": "^1.51.1",
29
- "@rsbuild/core": "^1.3.1",
36
+ "@rsbuild/core": "^1.3.13",
30
37
  "@rslib/core": "^0.6.1",
31
38
  "@types/node": "^22.13.16",
32
39
  "playwright": "^1.51.1",
33
40
  "simple-git-hooks": "^2.12.1",
34
41
  "typescript": "^5.8.2",
35
- "rsbuild-plugin-virtual-module": "0.1.1"
42
+ "rsbuild-plugin-virtual-module": "workspace:*"
36
43
  },
37
44
  "peerDependencies": {
38
45
  "@rsbuild/core": "1.x"
@@ -42,16 +49,9 @@
42
49
  "optional": true
43
50
  }
44
51
  },
52
+ "packageManager": "pnpm@10.5.2",
45
53
  "publishConfig": {
46
54
  "access": "public",
47
55
  "registry": "https://registry.npmjs.org/"
48
- },
49
- "scripts": {
50
- "build": "rslib build",
51
- "dev": "rslib build --watch",
52
- "lint": "biome check .",
53
- "lint:write": "biome check . --write",
54
- "test": "playwright test",
55
- "bump": "npx bumpp"
56
56
  }
57
- }
57
+ }