@rsbuild/plugin-svelte 1.0.1-rc.5 → 1.0.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/dist/index.cjs CHANGED
@@ -1,101 +1,132 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/index.ts
31
- var src_exports = {};
32
- __export(src_exports, {
33
- PLUGIN_SVELTE_NAME: () => PLUGIN_SVELTE_NAME,
34
- pluginSvelte: () => pluginSvelte
35
- });
36
- module.exports = __toCommonJS(src_exports);
37
- var import_node_path = __toESM(require("path"));
38
- var import_core = require("@rsbuild/core");
39
- var PLUGIN_SVELTE_NAME = "rsbuild:svelte";
40
- function pluginSvelte(options = {}) {
41
- return {
42
- name: PLUGIN_SVELTE_NAME,
43
- setup(api) {
44
- let sveltePath = "";
45
- try {
46
- sveltePath = import_node_path.default.dirname(
47
- require.resolve("svelte/package.json", {
48
- paths: [api.context.rootPath]
49
- })
50
- );
51
- } catch (err) {
52
- import_core.logger.error(
53
- "Cannot resolve `svelte` package under the project directory, did you forget to install it?"
54
- );
55
- throw new Error("Cannot resolve `svelte` package", {
56
- cause: err
2
+ // The require scope
3
+ var __webpack_require__ = {};
4
+ /************************************************************************/ // webpack/runtime/compat_get_default_export
5
+ (()=>{
6
+ // getDefaultExport function for compatibility with non-harmony modules
7
+ __webpack_require__.n = function(module) {
8
+ var getter = module && module.__esModule ? function() {
9
+ return module['default'];
10
+ } : function() {
11
+ return module;
12
+ };
13
+ __webpack_require__.d(getter, {
14
+ a: getter
57
15
  });
58
- }
59
- api.modifyBundlerChain(
60
- async (chain, { CHAIN_ID, environment, isDev, isProd }) => {
61
- const { default: sveltePreprocess } = await import("svelte-preprocess");
62
- const environmentConfig = environment.config;
63
- chain.resolve.alias.set(
64
- "svelte",
65
- import_node_path.default.join(sveltePath, "src/runtime")
66
- );
67
- chain.resolve.extensions.add(".svelte");
68
- chain.resolve.mainFields.add("svelte").add("...");
69
- chain.resolve.conditionNames.add("svelte").add("...");
70
- const loaderPath = require.resolve("svelte-loader");
71
- chain.merge({
72
- resolveLoader: {
73
- alias: {
74
- "svelte-loader": loaderPath
75
- }
76
- }
77
- });
78
- const userLoaderOptions = options.svelteLoaderOptions ?? {};
79
- const svelteLoaderOptions = {
80
- preprocess: sveltePreprocess(options.preprocessOptions),
81
- // NOTE emitCss: true is currently not supported with HMR
82
- // See https://github.com/web-infra-dev/rsbuild/issues/2744
83
- emitCss: isProd && !environmentConfig.output.injectStyles,
84
- hotReload: isDev && environmentConfig.dev.hmr,
85
- ...userLoaderOptions,
86
- compilerOptions: {
87
- dev: isDev,
88
- ...userLoaderOptions.compilerOptions
16
+ return getter;
17
+ };
18
+ })();
19
+ // webpack/runtime/define_property_getters
20
+ (()=>{
21
+ __webpack_require__.d = function(exports1, definition) {
22
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
23
+ enumerable: true,
24
+ get: definition[key]
25
+ });
26
+ };
27
+ })();
28
+ // webpack/runtime/has_own_property
29
+ (()=>{
30
+ __webpack_require__.o = function(obj, prop) {
31
+ return Object.prototype.hasOwnProperty.call(obj, prop);
32
+ };
33
+ })();
34
+ // webpack/runtime/make_namespace_object
35
+ (()=>{
36
+ // define __esModule on exports
37
+ __webpack_require__.r = function(exports1) {
38
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
39
+ value: 'Module'
40
+ });
41
+ Object.defineProperty(exports1, '__esModule', {
42
+ value: true
43
+ });
44
+ };
45
+ })();
46
+ /************************************************************************/ var __webpack_exports__ = {};
47
+ // ESM COMPAT FLAG
48
+ __webpack_require__.r(__webpack_exports__);
49
+ // EXPORTS
50
+ __webpack_require__.d(__webpack_exports__, {
51
+ PLUGIN_SVELTE_NAME: ()=>/* binding */ PLUGIN_SVELTE_NAME,
52
+ pluginSvelte: ()=>/* binding */ pluginSvelte
53
+ });
54
+ const external_node_fs_namespaceObject = require("node:fs");
55
+ const external_node_path_namespaceObject = require("node:path");
56
+ var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
57
+ const core_namespaceObject = require("@rsbuild/core");
58
+ const external_svelte_preprocess_namespaceObject = require("svelte-preprocess");
59
+ const PLUGIN_SVELTE_NAME = 'rsbuild:svelte';
60
+ const isSvelte5 = async (sveltePath)=>{
61
+ try {
62
+ const pkgPath = external_node_path_default().join(sveltePath, 'package.json');
63
+ const pkgRaw = await external_node_fs_namespaceObject.promises.readFile(pkgPath, 'utf-8');
64
+ const pkgJson = JSON.parse(pkgRaw);
65
+ return pkgJson.version.startsWith('5.');
66
+ } catch (err) {
67
+ return false;
68
+ }
69
+ };
70
+ function pluginSvelte() {
71
+ let options = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
72
+ return {
73
+ name: PLUGIN_SVELTE_NAME,
74
+ setup (api) {
75
+ let sveltePath = '';
76
+ try {
77
+ // Resolve `svelte` package path from the project directory
78
+ sveltePath = external_node_path_default().dirname(require.resolve('svelte/package.json', {
79
+ paths: [
80
+ api.context.rootPath
81
+ ]
82
+ }));
83
+ } catch (err) {
84
+ core_namespaceObject.logger.error('Cannot resolve `svelte` package under the project directory, did you forget to install it?');
85
+ throw new Error('Cannot resolve `svelte` package', {
86
+ cause: err
87
+ });
89
88
  }
90
- };
91
- chain.module.rule(CHAIN_ID.RULE.SVELTE).test(/\.svelte$/).use(CHAIN_ID.USE.SVELTE).loader(loaderPath).options(svelteLoaderOptions);
89
+ api.modifyBundlerChain(async (chain, param)=>{
90
+ let { CHAIN_ID, environment, isDev, isProd } = param;
91
+ const svelte5 = await isSvelte5(sveltePath);
92
+ const environmentConfig = environment.config;
93
+ if (!svelte5) chain.resolve.alias.set('svelte', external_node_path_default().join(sveltePath, 'src/runtime'));
94
+ chain.resolve.extensions.add('.svelte');
95
+ chain.resolve.mainFields.add('svelte').add('...');
96
+ chain.resolve.conditionNames.add('svelte').add('...');
97
+ const loaderPath = require.resolve('svelte-loader');
98
+ // We need to set an alias from `svelte-loader` to its realpath.
99
+ // Because with `emitCss` option on, the loader generates css
100
+ // imports with inline loader reference like `!svelte-loader...`,
101
+ // which would cause the bundler failed to resolve the loader.
102
+ // See https://github.com/sveltejs/svelte-loader/blob/344f00744b06a98ff5ee7e7a04d5e04ac496988c/index.js#L128
103
+ chain.merge({
104
+ resolveLoader: {
105
+ alias: {
106
+ 'svelte-loader': loaderPath
107
+ }
108
+ }
109
+ });
110
+ const userLoaderOptions = options.svelteLoaderOptions ?? {};
111
+ const svelteLoaderOptions = {
112
+ preprocess: (0, external_svelte_preprocess_namespaceObject.sveltePreprocess)(options.preprocessOptions),
113
+ // NOTE emitCss: true is currently not supported with HMR
114
+ // See https://github.com/web-infra-dev/rsbuild/issues/2744
115
+ emitCss: isProd && !environmentConfig.output.injectStyles,
116
+ hotReload: isDev && environmentConfig.dev.hmr,
117
+ ...userLoaderOptions,
118
+ compilerOptions: {
119
+ dev: isDev,
120
+ ...userLoaderOptions.compilerOptions
121
+ }
122
+ };
123
+ chain.module.rule(CHAIN_ID.RULE.SVELTE).test(svelte5 ? /\.(?:svelte|svelte\.js|svelte\.ts)$/ : /\.svelte$/).use(CHAIN_ID.USE.SVELTE).loader(loaderPath).options(svelteLoaderOptions);
124
+ });
92
125
  }
93
- );
94
- }
95
- };
126
+ };
96
127
  }
97
- // Annotate the CommonJS export names for ESM import in node:
98
- 0 && (module.exports = {
99
- PLUGIN_SVELTE_NAME,
100
- pluginSvelte
128
+ var __webpack_export_target__ = exports;
129
+ for(var i in __webpack_exports__)__webpack_export_target__[i] = __webpack_exports__[i];
130
+ if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
131
+ value: true
101
132
  });
@@ -1,5 +1,5 @@
1
1
  import type { RsbuildPlugin } from '@rsbuild/core';
2
- import type { sveltePreprocess } from 'svelte-preprocess';
2
+ import { sveltePreprocess } from 'svelte-preprocess';
3
3
  import type { CompileOptions } from 'svelte/compiler';
4
4
  export type AutoPreprocessOptions = NonNullable<Parameters<typeof sveltePreprocess>[0]>;
5
5
  export interface SvelteLoaderOptions {
package/dist/index.js CHANGED
@@ -1,80 +1,74 @@
1
- import { createRequire } from 'module';
2
- var require = createRequire(import.meta['url']);
3
-
4
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
5
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
6
- }) : x)(function(x) {
7
- if (typeof require !== "undefined")
8
- return require.apply(this, arguments);
9
- throw Error('Dynamic require of "' + x + '" is not supported');
10
- });
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
13
- import path from "path";
14
- import { fileURLToPath } from "url";
15
-
16
- // src/index.ts
17
- import path2 from "path";
18
- import { logger } from "@rsbuild/core";
19
- var PLUGIN_SVELTE_NAME = "rsbuild:svelte";
20
- function pluginSvelte(options = {}) {
21
- return {
22
- name: PLUGIN_SVELTE_NAME,
23
- setup(api) {
24
- let sveltePath = "";
25
- try {
26
- sveltePath = path2.dirname(
27
- __require.resolve("svelte/package.json", {
28
- paths: [api.context.rootPath]
29
- })
30
- );
31
- } catch (err) {
32
- logger.error(
33
- "Cannot resolve `svelte` package under the project directory, did you forget to install it?"
34
- );
35
- throw new Error("Cannot resolve `svelte` package", {
36
- cause: err
37
- });
38
- }
39
- api.modifyBundlerChain(
40
- async (chain, { CHAIN_ID, environment, isDev, isProd }) => {
41
- const { default: sveltePreprocess } = await import("svelte-preprocess");
42
- const environmentConfig = environment.config;
43
- chain.resolve.alias.set(
44
- "svelte",
45
- path2.join(sveltePath, "src/runtime")
46
- );
47
- chain.resolve.extensions.add(".svelte");
48
- chain.resolve.mainFields.add("svelte").add("...");
49
- chain.resolve.conditionNames.add("svelte").add("...");
50
- const loaderPath = __require.resolve("svelte-loader");
51
- chain.merge({
52
- resolveLoader: {
53
- alias: {
54
- "svelte-loader": loaderPath
55
- }
56
- }
57
- });
58
- const userLoaderOptions = options.svelteLoaderOptions ?? {};
59
- const svelteLoaderOptions = {
60
- preprocess: sveltePreprocess(options.preprocessOptions),
61
- // NOTE emitCss: true is currently not supported with HMR
62
- // See https://github.com/web-infra-dev/rsbuild/issues/2744
63
- emitCss: isProd && !environmentConfig.output.injectStyles,
64
- hotReload: isDev && environmentConfig.dev.hmr,
65
- ...userLoaderOptions,
66
- compilerOptions: {
67
- dev: isDev,
68
- ...userLoaderOptions.compilerOptions
1
+ import * as __WEBPACK_EXTERNAL_MODULE_node_fs__ from "node:fs";
2
+ import * as __WEBPACK_EXTERNAL_MODULE_node_path__ from "node:path";
3
+ import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_core__ from "@rsbuild/core";
4
+ import * as __WEBPACK_EXTERNAL_MODULE_svelte_preprocess__ from "svelte-preprocess";
5
+ const PLUGIN_SVELTE_NAME = 'rsbuild:svelte';
6
+ const isSvelte5 = async (sveltePath)=>{
7
+ try {
8
+ const pkgPath = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(sveltePath, 'package.json');
9
+ const pkgRaw = await __WEBPACK_EXTERNAL_MODULE_node_fs__.promises.readFile(pkgPath, 'utf-8');
10
+ const pkgJson = JSON.parse(pkgRaw);
11
+ return pkgJson.version.startsWith('5.');
12
+ } catch (err) {
13
+ return false;
14
+ }
15
+ };
16
+ function pluginSvelte() {
17
+ let options = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
18
+ return {
19
+ name: PLUGIN_SVELTE_NAME,
20
+ setup (api) {
21
+ let sveltePath = '';
22
+ try {
23
+ // Resolve `svelte` package path from the project directory
24
+ sveltePath = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].dirname(require.resolve('svelte/package.json', {
25
+ paths: [
26
+ api.context.rootPath
27
+ ]
28
+ }));
29
+ } catch (err) {
30
+ __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.logger.error('Cannot resolve `svelte` package under the project directory, did you forget to install it?');
31
+ throw new Error('Cannot resolve `svelte` package', {
32
+ cause: err
33
+ });
69
34
  }
70
- };
71
- chain.module.rule(CHAIN_ID.RULE.SVELTE).test(/\.svelte$/).use(CHAIN_ID.USE.SVELTE).loader(loaderPath).options(svelteLoaderOptions);
35
+ api.modifyBundlerChain(async (chain, param)=>{
36
+ let { CHAIN_ID, environment, isDev, isProd } = param;
37
+ const svelte5 = await isSvelte5(sveltePath);
38
+ const environmentConfig = environment.config;
39
+ if (!svelte5) chain.resolve.alias.set('svelte', __WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(sveltePath, 'src/runtime'));
40
+ chain.resolve.extensions.add('.svelte');
41
+ chain.resolve.mainFields.add('svelte').add('...');
42
+ chain.resolve.conditionNames.add('svelte').add('...');
43
+ const loaderPath = require.resolve('svelte-loader');
44
+ // We need to set an alias from `svelte-loader` to its realpath.
45
+ // Because with `emitCss` option on, the loader generates css
46
+ // imports with inline loader reference like `!svelte-loader...`,
47
+ // which would cause the bundler failed to resolve the loader.
48
+ // See https://github.com/sveltejs/svelte-loader/blob/344f00744b06a98ff5ee7e7a04d5e04ac496988c/index.js#L128
49
+ chain.merge({
50
+ resolveLoader: {
51
+ alias: {
52
+ 'svelte-loader': loaderPath
53
+ }
54
+ }
55
+ });
56
+ const userLoaderOptions = options.svelteLoaderOptions ?? {};
57
+ const svelteLoaderOptions = {
58
+ preprocess: (0, __WEBPACK_EXTERNAL_MODULE_svelte_preprocess__.sveltePreprocess)(options.preprocessOptions),
59
+ // NOTE emitCss: true is currently not supported with HMR
60
+ // See https://github.com/web-infra-dev/rsbuild/issues/2744
61
+ emitCss: isProd && !environmentConfig.output.injectStyles,
62
+ hotReload: isDev && environmentConfig.dev.hmr,
63
+ ...userLoaderOptions,
64
+ compilerOptions: {
65
+ dev: isDev,
66
+ ...userLoaderOptions.compilerOptions
67
+ }
68
+ };
69
+ chain.module.rule(CHAIN_ID.RULE.SVELTE).test(svelte5 ? /\.(?:svelte|svelte\.js|svelte\.ts)$/ : /\.svelte$/).use(CHAIN_ID.USE.SVELTE).loader(loaderPath).options(svelteLoaderOptions);
70
+ });
72
71
  }
73
- );
74
- }
75
- };
72
+ };
76
73
  }
77
- export {
78
- PLUGIN_SVELTE_NAME,
79
- pluginSvelte
80
- };
74
+ export { PLUGIN_SVELTE_NAME, pluginSvelte };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/plugin-svelte",
3
- "version": "1.0.1-rc.5",
3
+ "version": "1.0.2",
4
4
  "description": "Svelte plugin for Rsbuild",
5
5
  "repository": {
6
6
  "type": "git",
@@ -11,30 +11,29 @@
11
11
  "type": "module",
12
12
  "exports": {
13
13
  ".": {
14
- "types": "./dist-types/index.d.ts",
14
+ "types": "./dist/index.d.ts",
15
15
  "import": "./dist/index.js",
16
16
  "require": "./dist/index.cjs"
17
17
  }
18
18
  },
19
19
  "main": "./dist/index.cjs",
20
- "types": "./dist-types/index.d.ts",
20
+ "types": "./dist/index.d.ts",
21
21
  "files": [
22
- "dist",
23
- "dist-types"
22
+ "dist"
24
23
  ],
25
24
  "dependencies": {
26
- "svelte-loader": "3.2.3",
27
- "svelte-preprocess": "^6.0.2"
25
+ "svelte-loader": "3.2.4",
26
+ "svelte-preprocess": "^6.0.3"
28
27
  },
29
28
  "devDependencies": {
30
29
  "@types/node": "18.x",
31
30
  "svelte": "^4.2.19",
32
- "typescript": "^5.5.2",
33
- "@rsbuild/core": "1.0.1-rc.5",
34
- "@scripts/test-helper": "1.0.1-rc.5"
31
+ "typescript": "^5.6.3",
32
+ "@rsbuild/core": "1.0.14",
33
+ "@scripts/test-helper": "1.0.1"
35
34
  },
36
35
  "peerDependencies": {
37
- "@rsbuild/core": "^1.0.1-rc.4"
36
+ "@rsbuild/core": "1.x || ^1.0.1-rc.0"
38
37
  },
39
38
  "publishConfig": {
40
39
  "access": "public",
@@ -42,7 +41,7 @@
42
41
  "registry": "https://registry.npmjs.org/"
43
42
  },
44
43
  "scripts": {
45
- "build": "modern build",
46
- "dev": "modern build --watch"
44
+ "build": "rslib build",
45
+ "dev": "rslib build --watch"
47
46
  }
48
47
  }
@@ -1 +0,0 @@
1
- {"//":"This file is for making TypeScript work with moduleResolution node16+.","version":"1.0.0"}