@lytjs/bundler 6.5.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 ADDED
@@ -0,0 +1,81 @@
1
+ # @lytjs/bundler
2
+
3
+ LytJS 构建工具集成,提供 Vite 和 Webpack 插件支持。
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ pnpm add -D @lytjs/bundler
9
+ ```
10
+
11
+ ## 快速开始
12
+
13
+ ### Vite 配置
14
+
15
+ ```typescript
16
+ import { defineConfig } from 'vite';
17
+ import { createVitePlugin } from '@lytjs/bundler';
18
+
19
+ export default defineConfig({
20
+ plugins: [
21
+ createVitePlugin({
22
+ ssr: false,
23
+ ssg: false,
24
+ }),
25
+ ],
26
+ });
27
+ ```
28
+
29
+ ### 预设配置
30
+
31
+ ```typescript
32
+ import { createViteConfig } from '@lytjs/bundler';
33
+
34
+ export default createViteConfig({
35
+ ssg: true,
36
+ });
37
+ ```
38
+
39
+ ## 特性
40
+
41
+ - Vite 插件集成
42
+ - Webpack 插件集成
43
+ - SSG 支持
44
+ - SSR 配置优化
45
+
46
+ ## API
47
+
48
+ ### createVitePlugin(options)
49
+
50
+ 创建 Vite 插件。
51
+
52
+ ```typescript
53
+ import { createVitePlugin } from '@lytjs/bundler';
54
+
55
+ const plugin = createVitePlugin({
56
+ ssr: false,
57
+ ssg: false,
58
+ });
59
+ ```
60
+
61
+ ### createWebpackPlugin(options)
62
+
63
+ 创建 Webpack 插件。
64
+
65
+ ### getPreset(name)
66
+
67
+ 获取预设配置。
68
+
69
+ ```typescript
70
+ import { getPreset } from '@lytjs/bundler';
71
+
72
+ const preset = getPreset('ssg');
73
+ ```
74
+
75
+ ### createViteConfig(options)
76
+
77
+ 创建完整的 Vite 配置。
78
+
79
+ ## 许可证
80
+
81
+ MIT
package/dist/index.cjs ADDED
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ createViteConfig: () => createViteConfig,
24
+ createVitePlugin: () => createVitePlugin,
25
+ createWebpackPlugin: () => createWebpackPlugin,
26
+ getPreset: () => getPreset
27
+ });
28
+ module.exports = __toCommonJS(index_exports);
29
+ function createVitePlugin(options = {}) {
30
+ const { ssg = false, ssgPages = [], ssr = false } = options;
31
+ return {
32
+ name: "lytjs",
33
+ configResolved(config) {
34
+ console.log("[lytjs] Vite plugin resolved");
35
+ },
36
+ transform(code, id) {
37
+ if (id.endsWith(".lyt") || id.endsWith(".vue")) {
38
+ console.log("[lytjs] Transforming", id);
39
+ }
40
+ return null;
41
+ },
42
+ configureServer(server) {
43
+ console.log("[lytjs] Dev server configured");
44
+ }
45
+ };
46
+ }
47
+ function createWebpackPlugin(options = {}) {
48
+ const { ssg = false, ssgPages = [], ssr = false } = options;
49
+ return {
50
+ name: "lytjs",
51
+ apply(compiler) {
52
+ compiler.hooks.beforeCompile.tap("LytPlugin", () => {
53
+ console.log("[lytjs] Webpack plugin applied");
54
+ });
55
+ }
56
+ };
57
+ }
58
+ function getPreset(name = "default") {
59
+ const presets = {
60
+ default: {
61
+ name: "default",
62
+ vite: {
63
+ plugins: [createVitePlugin()]
64
+ }
65
+ },
66
+ ssg: {
67
+ name: "ssg",
68
+ vite: {
69
+ plugins: [createVitePlugin({ ssg: true })]
70
+ }
71
+ },
72
+ ssr: {
73
+ name: "ssr",
74
+ vite: {
75
+ plugins: [createVitePlugin({ ssr: true })]
76
+ }
77
+ }
78
+ };
79
+ return presets[name] || presets.default;
80
+ }
81
+ function createViteConfig(options = {}) {
82
+ const preset = getPreset(options.ssg ? "ssg" : options.ssr ? "ssr" : "default");
83
+ return {
84
+ ...preset.vite
85
+ };
86
+ }
87
+ // Annotate the CommonJS export names for ESM import in node:
88
+ 0 && (module.exports = {
89
+ createViteConfig,
90
+ createVitePlugin,
91
+ createWebpackPlugin,
92
+ getPreset
93
+ });
@@ -0,0 +1,62 @@
1
+ /**
2
+ * @lytjs/bundler - Type definitions
3
+ */
4
+ interface LytPluginOptions {
5
+ /** 是否启用 SSG */
6
+ ssg?: boolean;
7
+ /** SSG 页面路径 */
8
+ ssgPages?: string[];
9
+ /** 是否启用 SSR */
10
+ ssr?: boolean;
11
+ }
12
+ interface LytPluginConfig {
13
+ /** Vite 插件配置 */
14
+ vite?: any;
15
+ /** Webpack 插件配置 */
16
+ webpack?: any;
17
+ }
18
+ interface BundlerPreset {
19
+ /** 预设名称 */
20
+ name: string;
21
+ /** Vite 配置 */
22
+ vite?: any;
23
+ /** Webpack 配置 */
24
+ webpack?: any;
25
+ }
26
+
27
+ /**
28
+ * @lytjs/bundler - LytJS 构建工具集成
29
+ *
30
+ * 提供 Vite 和 Webpack 的基础集成
31
+ */
32
+
33
+ /**
34
+ * 创建 Vite 插件
35
+ *
36
+ * @param options - 插件选项
37
+ * @returns Vite 插件
38
+ */
39
+ declare function createVitePlugin(options?: LytPluginOptions): any;
40
+ /**
41
+ * 创建 Webpack 插件
42
+ *
43
+ * @param options - 插件选项
44
+ * @returns Webpack 插件
45
+ */
46
+ declare function createWebpackPlugin(options?: LytPluginOptions): any;
47
+ /**
48
+ * 获取默认预设配置
49
+ *
50
+ * @param name - 预设名称
51
+ * @returns 预设配置
52
+ */
53
+ declare function getPreset(name?: string): BundlerPreset;
54
+ /**
55
+ * 创建完整的 Vite 配置
56
+ *
57
+ * @param options - 插件选项
58
+ * @returns Vite 配置
59
+ */
60
+ declare function createViteConfig(options?: LytPluginOptions): any;
61
+
62
+ export { type BundlerPreset, type LytPluginConfig, type LytPluginOptions, createViteConfig, createVitePlugin, createWebpackPlugin, getPreset };
@@ -0,0 +1,62 @@
1
+ /**
2
+ * @lytjs/bundler - Type definitions
3
+ */
4
+ interface LytPluginOptions {
5
+ /** 是否启用 SSG */
6
+ ssg?: boolean;
7
+ /** SSG 页面路径 */
8
+ ssgPages?: string[];
9
+ /** 是否启用 SSR */
10
+ ssr?: boolean;
11
+ }
12
+ interface LytPluginConfig {
13
+ /** Vite 插件配置 */
14
+ vite?: any;
15
+ /** Webpack 插件配置 */
16
+ webpack?: any;
17
+ }
18
+ interface BundlerPreset {
19
+ /** 预设名称 */
20
+ name: string;
21
+ /** Vite 配置 */
22
+ vite?: any;
23
+ /** Webpack 配置 */
24
+ webpack?: any;
25
+ }
26
+
27
+ /**
28
+ * @lytjs/bundler - LytJS 构建工具集成
29
+ *
30
+ * 提供 Vite 和 Webpack 的基础集成
31
+ */
32
+
33
+ /**
34
+ * 创建 Vite 插件
35
+ *
36
+ * @param options - 插件选项
37
+ * @returns Vite 插件
38
+ */
39
+ declare function createVitePlugin(options?: LytPluginOptions): any;
40
+ /**
41
+ * 创建 Webpack 插件
42
+ *
43
+ * @param options - 插件选项
44
+ * @returns Webpack 插件
45
+ */
46
+ declare function createWebpackPlugin(options?: LytPluginOptions): any;
47
+ /**
48
+ * 获取默认预设配置
49
+ *
50
+ * @param name - 预设名称
51
+ * @returns 预设配置
52
+ */
53
+ declare function getPreset(name?: string): BundlerPreset;
54
+ /**
55
+ * 创建完整的 Vite 配置
56
+ *
57
+ * @param options - 插件选项
58
+ * @returns Vite 配置
59
+ */
60
+ declare function createViteConfig(options?: LytPluginOptions): any;
61
+
62
+ export { type BundlerPreset, type LytPluginConfig, type LytPluginOptions, createViteConfig, createVitePlugin, createWebpackPlugin, getPreset };
package/dist/index.mjs ADDED
@@ -0,0 +1,65 @@
1
+ // src/index.ts
2
+ function createVitePlugin(options = {}) {
3
+ const { ssg = false, ssgPages = [], ssr = false } = options;
4
+ return {
5
+ name: "lytjs",
6
+ configResolved(config) {
7
+ console.log("[lytjs] Vite plugin resolved");
8
+ },
9
+ transform(code, id) {
10
+ if (id.endsWith(".lyt") || id.endsWith(".vue")) {
11
+ console.log("[lytjs] Transforming", id);
12
+ }
13
+ return null;
14
+ },
15
+ configureServer(server) {
16
+ console.log("[lytjs] Dev server configured");
17
+ }
18
+ };
19
+ }
20
+ function createWebpackPlugin(options = {}) {
21
+ const { ssg = false, ssgPages = [], ssr = false } = options;
22
+ return {
23
+ name: "lytjs",
24
+ apply(compiler) {
25
+ compiler.hooks.beforeCompile.tap("LytPlugin", () => {
26
+ console.log("[lytjs] Webpack plugin applied");
27
+ });
28
+ }
29
+ };
30
+ }
31
+ function getPreset(name = "default") {
32
+ const presets = {
33
+ default: {
34
+ name: "default",
35
+ vite: {
36
+ plugins: [createVitePlugin()]
37
+ }
38
+ },
39
+ ssg: {
40
+ name: "ssg",
41
+ vite: {
42
+ plugins: [createVitePlugin({ ssg: true })]
43
+ }
44
+ },
45
+ ssr: {
46
+ name: "ssr",
47
+ vite: {
48
+ plugins: [createVitePlugin({ ssr: true })]
49
+ }
50
+ }
51
+ };
52
+ return presets[name] || presets.default;
53
+ }
54
+ function createViteConfig(options = {}) {
55
+ const preset = getPreset(options.ssg ? "ssg" : options.ssr ? "ssr" : "default");
56
+ return {
57
+ ...preset.vite
58
+ };
59
+ }
60
+ export {
61
+ createViteConfig,
62
+ createVitePlugin,
63
+ createWebpackPlugin,
64
+ getPreset
65
+ };
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@lytjs/bundler",
3
+ "version": "6.5.0",
4
+ "description": "LytJS bundler integration for Vite",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.mjs",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.mjs",
13
+ "require": "./dist/index.cjs"
14
+ },
15
+ "./package.json": "./package.json"
16
+ },
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "sideEffects": false,
21
+ "scripts": {
22
+ "build": "tsup",
23
+ "dev": "tsup --watch",
24
+ "test": "vitest run",
25
+ "type-check": "tsc --noEmit",
26
+ "lint": "eslint \"src/**/*.ts\"",
27
+ "clean": "rm -rf dist"
28
+ },
29
+ "dependencies": {},
30
+ "devDependencies": {
31
+ "tsup": "^8.0.0",
32
+ "typescript": "^5.4.0",
33
+ "vitest": "^3.0.0"
34
+ },
35
+ "license": "MIT",
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "https://gitee.com/lytjs/lytjs.git",
39
+ "directory": "packages/ecosystem/packages/bundler"
40
+ },
41
+ "keywords": [
42
+ "lytjs",
43
+ "bundler",
44
+ "vite",
45
+ "webpack"
46
+ ]
47
+ }