@rsbuild/plugin-svelte 2.0.0-alpha.3 → 2.0.0

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.d.ts CHANGED
@@ -5,27 +5,23 @@ export type AutoPreprocessOptions = NonNullable<Parameters<typeof sveltePreproce
5
5
  export interface SvelteLoaderOptions {
6
6
  compilerOptions?: Omit<CompileOptions, 'filename' | 'format' | 'generate'>;
7
7
  /**
8
- * Extra HMR options, the defaults are completely fine\
9
- * You can safely omit hotOptions altogether
10
- */
11
- hotOptions?: {
12
- /** Preserve local component state */
13
- preserveLocalState?: boolean;
8
+ * Extra HMR options, the defaults are completely fine\
9
+ * You can safely omit hotOptions altogether
10
+ */ hotOptions?: {
11
+ /** Preserve local component state */ preserveLocalState?: boolean;
14
12
  [key: string]: unknown;
15
13
  };
16
14
  [key: string]: unknown;
17
15
  }
18
16
  export type PluginSvelteOptions = {
19
17
  /**
20
- * The options of svelte-loader
21
- * @see https://github.com/sveltejs/svelte-loader
22
- */
23
- svelteLoaderOptions?: SvelteLoaderOptions;
18
+ * The options of svelte-loader
19
+ * @see https://github.com/sveltejs/svelte-loader
20
+ */ svelteLoaderOptions?: SvelteLoaderOptions;
24
21
  /**
25
- * The options of svelte-preprocess.
26
- * @see https://github.com/sveltejs/svelte-preprocess
27
- */
28
- preprocessOptions?: AutoPreprocessOptions;
22
+ * The options of svelte-preprocess.
23
+ * @see https://github.com/sveltejs/svelte-preprocess
24
+ */ preprocessOptions?: AutoPreprocessOptions;
29
25
  };
30
- export declare const PLUGIN_SVELTE_NAME = "rsbuild:svelte";
26
+ export declare const PLUGIN_SVELTE_NAME = 'rsbuild:svelte';
31
27
  export declare function pluginSvelte(options?: PluginSvelteOptions): RsbuildPlugin;
package/dist/index.js CHANGED
@@ -1,41 +1,35 @@
1
- import { promises } from "node:fs";
1
+ import { readFileSync } from "node:fs";
2
2
  import { createRequire } from "node:module";
3
- import node_path from "node:path";
4
- import { logger } from "@rsbuild/core";
5
3
  import { sveltePreprocess } from "svelte-preprocess";
6
- let src_require = createRequire(import.meta.url), PLUGIN_SVELTE_NAME = 'rsbuild:svelte', isSvelte5 = async (sveltePath)=>{
7
- try {
8
- let pkgPath = node_path.join(sveltePath, 'package.json'), pkgRaw = await promises.readFile(pkgPath, 'utf-8');
9
- return JSON.parse(pkgRaw).version.startsWith('5.');
10
- } catch {
11
- return !1;
12
- }
13
- };
4
+ let src_require = createRequire(import.meta.url), PLUGIN_SVELTE_NAME = 'rsbuild:svelte';
14
5
  function pluginSvelte(options = {}) {
15
6
  return {
16
7
  name: PLUGIN_SVELTE_NAME,
17
8
  setup (api) {
18
- let sveltePath = '';
19
- try {
20
- sveltePath = node_path.dirname(src_require.resolve('svelte/package.json', {
21
- paths: [
22
- api.context.rootPath
23
- ]
24
- }));
25
- } catch (err) {
26
- throw logger.error('Cannot resolve `svelte` package under the project directory, did you forget to install it?'), Error('[rsbuild:svelte] Failed to resolve `svelte` package', {
27
- cause: err
28
- });
29
- }
30
- api.modifyEnvironmentConfig((config, { mergeEnvironmentConfig })=>mergeEnvironmentConfig({
9
+ ((rootPath)=>{
10
+ let pkgPath;
11
+ try {
12
+ pkgPath = src_require.resolve('svelte/package.json', {
13
+ paths: [
14
+ rootPath
15
+ ]
16
+ });
17
+ } catch (err) {
18
+ throw Error('Cannot resolve `svelte` package under the project directory, did you forget to install it?', {
19
+ cause: err
20
+ });
21
+ }
22
+ let { version } = JSON.parse(readFileSync(pkgPath, 'utf-8'));
23
+ if (!((version ? Number(version.split('.')[0]) : 0) >= 5)) throw Error(`"@rsbuild/plugin-svelte" requires svelte >= 5.0.0, but found ${version || 'unknown'}.`);
24
+ })(api.context.rootPath), api.modifyEnvironmentConfig((config, { mergeEnvironmentConfig })=>mergeEnvironmentConfig({
31
25
  source: {
32
26
  include: [
33
27
  /node_modules[\\/]svelte[\\/]/
34
28
  ]
35
29
  }
36
- }, config)), api.modifyBundlerChain(async (chain, { CHAIN_ID, environment, isDev, isProd })=>{
37
- let svelte5 = await isSvelte5(sveltePath), environmentConfig = environment.config;
38
- svelte5 || chain.resolve.alias.set('svelte', node_path.join(sveltePath, 'src/runtime')), chain.resolve.extensions.add('.svelte'), chain.resolve.mainFields.add('svelte').add('...'), chain.resolve.conditionNames.add('svelte').add('...');
30
+ }, config)), api.modifyBundlerChain((chain, { CHAIN_ID, environment, isDev, isProd })=>{
31
+ let environmentConfig = environment.config;
32
+ chain.resolve.extensions.add('.svelte'), chain.resolve.mainFields.add('svelte').add('...'), chain.resolve.conditionNames.add('svelte').add('...');
39
33
  let loaderPath = src_require.resolve('svelte-loader');
40
34
  chain.resolveLoader.alias.set('svelte-loader', loaderPath);
41
35
  let userLoaderOptions = options.svelteLoaderOptions ?? {}, svelteLoaderOptions = {
@@ -48,10 +42,9 @@ function pluginSvelte(options = {}) {
48
42
  ...userLoaderOptions.compilerOptions
49
43
  }
50
44
  }, jsRule = chain.module.rules.get(CHAIN_ID.RULE.JS), swcUse = jsRule.oneOfs.get(CHAIN_ID.ONE_OF.JS_MAIN).uses.get(CHAIN_ID.USE.SWC), svelteRule = chain.module.rule(CHAIN_ID.RULE.SVELTE).test(/\.svelte$/);
51
- if (svelte5 && jsRule && svelteRule.use(CHAIN_ID.USE.SWC).loader(swcUse.get('loader')).options(swcUse.get('options')), svelteRule.use(CHAIN_ID.USE.SVELTE).loader(loaderPath).options(svelteLoaderOptions).end(), svelte5 && jsRule) {
52
- let regexp = /\.(?:svelte\.js|svelte\.ts)$/;
53
- jsRule.exclude.add(regexp), chain.module.rule('svelte-js').test(regexp).use(CHAIN_ID.USE.SVELTE).loader(loaderPath).options(svelteLoaderOptions).end().use(CHAIN_ID.USE.SWC).loader(swcUse.get('loader')).options(swcUse.get('options'));
54
- }
45
+ svelteRule.use(CHAIN_ID.USE.SWC).loader(swcUse.get('loader')).options(swcUse.get('options')), svelteRule.use(CHAIN_ID.USE.SVELTE).loader(loaderPath).options(svelteLoaderOptions).end();
46
+ let regexp = /\.(?:svelte\.js|svelte\.ts)$/;
47
+ jsRule.exclude.add(regexp), chain.module.rule('svelte-js').test(regexp).use(CHAIN_ID.USE.SVELTE).loader(loaderPath).options(svelteLoaderOptions).end().use(CHAIN_ID.USE.SWC).loader(swcUse.get('loader')).options(swcUse.get('options'));
55
48
  });
56
49
  }
57
50
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/plugin-svelte",
3
- "version": "2.0.0-alpha.3",
3
+ "version": "2.0.0",
4
4
  "description": "Svelte plugin for Rsbuild",
5
5
  "repository": {
6
6
  "type": "git",
@@ -12,37 +12,40 @@
12
12
  "exports": {
13
13
  ".": {
14
14
  "types": "./dist/index.d.ts",
15
- "import": "./dist/index.js",
16
- "require": "./dist/index.cjs"
15
+ "default": "./dist/index.js"
17
16
  }
18
17
  },
19
- "main": "./dist/index.cjs",
20
18
  "types": "./dist/index.d.ts",
21
19
  "files": [
22
20
  "dist"
23
21
  ],
24
22
  "dependencies": {
25
23
  "svelte-loader": "3.2.4",
26
- "svelte-preprocess": "^6.0.3"
24
+ "svelte-preprocess": "6.0.5"
27
25
  },
28
26
  "devDependencies": {
29
- "@rslib/core": "0.19.3",
30
- "@types/node": "^24.10.9",
31
- "svelte": "^5.48.2",
32
- "typescript": "^5.9.3",
33
- "@rsbuild/core": "2.0.0-alpha.3",
34
- "@scripts/test-helper": "1.0.1"
27
+ "@rslib/core": "0.22.0",
28
+ "@types/node": "^24.12.4",
29
+ "svelte": "^5.55.9",
30
+ "typescript": "^6.0.3",
31
+ "@rsbuild/core": "2.0.9",
32
+ "@scripts/test-helper": "1.0.0"
35
33
  },
36
34
  "peerDependencies": {
37
- "@rsbuild/core": "^2.0.0-0"
35
+ "@rsbuild/core": "^2.0.0",
36
+ "svelte": "^5.0.0"
37
+ },
38
+ "peerDependenciesMeta": {
39
+ "@rsbuild/core": {
40
+ "optional": true
41
+ }
38
42
  },
39
43
  "publishConfig": {
40
44
  "access": "public",
41
45
  "registry": "https://registry.npmjs.org/"
42
46
  },
43
47
  "scripts": {
44
- "build": "rslib build",
45
- "dev": "rslib build -w",
46
- "bump": "pnpx bumpp --no-tag"
48
+ "build": "rslib",
49
+ "dev": "rslib -w"
47
50
  }
48
51
  }
package/dist/index.cjs DELETED
@@ -1,87 +0,0 @@
1
- "use strict";
2
- const __rslib_import_meta_url__ = "u" < typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
3
- var __webpack_require__ = {};
4
- __webpack_require__.n = (module)=>{
5
- var getter = module && module.__esModule ? ()=>module.default : ()=>module;
6
- return __webpack_require__.d(getter, {
7
- a: getter
8
- }), getter;
9
- }, __webpack_require__.d = (exports1, definition)=>{
10
- for(var key in definition)__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key) && Object.defineProperty(exports1, key, {
11
- enumerable: !0,
12
- get: definition[key]
13
- });
14
- }, __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop), __webpack_require__.r = (exports1)=>{
15
- "u" > typeof Symbol && Symbol.toStringTag && Object.defineProperty(exports1, Symbol.toStringTag, {
16
- value: 'Module'
17
- }), Object.defineProperty(exports1, '__esModule', {
18
- value: !0
19
- });
20
- };
21
- var __webpack_exports__ = {};
22
- __webpack_require__.r(__webpack_exports__), __webpack_require__.d(__webpack_exports__, {
23
- PLUGIN_SVELTE_NAME: ()=>PLUGIN_SVELTE_NAME,
24
- pluginSvelte: ()=>pluginSvelte
25
- });
26
- const external_node_fs_namespaceObject = require("node:fs"), external_node_module_namespaceObject = require("node:module"), external_node_path_namespaceObject = require("node:path");
27
- var external_node_path_default = __webpack_require__.n(external_node_path_namespaceObject);
28
- const core_namespaceObject = require("@rsbuild/core"), external_svelte_preprocess_namespaceObject = require("svelte-preprocess"), src_require = (0, external_node_module_namespaceObject.createRequire)(__rslib_import_meta_url__), PLUGIN_SVELTE_NAME = 'rsbuild:svelte', isSvelte5 = async (sveltePath)=>{
29
- try {
30
- let pkgPath = external_node_path_default().join(sveltePath, 'package.json'), pkgRaw = await external_node_fs_namespaceObject.promises.readFile(pkgPath, 'utf-8');
31
- return JSON.parse(pkgRaw).version.startsWith('5.');
32
- } catch {
33
- return !1;
34
- }
35
- };
36
- function pluginSvelte(options = {}) {
37
- return {
38
- name: PLUGIN_SVELTE_NAME,
39
- setup (api) {
40
- let sveltePath = '';
41
- try {
42
- sveltePath = external_node_path_default().dirname(src_require.resolve('svelte/package.json', {
43
- paths: [
44
- api.context.rootPath
45
- ]
46
- }));
47
- } catch (err) {
48
- throw core_namespaceObject.logger.error('Cannot resolve `svelte` package under the project directory, did you forget to install it?'), Error('[rsbuild:svelte] Failed to resolve `svelte` package', {
49
- cause: err
50
- });
51
- }
52
- api.modifyEnvironmentConfig((config, { mergeEnvironmentConfig })=>mergeEnvironmentConfig({
53
- source: {
54
- include: [
55
- /node_modules[\\/]svelte[\\/]/
56
- ]
57
- }
58
- }, config)), api.modifyBundlerChain(async (chain, { CHAIN_ID, environment, isDev, isProd })=>{
59
- let svelte5 = await isSvelte5(sveltePath), environmentConfig = environment.config;
60
- svelte5 || chain.resolve.alias.set('svelte', external_node_path_default().join(sveltePath, 'src/runtime')), chain.resolve.extensions.add('.svelte'), chain.resolve.mainFields.add('svelte').add('...'), chain.resolve.conditionNames.add('svelte').add('...');
61
- let loaderPath = src_require.resolve('svelte-loader');
62
- chain.resolveLoader.alias.set('svelte-loader', loaderPath);
63
- let userLoaderOptions = options.svelteLoaderOptions ?? {}, svelteLoaderOptions = {
64
- preprocess: (0, external_svelte_preprocess_namespaceObject.sveltePreprocess)(options.preprocessOptions),
65
- emitCss: isProd && !environmentConfig.output.injectStyles,
66
- hotReload: isDev && environmentConfig.dev.hmr,
67
- ...userLoaderOptions,
68
- compilerOptions: {
69
- dev: isDev,
70
- ...userLoaderOptions.compilerOptions
71
- }
72
- }, jsRule = chain.module.rules.get(CHAIN_ID.RULE.JS), swcUse = jsRule.oneOfs.get(CHAIN_ID.ONE_OF.JS_MAIN).uses.get(CHAIN_ID.USE.SWC), svelteRule = chain.module.rule(CHAIN_ID.RULE.SVELTE).test(/\.svelte$/);
73
- if (svelte5 && jsRule && svelteRule.use(CHAIN_ID.USE.SWC).loader(swcUse.get('loader')).options(swcUse.get('options')), svelteRule.use(CHAIN_ID.USE.SVELTE).loader(loaderPath).options(svelteLoaderOptions).end(), svelte5 && jsRule) {
74
- let regexp = /\.(?:svelte\.js|svelte\.ts)$/;
75
- jsRule.exclude.add(regexp), chain.module.rule('svelte-js').test(regexp).use(CHAIN_ID.USE.SVELTE).loader(loaderPath).options(svelteLoaderOptions).end().use(CHAIN_ID.USE.SWC).loader(swcUse.get('loader')).options(swcUse.get('options'));
76
- }
77
- });
78
- }
79
- };
80
- }
81
- for(var __rspack_i in exports.PLUGIN_SVELTE_NAME = __webpack_exports__.PLUGIN_SVELTE_NAME, exports.pluginSvelte = __webpack_exports__.pluginSvelte, __webpack_exports__)-1 === [
82
- "PLUGIN_SVELTE_NAME",
83
- "pluginSvelte"
84
- ].indexOf(__rspack_i) && (exports[__rspack_i] = __webpack_exports__[__rspack_i]);
85
- Object.defineProperty(exports, '__esModule', {
86
- value: !0
87
- });