@rsbuild/plugin-svelte 1.0.7 → 1.0.9
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 +11 -11
- package/dist/index.cjs +16 -28
- package/dist/index.js +15 -23
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
<a href="https://rsbuild.dev" target="blank"><img src="https://github.com/web-infra-dev/rsbuild/assets/7237365/84abc13e-b620-468f-a90b-dbf28e7e9427" alt="Rsbuild Logo" /></a>
|
|
3
|
-
</p>
|
|
1
|
+
# @rsbuild/plugin-svelte
|
|
4
2
|
|
|
5
|
-
|
|
3
|
+
An Rsbuild plugin to provide support for Svelte.
|
|
6
4
|
|
|
7
|
-
|
|
5
|
+
<p>
|
|
6
|
+
<a href="https://npmjs.com/package/@rsbuild/plugin-svelte">
|
|
7
|
+
<img src="https://img.shields.io/npm/v/@rsbuild/plugin-svelte?style=flat-square&colorA=564341&colorB=EDED91" alt="npm version" />
|
|
8
|
+
</a>
|
|
9
|
+
<img src="https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square&colorA=564341&colorB=EDED91" alt="license" />
|
|
10
|
+
<a href="https://npmcharts.com/compare/@rsbuild/plugin-svelte?minimal=true"><img src="https://img.shields.io/npm/dm/@rsbuild/plugin-svelte.svg?style=flat-square&colorA=564341&colorB=EDED91" alt="downloads" /></a>
|
|
11
|
+
</p>
|
|
8
12
|
|
|
9
13
|
## Documentation
|
|
10
14
|
|
|
11
|
-
https://rsbuild.dev/
|
|
12
|
-
|
|
13
|
-
## Contributing
|
|
14
|
-
|
|
15
|
-
Please read the [Contributing Guide](https://github.com/web-infra-dev/rsbuild/blob/main/CONTRIBUTING.md).
|
|
15
|
+
See [Documentation](https://rsbuild.dev/plugins/list/plugin-svelte).
|
|
16
16
|
|
|
17
17
|
## License
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
[MIT](https://github.com/web-infra-dev/rsbuild/blob/main/LICENSE).
|
package/dist/index.cjs
CHANGED
|
@@ -1,23 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
let __rslib_import_meta_url__ = 'undefined' == typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
|
|
3
3
|
var __webpack_require__ = {};
|
|
4
|
-
__webpack_require__.n =
|
|
5
|
-
var getter = module && module.__esModule ?
|
|
6
|
-
return module.default;
|
|
7
|
-
} : function() {
|
|
8
|
-
return module;
|
|
9
|
-
};
|
|
4
|
+
__webpack_require__.n = (module)=>{
|
|
5
|
+
var getter = module && module.__esModule ? ()=>module.default : ()=>module;
|
|
10
6
|
return __webpack_require__.d(getter, {
|
|
11
7
|
a: getter
|
|
12
8
|
}), getter;
|
|
13
|
-
}, __webpack_require__.d =
|
|
9
|
+
}, __webpack_require__.d = (exports1, definition)=>{
|
|
14
10
|
for(var key in definition)__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key) && Object.defineProperty(exports1, key, {
|
|
15
11
|
enumerable: !0,
|
|
16
12
|
get: definition[key]
|
|
17
13
|
});
|
|
18
|
-
}, __webpack_require__.o =
|
|
19
|
-
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
20
|
-
}, __webpack_require__.r = function(exports1) {
|
|
14
|
+
}, __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop), __webpack_require__.r = (exports1)=>{
|
|
21
15
|
'undefined' != typeof Symbol && Symbol.toStringTag && Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
22
16
|
value: 'Module'
|
|
23
17
|
}), Object.defineProperty(exports1, '__esModule', {
|
|
@@ -26,8 +20,8 @@ __webpack_require__.n = function(module) {
|
|
|
26
20
|
};
|
|
27
21
|
var __webpack_exports__ = {};
|
|
28
22
|
__webpack_require__.r(__webpack_exports__), __webpack_require__.d(__webpack_exports__, {
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
PLUGIN_SVELTE_NAME: ()=>PLUGIN_SVELTE_NAME,
|
|
24
|
+
pluginSvelte: ()=>pluginSvelte
|
|
31
25
|
});
|
|
32
26
|
let external_node_fs_namespaceObject = require("node:fs"), external_node_module_namespaceObject = require("node:module"), external_node_path_namespaceObject = require("node:path");
|
|
33
27
|
var external_node_path_default = __webpack_require__.n(external_node_path_namespaceObject);
|
|
@@ -57,15 +51,9 @@ function pluginSvelte(options = {}) {
|
|
|
57
51
|
}
|
|
58
52
|
api.modifyBundlerChain(async (chain, { CHAIN_ID, environment, isDev, isProd })=>{
|
|
59
53
|
let svelte5 = await isSvelte5(sveltePath), environmentConfig = environment.config;
|
|
60
|
-
|
|
54
|
+
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
55
|
let loaderPath = src_require.resolve('svelte-loader');
|
|
62
|
-
chain.
|
|
63
|
-
resolveLoader: {
|
|
64
|
-
alias: {
|
|
65
|
-
'svelte-loader': loaderPath
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
});
|
|
56
|
+
chain.resolveLoader.alias.set('svelte-loader', loaderPath);
|
|
69
57
|
let userLoaderOptions = options.svelteLoaderOptions ?? {}, svelteLoaderOptions = {
|
|
70
58
|
preprocess: (0, external_svelte_preprocess_namespaceObject.sveltePreprocess)(options.preprocessOptions),
|
|
71
59
|
emitCss: isProd && !environmentConfig.output.injectStyles,
|
|
@@ -75,19 +63,19 @@ function pluginSvelte(options = {}) {
|
|
|
75
63
|
dev: isDev,
|
|
76
64
|
...userLoaderOptions.compilerOptions
|
|
77
65
|
}
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
if (svelte5 && jsRule) {
|
|
82
|
-
let swcUse = jsRule.uses.get(CHAIN_ID.USE.SWC), regexp = /\.(?:svelte\.js|svelte\.ts)$/;
|
|
66
|
+
}, jsRule = chain.module.rules.get(CHAIN_ID.RULE.JS), swcUse = jsRule.uses.get(CHAIN_ID.USE.SWC), svelteRule = chain.module.rule(CHAIN_ID.RULE.SVELTE).test(/\.svelte$/);
|
|
67
|
+
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) {
|
|
68
|
+
let regexp = /\.(?:svelte\.js|svelte\.ts)$/;
|
|
83
69
|
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'));
|
|
84
70
|
}
|
|
85
71
|
});
|
|
86
72
|
}
|
|
87
73
|
};
|
|
88
74
|
}
|
|
89
|
-
var
|
|
90
|
-
|
|
91
|
-
|
|
75
|
+
for(var __webpack_i__ in exports.PLUGIN_SVELTE_NAME = __webpack_exports__.PLUGIN_SVELTE_NAME, exports.pluginSvelte = __webpack_exports__.pluginSvelte, __webpack_exports__)-1 === [
|
|
76
|
+
"PLUGIN_SVELTE_NAME",
|
|
77
|
+
"pluginSvelte"
|
|
78
|
+
].indexOf(__webpack_i__) && (exports[__webpack_i__] = __webpack_exports__[__webpack_i__]);
|
|
79
|
+
Object.defineProperty(exports, '__esModule', {
|
|
92
80
|
value: !0
|
|
93
81
|
});
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import * as
|
|
3
|
-
import * as
|
|
4
|
-
import * as
|
|
5
|
-
import * as
|
|
6
|
-
let src_require = (0,
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__ from "node:fs";
|
|
2
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_module_ab9f2194__ from "node:module";
|
|
3
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__ from "node:path";
|
|
4
|
+
import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__ from "@rsbuild/core";
|
|
5
|
+
import * as __WEBPACK_EXTERNAL_MODULE_svelte_preprocess_005f2e49__ from "svelte-preprocess";
|
|
6
|
+
let src_require = (0, __WEBPACK_EXTERNAL_MODULE_node_module_ab9f2194__.createRequire)(import.meta.url), PLUGIN_SVELTE_NAME = 'rsbuild:svelte', isSvelte5 = async (sveltePath)=>{
|
|
7
7
|
try {
|
|
8
|
-
let pkgPath =
|
|
8
|
+
let pkgPath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.join(sveltePath, 'package.json'), pkgRaw = await __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__.promises.readFile(pkgPath, 'utf-8');
|
|
9
9
|
return JSON.parse(pkgRaw).version.startsWith('5.');
|
|
10
10
|
} catch (err) {
|
|
11
11
|
return !1;
|
|
@@ -17,29 +17,23 @@ function pluginSvelte(options = {}) {
|
|
|
17
17
|
setup (api) {
|
|
18
18
|
let sveltePath = '';
|
|
19
19
|
try {
|
|
20
|
-
sveltePath =
|
|
20
|
+
sveltePath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.dirname(src_require.resolve('svelte/package.json', {
|
|
21
21
|
paths: [
|
|
22
22
|
api.context.rootPath
|
|
23
23
|
]
|
|
24
24
|
}));
|
|
25
25
|
} catch (err) {
|
|
26
|
-
throw
|
|
26
|
+
throw __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.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
27
|
cause: err
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
30
|
api.modifyBundlerChain(async (chain, { CHAIN_ID, environment, isDev, isProd })=>{
|
|
31
31
|
let svelte5 = await isSvelte5(sveltePath), environmentConfig = environment.config;
|
|
32
|
-
|
|
32
|
+
svelte5 || chain.resolve.alias.set('svelte', __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.join(sveltePath, 'src/runtime')), chain.resolve.extensions.add('.svelte'), chain.resolve.mainFields.add('svelte').add('...'), chain.resolve.conditionNames.add('svelte').add('...');
|
|
33
33
|
let loaderPath = src_require.resolve('svelte-loader');
|
|
34
|
-
chain.
|
|
35
|
-
resolveLoader: {
|
|
36
|
-
alias: {
|
|
37
|
-
'svelte-loader': loaderPath
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
});
|
|
34
|
+
chain.resolveLoader.alias.set('svelte-loader', loaderPath);
|
|
41
35
|
let userLoaderOptions = options.svelteLoaderOptions ?? {}, svelteLoaderOptions = {
|
|
42
|
-
preprocess: (0,
|
|
36
|
+
preprocess: (0, __WEBPACK_EXTERNAL_MODULE_svelte_preprocess_005f2e49__.sveltePreprocess)(options.preprocessOptions),
|
|
43
37
|
emitCss: isProd && !environmentConfig.output.injectStyles,
|
|
44
38
|
hotReload: isDev && environmentConfig.dev.hmr,
|
|
45
39
|
...userLoaderOptions,
|
|
@@ -47,11 +41,9 @@ function pluginSvelte(options = {}) {
|
|
|
47
41
|
dev: isDev,
|
|
48
42
|
...userLoaderOptions.compilerOptions
|
|
49
43
|
}
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
if (svelte5 && jsRule) {
|
|
54
|
-
let swcUse = jsRule.uses.get(CHAIN_ID.USE.SWC), regexp = /\.(?:svelte\.js|svelte\.ts)$/;
|
|
44
|
+
}, jsRule = chain.module.rules.get(CHAIN_ID.RULE.JS), swcUse = jsRule.uses.get(CHAIN_ID.USE.SWC), svelteRule = chain.module.rule(CHAIN_ID.RULE.SVELTE).test(/\.svelte$/);
|
|
45
|
+
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) {
|
|
46
|
+
let regexp = /\.(?:svelte\.js|svelte\.ts)$/;
|
|
55
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'));
|
|
56
48
|
}
|
|
57
49
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsbuild/plugin-svelte",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"description": "Svelte plugin for Rsbuild",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -26,11 +26,11 @@
|
|
|
26
26
|
"svelte-preprocess": "^6.0.3"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@rslib/core": "0.1
|
|
30
|
-
"@types/node": "^22.
|
|
31
|
-
"svelte": "^5.
|
|
32
|
-
"typescript": "^5.
|
|
33
|
-
"@rsbuild/core": "1.
|
|
29
|
+
"@rslib/core": "0.7.1",
|
|
30
|
+
"@types/node": "^22.15.19",
|
|
31
|
+
"svelte": "^5.30.2",
|
|
32
|
+
"typescript": "^5.8.3",
|
|
33
|
+
"@rsbuild/core": "1.3.20",
|
|
34
34
|
"@scripts/test-helper": "1.0.1"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|