@rsbuild/plugin-svelte 1.0.1-rc.4 → 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/dist/index.cjs CHANGED
@@ -34,9 +34,20 @@ __export(src_exports, {
34
34
  pluginSvelte: () => pluginSvelte
35
35
  });
36
36
  module.exports = __toCommonJS(src_exports);
37
+ var import_node_fs = require("fs");
37
38
  var import_node_path = __toESM(require("path"));
38
39
  var import_core = require("@rsbuild/core");
39
40
  var PLUGIN_SVELTE_NAME = "rsbuild:svelte";
41
+ var isSvelte5 = async (sveltePath) => {
42
+ try {
43
+ const pkgPath = import_node_path.default.join(sveltePath, "package.json");
44
+ const pkgRaw = await import_node_fs.promises.readFile(pkgPath, "utf-8");
45
+ const pkgJson = JSON.parse(pkgRaw);
46
+ return pkgJson.version.startsWith("5.");
47
+ } catch (err) {
48
+ return false;
49
+ }
50
+ };
40
51
  function pluginSvelte(options = {}) {
41
52
  return {
42
53
  name: PLUGIN_SVELTE_NAME,
@@ -59,11 +70,14 @@ function pluginSvelte(options = {}) {
59
70
  api.modifyBundlerChain(
60
71
  async (chain, { CHAIN_ID, environment, isDev, isProd }) => {
61
72
  const { default: sveltePreprocess } = await import("svelte-preprocess");
73
+ const svelte5 = await isSvelte5(sveltePath);
62
74
  const environmentConfig = environment.config;
63
- chain.resolve.alias.set(
64
- "svelte",
65
- import_node_path.default.join(sveltePath, "src/runtime")
66
- );
75
+ if (!svelte5) {
76
+ chain.resolve.alias.set(
77
+ "svelte",
78
+ import_node_path.default.join(sveltePath, "src/runtime")
79
+ );
80
+ }
67
81
  chain.resolve.extensions.add(".svelte");
68
82
  chain.resolve.mainFields.add("svelte").add("...");
69
83
  chain.resolve.conditionNames.add("svelte").add("...");
@@ -88,7 +102,7 @@ function pluginSvelte(options = {}) {
88
102
  ...userLoaderOptions.compilerOptions
89
103
  }
90
104
  };
91
- chain.module.rule(CHAIN_ID.RULE.SVELTE).test(/\.svelte$/).use(CHAIN_ID.USE.SVELTE).loader(loaderPath).options(svelteLoaderOptions);
105
+ chain.module.rule(CHAIN_ID.RULE.SVELTE).test(svelte5 ? /\.(?:svelte|svelte\.js|svelte\.ts)$/ : /\.svelte$/).use(CHAIN_ID.USE.SVELTE).loader(loaderPath).options(svelteLoaderOptions);
92
106
  }
93
107
  );
94
108
  }
package/dist/index.js CHANGED
@@ -9,14 +9,25 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
9
9
  throw Error('Dynamic require of "' + x + '" is not supported');
10
10
  });
11
11
 
12
- // ../../node_modules/.pnpm/@modern-js+module-tools@2.58.3_typescript@5.5.2/node_modules/@modern-js/module-tools/shims/esm.js
12
+ // ../../node_modules/.pnpm/@modern-js+module-tools@2.59.0_typescript@5.5.2/node_modules/@modern-js/module-tools/shims/esm.js
13
13
  import path from "path";
14
14
  import { fileURLToPath } from "url";
15
15
 
16
16
  // src/index.ts
17
+ import { promises } from "fs";
17
18
  import path2 from "path";
18
19
  import { logger } from "@rsbuild/core";
19
20
  var PLUGIN_SVELTE_NAME = "rsbuild:svelte";
21
+ var isSvelte5 = async (sveltePath) => {
22
+ try {
23
+ const pkgPath = path2.join(sveltePath, "package.json");
24
+ const pkgRaw = await promises.readFile(pkgPath, "utf-8");
25
+ const pkgJson = JSON.parse(pkgRaw);
26
+ return pkgJson.version.startsWith("5.");
27
+ } catch (err) {
28
+ return false;
29
+ }
30
+ };
20
31
  function pluginSvelte(options = {}) {
21
32
  return {
22
33
  name: PLUGIN_SVELTE_NAME,
@@ -39,11 +50,14 @@ function pluginSvelte(options = {}) {
39
50
  api.modifyBundlerChain(
40
51
  async (chain, { CHAIN_ID, environment, isDev, isProd }) => {
41
52
  const { default: sveltePreprocess } = await import("svelte-preprocess");
53
+ const svelte5 = await isSvelte5(sveltePath);
42
54
  const environmentConfig = environment.config;
43
- chain.resolve.alias.set(
44
- "svelte",
45
- path2.join(sveltePath, "src/runtime")
46
- );
55
+ if (!svelte5) {
56
+ chain.resolve.alias.set(
57
+ "svelte",
58
+ path2.join(sveltePath, "src/runtime")
59
+ );
60
+ }
47
61
  chain.resolve.extensions.add(".svelte");
48
62
  chain.resolve.mainFields.add("svelte").add("...");
49
63
  chain.resolve.conditionNames.add("svelte").add("...");
@@ -68,7 +82,7 @@ function pluginSvelte(options = {}) {
68
82
  ...userLoaderOptions.compilerOptions
69
83
  }
70
84
  };
71
- chain.module.rule(CHAIN_ID.RULE.SVELTE).test(/\.svelte$/).use(CHAIN_ID.USE.SVELTE).loader(loaderPath).options(svelteLoaderOptions);
85
+ chain.module.rule(CHAIN_ID.RULE.SVELTE).test(svelte5 ? /\.(?:svelte|svelte\.js|svelte\.ts)$/ : /\.svelte$/).use(CHAIN_ID.USE.SVELTE).loader(loaderPath).options(svelteLoaderOptions);
72
86
  }
73
87
  );
74
88
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/plugin-svelte",
3
- "version": "1.0.1-rc.4",
3
+ "version": "1.0.1",
4
4
  "description": "Svelte plugin for Rsbuild",
5
5
  "repository": {
6
6
  "type": "git",
@@ -30,11 +30,11 @@
30
30
  "@types/node": "18.x",
31
31
  "svelte": "^4.2.19",
32
32
  "typescript": "^5.5.2",
33
- "@rsbuild/core": "1.0.1-rc.4",
34
- "@scripts/test-helper": "1.0.1-rc.4"
33
+ "@rsbuild/core": "1.0.1",
34
+ "@scripts/test-helper": "1.0.1"
35
35
  },
36
36
  "peerDependencies": {
37
- "@rsbuild/core": "^1.0.1-rc.4"
37
+ "@rsbuild/core": "1.x || ^1.0.1-rc.0"
38
38
  },
39
39
  "publishConfig": {
40
40
  "access": "public",