@rsbuild/plugin-svelte 1.0.0 → 1.0.1-beta.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/README.md +1 -1
- package/dist/index.cjs +101 -0
- package/dist/index.d.ts +27 -9
- package/dist/index.js +59 -68
- package/package.json +15 -11
- package/dist/index.mjs +0 -69
package/README.md
CHANGED
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
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
|
|
57
|
+
});
|
|
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
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
chain.module.rule(CHAIN_ID.RULE.SVELTE).test(/\.svelte$/).use(CHAIN_ID.USE.SVELTE).loader(loaderPath).options(svelteLoaderOptions);
|
|
92
|
+
}
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
98
|
+
0 && (module.exports = {
|
|
99
|
+
PLUGIN_SVELTE_NAME,
|
|
100
|
+
pluginSvelte
|
|
101
|
+
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,31 @@
|
|
|
1
|
-
import { RsbuildPlugin } from '@rsbuild/core';
|
|
2
|
-
|
|
3
|
-
type
|
|
1
|
+
import type { RsbuildPlugin } from '@rsbuild/core';
|
|
2
|
+
import type { sveltePreprocess } from 'svelte-preprocess';
|
|
3
|
+
import type { CompileOptions } from 'svelte/compiler';
|
|
4
|
+
export type AutoPreprocessOptions = NonNullable<Parameters<typeof sveltePreprocess>[0]>;
|
|
5
|
+
export interface SvelteLoaderOptions {
|
|
6
|
+
compilerOptions?: Omit<CompileOptions, 'filename' | 'format' | 'generate'>;
|
|
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;
|
|
14
|
+
[key: string]: any;
|
|
15
|
+
};
|
|
16
|
+
[key: string]: any;
|
|
17
|
+
}
|
|
18
|
+
export type PluginSvelteOptions = {
|
|
4
19
|
/**
|
|
5
20
|
* The options of svelte-loader
|
|
6
|
-
*
|
|
7
|
-
|
|
21
|
+
* @see https://github.com/sveltejs/svelte-loader
|
|
22
|
+
*/
|
|
23
|
+
svelteLoaderOptions?: SvelteLoaderOptions;
|
|
24
|
+
/**
|
|
25
|
+
* The options of svelte-preprocess.
|
|
26
|
+
* @see https://github.com/sveltejs/svelte-preprocess
|
|
8
27
|
*/
|
|
9
|
-
|
|
28
|
+
preprocessOptions?: AutoPreprocessOptions;
|
|
10
29
|
};
|
|
11
|
-
declare
|
|
12
|
-
|
|
13
|
-
export { PluginSvelteOptions, pluginSvelte };
|
|
30
|
+
export declare const PLUGIN_SVELTE_NAME = "rsbuild:svelte";
|
|
31
|
+
export declare function pluginSvelte(options?: PluginSvelteOptions): RsbuildPlugin;
|
package/dist/index.js
CHANGED
|
@@ -1,89 +1,80 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
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);
|
|
1
|
+
import { createRequire } from 'module';
|
|
2
|
+
var require = createRequire(import.meta['url']);
|
|
29
3
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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');
|
|
34
10
|
});
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
11
|
+
|
|
12
|
+
// ../../node_modules/.pnpm/@modern-js+module-tools@2.54.6_eslint@9.6.0_typescript@5.5.2/node_modules/@modern-js/module-tools/shims/esm.js
|
|
13
|
+
import { fileURLToPath } from "url";
|
|
14
|
+
import path from "path";
|
|
15
|
+
|
|
16
|
+
// src/index.ts
|
|
17
|
+
import path2 from "path";
|
|
18
|
+
import { logger } from "@rsbuild/core";
|
|
19
|
+
var PLUGIN_SVELTE_NAME = "rsbuild:svelte";
|
|
38
20
|
function pluginSvelte(options = {}) {
|
|
39
21
|
return {
|
|
40
|
-
name:
|
|
22
|
+
name: PLUGIN_SVELTE_NAME,
|
|
41
23
|
setup(api) {
|
|
42
24
|
let sveltePath = "";
|
|
43
25
|
try {
|
|
44
|
-
sveltePath =
|
|
45
|
-
|
|
26
|
+
sveltePath = path2.dirname(
|
|
27
|
+
__require.resolve("svelte/package.json", {
|
|
46
28
|
paths: [api.context.rootPath]
|
|
47
29
|
})
|
|
48
30
|
);
|
|
49
31
|
} catch (err) {
|
|
50
|
-
|
|
51
|
-
|
|
32
|
+
logger.error(
|
|
33
|
+
"Cannot resolve `svelte` package under the project directory, did you forget to install it?"
|
|
52
34
|
);
|
|
53
|
-
throw new Error(
|
|
35
|
+
throw new Error("Cannot resolve `svelte` package", {
|
|
54
36
|
cause: err
|
|
55
37
|
});
|
|
56
38
|
}
|
|
57
|
-
api.modifyBundlerChain(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
+
}
|
|
67
56
|
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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,
|
|
72
66
|
compilerOptions: {
|
|
73
|
-
dev:
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
);
|
|
81
|
-
chain.module.rule(CHAIN_ID.RULE.SVELTE).test(/\.svelte$/).use(CHAIN_ID.USE.SVELTE).loader(loaderPath).options(svelteLoaderOptions);
|
|
82
|
-
});
|
|
67
|
+
dev: isDev,
|
|
68
|
+
...userLoaderOptions.compilerOptions
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
chain.module.rule(CHAIN_ID.RULE.SVELTE).test(/\.svelte$/).use(CHAIN_ID.USE.SVELTE).loader(loaderPath).options(svelteLoaderOptions);
|
|
72
|
+
}
|
|
73
|
+
);
|
|
83
74
|
}
|
|
84
75
|
};
|
|
85
76
|
}
|
|
86
|
-
|
|
87
|
-
|
|
77
|
+
export {
|
|
78
|
+
PLUGIN_SVELTE_NAME,
|
|
88
79
|
pluginSvelte
|
|
89
|
-
}
|
|
80
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsbuild/plugin-svelte",
|
|
3
|
-
"version": "1.0.0",
|
|
3
|
+
"version": "1.0.1-beta.0",
|
|
4
4
|
"description": "Svelte plugin for Rsbuild",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -8,28 +8,32 @@
|
|
|
8
8
|
"directory": "packages/plugin-svelte"
|
|
9
9
|
},
|
|
10
10
|
"license": "MIT",
|
|
11
|
+
"type": "module",
|
|
11
12
|
"exports": {
|
|
12
13
|
".": {
|
|
13
14
|
"types": "./dist/index.d.ts",
|
|
14
|
-
"import": "./dist/index.
|
|
15
|
-
"
|
|
15
|
+
"import": "./dist/index.js",
|
|
16
|
+
"require": "./dist/index.cjs"
|
|
16
17
|
}
|
|
17
18
|
},
|
|
18
|
-
"main": "./dist/index.
|
|
19
|
+
"main": "./dist/index.cjs",
|
|
19
20
|
"types": "./dist/index.d.ts",
|
|
20
21
|
"files": [
|
|
21
22
|
"dist"
|
|
22
23
|
],
|
|
23
24
|
"dependencies": {
|
|
24
|
-
"svelte-loader": "3.
|
|
25
|
-
"svelte-preprocess": "^
|
|
26
|
-
"@rsbuild/shared": "1.0.0"
|
|
25
|
+
"svelte-loader": "3.2.3",
|
|
26
|
+
"svelte-preprocess": "^6.0.1"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@types/node": "
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"@rsbuild/
|
|
29
|
+
"@types/node": "18.x",
|
|
30
|
+
"svelte": "^4.2.18",
|
|
31
|
+
"typescript": "^5.5.2",
|
|
32
|
+
"@rsbuild/core": "1.0.1-beta.0",
|
|
33
|
+
"@scripts/test-helper": "1.0.1-beta.0"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@rsbuild/core": "^1.0.1-beta.0"
|
|
33
37
|
},
|
|
34
38
|
"publishConfig": {
|
|
35
39
|
"access": "public",
|
package/dist/index.mjs
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
-
}) : x)(function(x) {
|
|
4
|
-
if (typeof require !== "undefined")
|
|
5
|
-
return require.apply(this, arguments);
|
|
6
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
// ../../node_modules/.pnpm/@modern-js+module-tools@2.40.0_typescript@5.3.2/node_modules/@modern-js/module-tools/shims/esm.js
|
|
10
|
-
import { fileURLToPath } from "url";
|
|
11
|
-
import path from "path";
|
|
12
|
-
|
|
13
|
-
// ../../scripts/require_shims.js
|
|
14
|
-
import { createRequire } from "module";
|
|
15
|
-
global.require = createRequire(import.meta.url);
|
|
16
|
-
|
|
17
|
-
// src/index.ts
|
|
18
|
-
import path2 from "path";
|
|
19
|
-
import { logger, deepmerge } from "@rsbuild/shared";
|
|
20
|
-
function pluginSvelte(options = {}) {
|
|
21
|
-
return {
|
|
22
|
-
name: "rsbuild:svelte",
|
|
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(async (chain, { CHAIN_ID, isProd }) => {
|
|
40
|
-
const { default: sveltePreprocess } = await import("svelte-preprocess");
|
|
41
|
-
const rsbuildConfig = api.getNormalizedConfig();
|
|
42
|
-
chain.resolve.alias.set("svelte", path2.join(sveltePath, "src/runtime")).end().extensions.add(".svelte").end().mainFields.prepend("svelte").end().set("conditionNames", ["svelte", "browser", "import"]);
|
|
43
|
-
const loaderPath = __require.resolve("svelte-loader");
|
|
44
|
-
chain.merge({
|
|
45
|
-
resolveLoader: {
|
|
46
|
-
alias: {
|
|
47
|
-
"svelte-loader": loaderPath
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
const svelteLoaderOptions = deepmerge(
|
|
52
|
-
{
|
|
53
|
-
compilerOptions: {
|
|
54
|
-
dev: !isProd
|
|
55
|
-
},
|
|
56
|
-
preprocess: sveltePreprocess(),
|
|
57
|
-
emitCss: !rsbuildConfig.output.disableCssExtract,
|
|
58
|
-
hotReload: !isProd && rsbuildConfig.dev.hmr
|
|
59
|
-
},
|
|
60
|
-
options.svelteLoaderOptions ?? {}
|
|
61
|
-
);
|
|
62
|
-
chain.module.rule(CHAIN_ID.RULE.SVELTE).test(/\.svelte$/).use(CHAIN_ID.USE.SVELTE).loader(loaderPath).options(svelteLoaderOptions);
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
export {
|
|
68
|
-
pluginSvelte
|
|
69
|
-
};
|