@rsbuild/plugin-svelte 1.0.1 → 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,115 +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
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
15
+ });
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
35
53
  });
36
- module.exports = __toCommonJS(src_exports);
37
- var import_node_fs = require("fs");
38
- var import_node_path = __toESM(require("path"));
39
- var import_core = require("@rsbuild/core");
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
- }
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
+ }
50
69
  };
51
- function pluginSvelte(options = {}) {
52
- return {
53
- name: PLUGIN_SVELTE_NAME,
54
- setup(api) {
55
- let sveltePath = "";
56
- try {
57
- sveltePath = import_node_path.default.dirname(
58
- require.resolve("svelte/package.json", {
59
- paths: [api.context.rootPath]
60
- })
61
- );
62
- } catch (err) {
63
- import_core.logger.error(
64
- "Cannot resolve `svelte` package under the project directory, did you forget to install it?"
65
- );
66
- throw new Error("Cannot resolve `svelte` package", {
67
- cause: err
68
- });
69
- }
70
- api.modifyBundlerChain(
71
- async (chain, { CHAIN_ID, environment, isDev, isProd }) => {
72
- const { default: sveltePreprocess } = await import("svelte-preprocess");
73
- const svelte5 = await isSvelte5(sveltePath);
74
- const environmentConfig = environment.config;
75
- if (!svelte5) {
76
- chain.resolve.alias.set(
77
- "svelte",
78
- import_node_path.default.join(sveltePath, "src/runtime")
79
- );
80
- }
81
- chain.resolve.extensions.add(".svelte");
82
- chain.resolve.mainFields.add("svelte").add("...");
83
- chain.resolve.conditionNames.add("svelte").add("...");
84
- const loaderPath = require.resolve("svelte-loader");
85
- chain.merge({
86
- resolveLoader: {
87
- alias: {
88
- "svelte-loader": loaderPath
89
- }
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
+ });
90
88
  }
91
- });
92
- const userLoaderOptions = options.svelteLoaderOptions ?? {};
93
- const svelteLoaderOptions = {
94
- preprocess: sveltePreprocess(options.preprocessOptions),
95
- // NOTE emitCss: true is currently not supported with HMR
96
- // See https://github.com/web-infra-dev/rsbuild/issues/2744
97
- emitCss: isProd && !environmentConfig.output.injectStyles,
98
- hotReload: isDev && environmentConfig.dev.hmr,
99
- ...userLoaderOptions,
100
- compilerOptions: {
101
- dev: isDev,
102
- ...userLoaderOptions.compilerOptions
103
- }
104
- };
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);
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
+ });
106
125
  }
107
- );
108
- }
109
- };
126
+ };
110
127
  }
111
- // Annotate the CommonJS export names for ESM import in node:
112
- 0 && (module.exports = {
113
- PLUGIN_SVELTE_NAME,
114
- 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
115
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,94 +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.59.0_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 { promises } from "fs";
18
- import path2 from "path";
19
- import { logger } from "@rsbuild/core";
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
- }
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
+ }
30
15
  };
31
- function pluginSvelte(options = {}) {
32
- return {
33
- name: PLUGIN_SVELTE_NAME,
34
- setup(api) {
35
- let sveltePath = "";
36
- try {
37
- sveltePath = path2.dirname(
38
- __require.resolve("svelte/package.json", {
39
- paths: [api.context.rootPath]
40
- })
41
- );
42
- } catch (err) {
43
- logger.error(
44
- "Cannot resolve `svelte` package under the project directory, did you forget to install it?"
45
- );
46
- throw new Error("Cannot resolve `svelte` package", {
47
- cause: err
48
- });
49
- }
50
- api.modifyBundlerChain(
51
- async (chain, { CHAIN_ID, environment, isDev, isProd }) => {
52
- const { default: sveltePreprocess } = await import("svelte-preprocess");
53
- const svelte5 = await isSvelte5(sveltePath);
54
- const environmentConfig = environment.config;
55
- if (!svelte5) {
56
- chain.resolve.alias.set(
57
- "svelte",
58
- path2.join(sveltePath, "src/runtime")
59
- );
60
- }
61
- chain.resolve.extensions.add(".svelte");
62
- chain.resolve.mainFields.add("svelte").add("...");
63
- chain.resolve.conditionNames.add("svelte").add("...");
64
- const loaderPath = __require.resolve("svelte-loader");
65
- chain.merge({
66
- resolveLoader: {
67
- alias: {
68
- "svelte-loader": loaderPath
69
- }
70
- }
71
- });
72
- const userLoaderOptions = options.svelteLoaderOptions ?? {};
73
- const svelteLoaderOptions = {
74
- preprocess: sveltePreprocess(options.preprocessOptions),
75
- // NOTE emitCss: true is currently not supported with HMR
76
- // See https://github.com/web-infra-dev/rsbuild/issues/2744
77
- emitCss: isProd && !environmentConfig.output.injectStyles,
78
- hotReload: isDev && environmentConfig.dev.hmr,
79
- ...userLoaderOptions,
80
- compilerOptions: {
81
- dev: isDev,
82
- ...userLoaderOptions.compilerOptions
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
+ });
83
34
  }
84
- };
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);
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
+ });
86
71
  }
87
- );
88
- }
89
- };
72
+ };
90
73
  }
91
- export {
92
- PLUGIN_SVELTE_NAME,
93
- pluginSvelte
94
- };
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",
3
+ "version": "1.0.2",
4
4
  "description": "Svelte plugin for Rsbuild",
5
5
  "repository": {
6
6
  "type": "git",
@@ -11,26 +11,25 @@
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",
31
+ "typescript": "^5.6.3",
32
+ "@rsbuild/core": "1.0.14",
34
33
  "@scripts/test-helper": "1.0.1"
35
34
  },
36
35
  "peerDependencies": {
@@ -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"}