@l-comedy/core 0.1.2 → 0.1.4

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.d.ts CHANGED
@@ -16,7 +16,11 @@ interface UserConfig {
16
16
  basename?: string
17
17
  routes?: RouteConfig[]
18
18
  }
19
- plugins?: Array<'route' | LComedyPlugin>
19
+ reduxToolkit?: {
20
+ /** 相对于@ */
21
+ slicesDir?: string
22
+ }
23
+ plugins?: Array<'route' | 'redux-toolkit' | LComedyPlugin>
20
24
  rspackConfig?: Configuration
21
25
  sourceDir?: string
22
26
  output?: string
@@ -29,11 +33,11 @@ interface LComedyPlugin {
29
33
  name: string
30
34
  generateFiles?: (setupConfig: SetupConfigPlugin) => Promise<void> | viod
31
35
  modifyEntry?: (
32
- setupConfig: SetupConfigPlugin
36
+ setupConfig: SetupConfigPlugin,
33
37
  ) => EntryModifier | Promise<EntryModifier>
34
38
  rspackConfig?: (
35
39
  rspackConfig: Configuration,
36
- setupConfig: SetupConfig
40
+ setupConfig: SetupConfig,
37
41
  ) => Configuration | Promise<Configuration>
38
42
  runtimeExports?: string[]
39
43
  }
@@ -72,6 +76,7 @@ type SetupConfigPlugin = Omit<SetupConfig, 'plugins'>
72
76
 
73
77
  interface EntryModifier {
74
78
  imports?: string[]
79
+ runtimeExports?: string[]
75
80
  reactImports?: string[]
76
81
  beforeRender?: string
77
82
  afterRender?: string
@@ -1,4 +1,4 @@
1
- import { L as LComedyPlugin } from '../types.d-LN_39F7o.js';
1
+ import { L as LComedyPlugin } from '../types.d-CDy64Uxi.js';
2
2
  import '@rspack/core';
3
3
  import 'tsup';
4
4
  import 'html-webpack-plugin';
@@ -82,7 +82,9 @@ function createLComedyPluginAppConfig() {
82
82
  transpileOnly: true,
83
83
  compilerOptions: {
84
84
  paths: {
85
- "@/*": ["src/*"]
85
+ // TODO: 使用变量
86
+ "@/*": ["src/*"],
87
+ "@@/*": [".comedy/*"]
86
88
  }
87
89
  }
88
90
  }
@@ -133,7 +135,8 @@ function createLComedyPluginAppConfig() {
133
135
  patterns: [
134
136
  {
135
137
  from: publicDir,
136
- to: "."
138
+ to: ".",
139
+ noErrorOnMissing: true
137
140
  }
138
141
  ]
139
142
  })
@@ -1,5 +1,5 @@
1
1
  export { createLComedyPluginAppConfig as default } from './createLComedyPluginAppConfig.js';
2
- import '../types.d-LN_39F7o.js';
2
+ import '../types.d-CDy64Uxi.js';
3
3
  import '@rspack/core';
4
4
  import 'tsup';
5
5
  import 'html-webpack-plugin';
@@ -84,7 +84,9 @@ function createLComedyPluginAppConfig() {
84
84
  transpileOnly: true,
85
85
  compilerOptions: {
86
86
  paths: {
87
- "@/*": ["src/*"]
87
+ // TODO: 使用变量
88
+ "@/*": ["src/*"],
89
+ "@@/*": [".comedy/*"]
88
90
  }
89
91
  }
90
92
  }
@@ -135,7 +137,8 @@ function createLComedyPluginAppConfig() {
135
137
  patterns: [
136
138
  {
137
139
  from: publicDir,
138
- to: "."
140
+ to: ".",
141
+ noErrorOnMissing: true
139
142
  }
140
143
  ]
141
144
  })
@@ -0,0 +1,9 @@
1
+ import { L as LComedyPlugin } from '../types.d-CDy64Uxi.js';
2
+ import '@rspack/core';
3
+ import 'tsup';
4
+ import 'html-webpack-plugin';
5
+ import '@jest/types';
6
+
7
+ declare function createLComedyPluginGlobalCSS(): LComedyPlugin;
8
+
9
+ export { createLComedyPluginGlobalCSS };
@@ -0,0 +1,59 @@
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/plugins/global-css/createLComedyPluginGlobalCSS.ts
31
+ var createLComedyPluginGlobalCSS_exports = {};
32
+ __export(createLComedyPluginGlobalCSS_exports, {
33
+ createLComedyPluginGlobalCSS: () => createLComedyPluginGlobalCSS
34
+ });
35
+ module.exports = __toCommonJS(createLComedyPluginGlobalCSS_exports);
36
+ var import_fs_extra = __toESM(require("fs-extra"));
37
+ var import_path = __toESM(require("path"));
38
+ var names = ["global.css", "global.less"];
39
+ function createLComedyPluginGlobalCSS() {
40
+ return {
41
+ name: "l-comedy-plugin-global-css",
42
+ modifyEntry(setupConfig) {
43
+ const imports = [];
44
+ names.forEach((name) => {
45
+ const cssPath = import_path.default.posix.join(setupConfig.sourceDir, name);
46
+ if (import_fs_extra.default.existsSync(cssPath)) {
47
+ imports.push(`import '@/${name}'`);
48
+ }
49
+ });
50
+ return {
51
+ imports
52
+ };
53
+ }
54
+ };
55
+ }
56
+ // Annotate the CommonJS export names for ESM import in node:
57
+ 0 && (module.exports = {
58
+ createLComedyPluginGlobalCSS
59
+ });
@@ -0,0 +1,6 @@
1
+ export { createLComedyPluginGlobalCSS as default } from './createLComedyPluginGlobalCSS.js';
2
+ import '../types.d-CDy64Uxi.js';
3
+ import '@rspack/core';
4
+ import 'tsup';
5
+ import 'html-webpack-plugin';
6
+ import '@jest/types';
@@ -0,0 +1,57 @@
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/plugins/global-css/index.ts
31
+ var global_css_exports = {};
32
+ __export(global_css_exports, {
33
+ default: () => createLComedyPluginGlobalCSS
34
+ });
35
+ module.exports = __toCommonJS(global_css_exports);
36
+
37
+ // src/plugins/global-css/createLComedyPluginGlobalCSS.ts
38
+ var import_fs_extra = __toESM(require("fs-extra"));
39
+ var import_path = __toESM(require("path"));
40
+ var names = ["global.css", "global.less"];
41
+ function createLComedyPluginGlobalCSS() {
42
+ return {
43
+ name: "l-comedy-plugin-global-css",
44
+ modifyEntry(setupConfig) {
45
+ const imports = [];
46
+ names.forEach((name) => {
47
+ const cssPath = import_path.default.posix.join(setupConfig.sourceDir, name);
48
+ if (import_fs_extra.default.existsSync(cssPath)) {
49
+ imports.push(`import '@/${name}'`);
50
+ }
51
+ });
52
+ return {
53
+ imports
54
+ };
55
+ }
56
+ };
57
+ }
@@ -1,4 +1,4 @@
1
- import { S as SetupConfigPlugin } from '../types.d-LN_39F7o.js';
1
+ import { S as SetupConfigPlugin } from '../types.d-CDy64Uxi.js';
2
2
  import '@rspack/core';
3
3
  import 'tsup';
4
4
  import 'html-webpack-plugin';
@@ -1,4 +1,4 @@
1
- import { L as LComedyPlugin } from '../types.d-LN_39F7o.js';
1
+ import { L as LComedyPlugin } from '../types.d-CDy64Uxi.js';
2
2
  import '@rspack/core';
3
3
  import 'tsup';
4
4
  import 'html-webpack-plugin';
@@ -1,4 +1,4 @@
1
- import { S as SetupConfigPlugin } from '../types.d-LN_39F7o.js';
1
+ import { S as SetupConfigPlugin } from '../types.d-CDy64Uxi.js';
2
2
  import '@rspack/core';
3
3
  import 'tsup';
4
4
  import 'html-webpack-plugin';
@@ -1,5 +1,5 @@
1
1
  export { createLComedyPluginHtml as default } from './createLComedyPluginHtml.js';
2
- import '../types.d-LN_39F7o.js';
2
+ import '../types.d-CDy64Uxi.js';
3
3
  import '@rspack/core';
4
4
  import 'tsup';
5
5
  import 'html-webpack-plugin';
@@ -1,4 +1,4 @@
1
- import { L as LComedyPlugin } from '../types.d-LN_39F7o.js';
1
+ import { L as LComedyPlugin } from '../types.d-CDy64Uxi.js';
2
2
  import '@rspack/core';
3
3
  import 'tsup';
4
4
  import 'html-webpack-plugin';
@@ -1,5 +1,5 @@
1
1
  export { createLComedyPluginLayout as default } from './createLComedyPluginLayout.js';
2
- import '../types.d-LN_39F7o.js';
2
+ import '../types.d-CDy64Uxi.js';
3
3
  import '@rspack/core';
4
4
  import 'tsup';
5
5
  import 'html-webpack-plugin';
@@ -1,4 +1,4 @@
1
- import { L as LComedyPlugin } from '../types.d-LN_39F7o.js';
1
+ import { L as LComedyPlugin } from '../types.d-CDy64Uxi.js';
2
2
  import '@rspack/core';
3
3
  import 'tsup';
4
4
  import 'html-webpack-plugin';
@@ -1,5 +1,5 @@
1
1
  export { createLComedyPluginPageLoading as default } from './createLComedyPluginPageLoading.js';
2
- import '../types.d-LN_39F7o.js';
2
+ import '../types.d-CDy64Uxi.js';
3
3
  import '@rspack/core';
4
4
  import 'tsup';
5
5
  import 'html-webpack-plugin';
@@ -0,0 +1,9 @@
1
+ import { L as LComedyPlugin } from '../types.d-CDy64Uxi.js';
2
+ import '@rspack/core';
3
+ import 'tsup';
4
+ import 'html-webpack-plugin';
5
+ import '@jest/types';
6
+
7
+ declare function createLComedyPluginReduxToolkit(): LComedyPlugin;
8
+
9
+ export { createLComedyPluginReduxToolkit };
@@ -0,0 +1,152 @@
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
+ var __async = (__this, __arguments, generator) => {
30
+ return new Promise((resolve, reject) => {
31
+ var fulfilled = (value) => {
32
+ try {
33
+ step(generator.next(value));
34
+ } catch (e) {
35
+ reject(e);
36
+ }
37
+ };
38
+ var rejected = (value) => {
39
+ try {
40
+ step(generator.throw(value));
41
+ } catch (e) {
42
+ reject(e);
43
+ }
44
+ };
45
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
46
+ step((generator = generator.apply(__this, __arguments)).next());
47
+ });
48
+ };
49
+
50
+ // src/plugins/redux-toolkit/createLComedyPluginReduxToolkit.ts
51
+ var createLComedyPluginReduxToolkit_exports = {};
52
+ __export(createLComedyPluginReduxToolkit_exports, {
53
+ createLComedyPluginReduxToolkit: () => createLComedyPluginReduxToolkit
54
+ });
55
+ module.exports = __toCommonJS(createLComedyPluginReduxToolkit_exports);
56
+ var import_fs_extra = __toESM(require("fs-extra"));
57
+ var import_path = __toESM(require("path"));
58
+ var import_fast_glob = __toESM(require("fast-glob"));
59
+ function createLComedyPluginReduxToolkit() {
60
+ return {
61
+ name: "l-comedy-plugin-redux-toolkit",
62
+ generateFiles(setupConfig) {
63
+ return __async(this, null, function* () {
64
+ var _a2;
65
+ const sliceDir = ((_a2 = setupConfig.userConfig.reduxToolkit) == null ? void 0 : _a2.slicesDir) || `store/slice`;
66
+ const entires = yield (0, import_fast_glob.default)([`${sliceDir}/*.ts`, "!**/*.tsx"], {
67
+ cwd: setupConfig.sourcePath,
68
+ onlyFiles: true
69
+ });
70
+ const fileMap = entires.map((filePath) => ({
71
+ name: import_path.default.parse(filePath).name,
72
+ filePath
73
+ }));
74
+ import_fs_extra.default.outputFileSync(
75
+ import_path.default.posix.join(setupConfig.workDir, "runtimes", "redux/store.ts"),
76
+ `import { configureStore } from '@reduxjs/toolkit';
77
+ import {
78
+ useDispatch,
79
+ useSelector,
80
+ useStore,
81
+ } from 'react-redux';
82
+ import type { TypedUseSelectorHook } from 'react-redux';
83
+
84
+ // \u5BFC\u5165\u6240\u6709 slice reducer
85
+ ${fileMap.map((item) => `import ${item.name}Reducer from '@/${sliceDir}/${item.name}';`).join("\n")}
86
+
87
+ // \u521B\u5EFA store
88
+ export const store = configureStore({
89
+ reducer: {
90
+ ${fileMap.map((item) => `${item.name}: ${item.name}Reducer,`).join("\n")}
91
+ },
92
+ });
93
+
94
+ export type RootState = ReturnType<typeof store.getState>;
95
+ export type AppDispatch = typeof store.dispatch;
96
+
97
+ export const useAppDispatch = () => useDispatch<AppDispatch>();
98
+ export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector;
99
+ export const useAppStore = () => useStore<RootState>();
100
+ `
101
+ );
102
+ });
103
+ },
104
+ modifyEntry() {
105
+ return __async(this, null, function* () {
106
+ return {
107
+ imports: [
108
+ `import { Provider as ReduxProvider } from 'react-redux'`,
109
+ `import { store as reduxStore } from './runtimes/redux/store'`
110
+ ],
111
+ runtimeExports: [
112
+ `export { useAppSelector, useAppDispatch, useAppStore } from './runtimes/redux/store'`
113
+ ],
114
+ appWrap(app) {
115
+ return `<ReduxProvider store={reduxStore}>
116
+ ${app}
117
+ </ReduxProvider>`;
118
+ }
119
+ };
120
+ });
121
+ }
122
+ /*modifyEntry(setupConfig) {
123
+ let hasLoading = false
124
+ const imports: string[] = []
125
+ const pageLoadingPath = path.posix.join(
126
+ setupConfig.sourceDir,
127
+ 'layout/PageLoading.tsx',
128
+ )
129
+
130
+ if (fs.existsSync(pageLoadingPath)) {
131
+ hasLoading = true
132
+ imports.push("import PageLoading from '@/layout/PageLoading'")
133
+ }
134
+
135
+ return {
136
+ imports,
137
+ reactImports: ['Suspense'],
138
+ appWrap(app) {
139
+ return `<Suspense fallback={${
140
+ hasLoading ? '<PageLoading />' : '<div />'
141
+ }}>
142
+ ${app}
143
+ </Suspense>`
144
+ },
145
+ }
146
+ },*/
147
+ };
148
+ }
149
+ // Annotate the CommonJS export names for ESM import in node:
150
+ 0 && (module.exports = {
151
+ createLComedyPluginReduxToolkit
152
+ });
@@ -0,0 +1,6 @@
1
+ export { createLComedyPluginReduxToolkit as default } from './createLComedyPluginReduxToolkit.js';
2
+ import '../types.d-CDy64Uxi.js';
3
+ import '@rspack/core';
4
+ import 'tsup';
5
+ import 'html-webpack-plugin';
6
+ import '@jest/types';
@@ -0,0 +1,150 @@
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
+ var __async = (__this, __arguments, generator) => {
30
+ return new Promise((resolve, reject) => {
31
+ var fulfilled = (value) => {
32
+ try {
33
+ step(generator.next(value));
34
+ } catch (e) {
35
+ reject(e);
36
+ }
37
+ };
38
+ var rejected = (value) => {
39
+ try {
40
+ step(generator.throw(value));
41
+ } catch (e) {
42
+ reject(e);
43
+ }
44
+ };
45
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
46
+ step((generator = generator.apply(__this, __arguments)).next());
47
+ });
48
+ };
49
+
50
+ // src/plugins/redux-toolkit/index.ts
51
+ var redux_toolkit_exports = {};
52
+ __export(redux_toolkit_exports, {
53
+ default: () => createLComedyPluginReduxToolkit
54
+ });
55
+ module.exports = __toCommonJS(redux_toolkit_exports);
56
+
57
+ // src/plugins/redux-toolkit/createLComedyPluginReduxToolkit.ts
58
+ var import_fs_extra = __toESM(require("fs-extra"));
59
+ var import_path = __toESM(require("path"));
60
+ var import_fast_glob = __toESM(require("fast-glob"));
61
+ function createLComedyPluginReduxToolkit() {
62
+ return {
63
+ name: "l-comedy-plugin-redux-toolkit",
64
+ generateFiles(setupConfig) {
65
+ return __async(this, null, function* () {
66
+ var _a2;
67
+ const sliceDir = ((_a2 = setupConfig.userConfig.reduxToolkit) == null ? void 0 : _a2.slicesDir) || `store/slice`;
68
+ const entires = yield (0, import_fast_glob.default)([`${sliceDir}/*.ts`, "!**/*.tsx"], {
69
+ cwd: setupConfig.sourcePath,
70
+ onlyFiles: true
71
+ });
72
+ const fileMap = entires.map((filePath) => ({
73
+ name: import_path.default.parse(filePath).name,
74
+ filePath
75
+ }));
76
+ import_fs_extra.default.outputFileSync(
77
+ import_path.default.posix.join(setupConfig.workDir, "runtimes", "redux/store.ts"),
78
+ `import { configureStore } from '@reduxjs/toolkit';
79
+ import {
80
+ useDispatch,
81
+ useSelector,
82
+ useStore,
83
+ } from 'react-redux';
84
+ import type { TypedUseSelectorHook } from 'react-redux';
85
+
86
+ // \u5BFC\u5165\u6240\u6709 slice reducer
87
+ ${fileMap.map((item) => `import ${item.name}Reducer from '@/${sliceDir}/${item.name}';`).join("\n")}
88
+
89
+ // \u521B\u5EFA store
90
+ export const store = configureStore({
91
+ reducer: {
92
+ ${fileMap.map((item) => `${item.name}: ${item.name}Reducer,`).join("\n")}
93
+ },
94
+ });
95
+
96
+ export type RootState = ReturnType<typeof store.getState>;
97
+ export type AppDispatch = typeof store.dispatch;
98
+
99
+ export const useAppDispatch = () => useDispatch<AppDispatch>();
100
+ export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector;
101
+ export const useAppStore = () => useStore<RootState>();
102
+ `
103
+ );
104
+ });
105
+ },
106
+ modifyEntry() {
107
+ return __async(this, null, function* () {
108
+ return {
109
+ imports: [
110
+ `import { Provider as ReduxProvider } from 'react-redux'`,
111
+ `import { store as reduxStore } from './runtimes/redux/store'`
112
+ ],
113
+ runtimeExports: [
114
+ `export { useAppSelector, useAppDispatch, useAppStore } from './runtimes/redux/store'`
115
+ ],
116
+ appWrap(app) {
117
+ return `<ReduxProvider store={reduxStore}>
118
+ ${app}
119
+ </ReduxProvider>`;
120
+ }
121
+ };
122
+ });
123
+ }
124
+ /*modifyEntry(setupConfig) {
125
+ let hasLoading = false
126
+ const imports: string[] = []
127
+ const pageLoadingPath = path.posix.join(
128
+ setupConfig.sourceDir,
129
+ 'layout/PageLoading.tsx',
130
+ )
131
+
132
+ if (fs.existsSync(pageLoadingPath)) {
133
+ hasLoading = true
134
+ imports.push("import PageLoading from '@/layout/PageLoading'")
135
+ }
136
+
137
+ return {
138
+ imports,
139
+ reactImports: ['Suspense'],
140
+ appWrap(app) {
141
+ return `<Suspense fallback={${
142
+ hasLoading ? '<PageLoading />' : '<div />'
143
+ }}>
144
+ ${app}
145
+ </Suspense>`
146
+ },
147
+ }
148
+ },*/
149
+ };
150
+ }
@@ -1,4 +1,4 @@
1
- import { L as LComedyPlugin } from '../types.d-LN_39F7o.js';
1
+ import { L as LComedyPlugin } from '../types.d-CDy64Uxi.js';
2
2
  import '@rspack/core';
3
3
  import 'tsup';
4
4
  import 'html-webpack-plugin';
@@ -1,5 +1,5 @@
1
1
  export { createLComedyPluginRoute as default } from './createLComedyPluginRoute.js';
2
- import '../types.d-LN_39F7o.js';
2
+ import '../types.d-CDy64Uxi.js';
3
3
  import '@rspack/core';
4
4
  import 'tsup';
5
5
  import 'html-webpack-plugin';
@@ -16,7 +16,11 @@ interface UserConfig {
16
16
  basename?: string
17
17
  routes?: RouteConfig[]
18
18
  }
19
- plugins?: Array<'route' | LComedyPlugin>
19
+ reduxToolkit?: {
20
+ /** 相对于@ */
21
+ slicesDir?: string
22
+ }
23
+ plugins?: Array<'route' | 'redux-toolkit' | LComedyPlugin>
20
24
  rspackConfig?: Configuration
21
25
  sourceDir?: string
22
26
  output?: string
@@ -29,11 +33,11 @@ interface LComedyPlugin {
29
33
  name: string
30
34
  generateFiles?: (setupConfig: SetupConfigPlugin) => Promise<void> | viod
31
35
  modifyEntry?: (
32
- setupConfig: SetupConfigPlugin
36
+ setupConfig: SetupConfigPlugin,
33
37
  ) => EntryModifier | Promise<EntryModifier>
34
38
  rspackConfig?: (
35
39
  rspackConfig: Configuration,
36
- setupConfig: SetupConfig
40
+ setupConfig: SetupConfig,
37
41
  ) => Configuration | Promise<Configuration>
38
42
  runtimeExports?: string[]
39
43
  }
@@ -72,6 +76,7 @@ type SetupConfigPlugin = Omit<SetupConfig, 'plugins'>
72
76
 
73
77
  interface EntryModifier {
74
78
  imports?: string[]
79
+ runtimeExports?: string[]
75
80
  reactImports?: string[]
76
81
  beforeRender?: string
77
82
  afterRender?: string
package/dist/run.js CHANGED
@@ -63,14 +63,14 @@ var __async = (__this, __arguments, generator) => {
63
63
  var import_commander = require("commander");
64
64
 
65
65
  // src/commands/dev.ts
66
- var import_path8 = __toESM(require("path"));
66
+ var import_path9 = __toESM(require("path"));
67
67
  var import_core2 = require("@rspack/core");
68
68
  var import_dev_server = require("@rspack/dev-server");
69
69
  var import_chokidar = __toESM(require("chokidar"));
70
70
 
71
71
  // src/setup.ts
72
- var import_fs_extra5 = __toESM(require("fs-extra"));
73
- var import_path7 = __toESM(require("path"));
72
+ var import_fs_extra6 = __toESM(require("fs-extra"));
73
+ var import_path8 = __toESM(require("path"));
74
74
 
75
75
  // src/utils/setup/generateEntryFile.ts
76
76
  var import_fs_extra = __toESM(require("fs-extra"));
@@ -130,6 +130,15 @@ import { createRoot } from 'react-dom/client';
130
130
  entryCode += m.afterRender + "\n";
131
131
  }
132
132
  });
133
+ yield import_fs_extra.default.outputFile(
134
+ import_path.default.posix.join(targetDir, "exports.ts"),
135
+ `${modifiers.filter((item) => item.runtimeExports).map(
136
+ (item) => {
137
+ var _a2;
138
+ return `${(_a2 = item.runtimeExports) == null ? void 0 : _a2.map((exportStr) => exportStr).join("\n")}`;
139
+ }
140
+ ).join("\n")}`
141
+ );
133
142
  yield import_fs_extra.default.outputFile(import_path.default.posix.join(targetDir, "entry.tsx"), entryCode);
134
143
  });
135
144
  }
@@ -167,7 +176,9 @@ function createLComedyPluginAppConfig() {
167
176
  transpileOnly: true,
168
177
  compilerOptions: {
169
178
  paths: {
170
- "@/*": ["src/*"]
179
+ // TODO: 使用变量
180
+ "@/*": ["src/*"],
181
+ "@@/*": [".comedy/*"]
171
182
  }
172
183
  }
173
184
  }
@@ -218,7 +229,8 @@ function createLComedyPluginAppConfig() {
218
229
  patterns: [
219
230
  {
220
231
  from: publicDir,
221
- to: "."
232
+ to: ".",
233
+ noErrorOnMissing: true
222
234
  }
223
235
  ]
224
236
  })
@@ -376,6 +388,28 @@ function createLComedyPluginLayout() {
376
388
  };
377
389
  }
378
390
 
391
+ // src/plugins/global-css/createLComedyPluginGlobalCSS.ts
392
+ var import_fs_extra5 = __toESM(require("fs-extra"));
393
+ var import_path7 = __toESM(require("path"));
394
+ var names = ["global.css", "global.less"];
395
+ function createLComedyPluginGlobalCSS() {
396
+ return {
397
+ name: "l-comedy-plugin-global-css",
398
+ modifyEntry(setupConfig) {
399
+ const imports = [];
400
+ names.forEach((name) => {
401
+ const cssPath = import_path7.default.posix.join(setupConfig.sourceDir, name);
402
+ if (import_fs_extra5.default.existsSync(cssPath)) {
403
+ imports.push(`import '@/${name}'`);
404
+ }
405
+ });
406
+ return {
407
+ imports
408
+ };
409
+ }
410
+ };
411
+ }
412
+
379
413
  // src/setup.ts
380
414
  function setup(userConfig, options) {
381
415
  return __async(this, null, function* () {
@@ -386,28 +420,29 @@ function setup(userConfig, options) {
386
420
  isProd,
387
421
  root: options.root,
388
422
  workDir,
389
- workPath: import_path7.default.posix.join(options.root, workDir),
423
+ workPath: import_path8.default.posix.join(options.root, workDir),
390
424
  sourceDir,
391
- sourcePath: import_path7.default.posix.join(options.root, sourceDir),
425
+ sourcePath: import_path8.default.posix.join(options.root, sourceDir),
392
426
  userConfig
393
427
  };
394
428
  const plugins = [
395
429
  createLComedyPluginAppConfig(),
396
430
  createLComedyPluginHtml(),
397
431
  createLComedyPluginLayout(),
398
- createLComedyPluginPageLoading()
432
+ createLComedyPluginPageLoading(),
433
+ createLComedyPluginGlobalCSS()
399
434
  ];
400
435
  for (const plugin of userConfig.plugins || []) {
401
436
  if (typeof plugin === "string") {
402
437
  plugins.push(
403
- require(import_path7.default.posix.join(__dirname, `./plugins/${plugin}`)).default()
438
+ require(import_path8.default.posix.join(__dirname, `./plugins/${plugin}`)).default()
404
439
  );
405
440
  } else if (typeof plugin === "object") {
406
441
  plugins.push(plugin);
407
442
  }
408
443
  }
409
- import_fs_extra5.default.ensureDirSync(baseConfig.workPath);
410
- import_fs_extra5.default.emptyDirSync(baseConfig.workPath);
444
+ import_fs_extra6.default.ensureDirSync(baseConfig.workPath);
445
+ import_fs_extra6.default.emptyDirSync(baseConfig.workPath);
411
446
  const modifiers = [];
412
447
  for (const plugin of plugins) {
413
448
  if (plugin.generateFiles) {
@@ -423,7 +458,7 @@ function setup(userConfig, options) {
423
458
  });
424
459
  yield generateEntryFile(
425
460
  modifiers,
426
- import_path7.default.posix.join(baseConfig.root, baseConfig.workDir),
461
+ import_path8.default.posix.join(baseConfig.root, baseConfig.workDir),
427
462
  setupConfig
428
463
  );
429
464
  let rspackConfig = {
@@ -431,7 +466,8 @@ function setup(userConfig, options) {
431
466
  resolve: {
432
467
  extensions: [".ts", ".tsx", ".js", ".jsx"],
433
468
  alias: {
434
- "@": setupConfig.sourcePath
469
+ "@": setupConfig.sourcePath,
470
+ "@@": setupConfig.workPath
435
471
  }
436
472
  }
437
473
  };
@@ -445,7 +481,7 @@ function setup(userConfig, options) {
445
481
  }
446
482
 
447
483
  // src/utils/config/loadUserConfig.ts
448
- var import_fs_extra6 = __toESM(require("fs-extra"));
484
+ var import_fs_extra7 = __toESM(require("fs-extra"));
449
485
  var import_vm = __toESM(require("vm"));
450
486
  var import_module = __toESM(require("module"));
451
487
  var import_esbuild = require("esbuild");
@@ -460,7 +496,7 @@ ${e}`);
460
496
  }
461
497
  function runFileConfig(filepath) {
462
498
  try {
463
- const fileContent = import_fs_extra6.default.readFileSync(filepath, "utf-8");
499
+ const fileContent = import_fs_extra7.default.readFileSync(filepath, "utf-8");
464
500
  const result = (0, import_esbuild.transformSync)(fileContent, {
465
501
  loader: "tsx",
466
502
  format: "cjs"
@@ -492,7 +528,7 @@ function getDefaultUserConfigName() {
492
528
  function dev(options) {
493
529
  return __async(this, null, function* () {
494
530
  const root = process.cwd().replace(/\\/g, "/");
495
- const filePath = import_path8.default.posix.join(
531
+ const filePath = import_path9.default.posix.join(
496
532
  root,
497
533
  (options == null ? void 0 : options.config) ? options.config : getDefaultUserConfigName()
498
534
  );
@@ -524,12 +560,12 @@ function createDevServer(root, filePath) {
524
560
  }
525
561
 
526
562
  // src/commands/build.ts
527
- var import_path9 = __toESM(require("path"));
563
+ var import_path10 = __toESM(require("path"));
528
564
  var import_core3 = require("@rspack/core");
529
565
  function build(options) {
530
566
  return __async(this, null, function* () {
531
567
  const root = process.cwd().replace(/\\/g, "/");
532
- const filePath = import_path9.default.posix.join(
568
+ const filePath = import_path10.default.posix.join(
533
569
  root,
534
570
  (options == null ? void 0 : options.config) ? options.config : getDefaultUserConfigName()
535
571
  );
@@ -576,7 +612,7 @@ function runBuild(rspackConfig) {
576
612
  }
577
613
 
578
614
  // src/commands/test.ts
579
- var import_path10 = __toESM(require("path"));
615
+ var import_path11 = __toESM(require("path"));
580
616
 
581
617
  // src/utils/setup/loadOptionalDependency.ts
582
618
  function loadOptionalDependency(packageName, importName) {
@@ -604,7 +640,7 @@ function test(options) {
604
640
  if (jestPreset) {
605
641
  const type = (options == null ? void 0 : options.type) || "all";
606
642
  const root = process.cwd().replace(/\\/g, "/");
607
- const filePath = import_path10.default.posix.join(
643
+ const filePath = import_path11.default.posix.join(
608
644
  root,
609
645
  (options == null ? void 0 : options.config) ? options.config : getDefaultUserConfigName()
610
646
  );
@@ -627,14 +663,14 @@ function test(options) {
627
663
  }
628
664
 
629
665
  // src/commands/tsup.ts
630
- var import_path11 = __toESM(require("path"));
631
- var import_fs_extra7 = __toESM(require("fs-extra"));
666
+ var import_path12 = __toESM(require("path"));
667
+ var import_fs_extra8 = __toESM(require("fs-extra"));
632
668
  var import_tsup = require("tsup");
633
669
  function runTsup(options) {
634
670
  return __async(this, null, function* () {
635
671
  var _a;
636
672
  const root = process.cwd().replace(/\\/g, "/");
637
- const filePath = import_path11.default.posix.join(
673
+ const filePath = import_path12.default.posix.join(
638
674
  root,
639
675
  (options == null ? void 0 : options.config) ? options.config : getDefaultUserConfigName()
640
676
  );
@@ -644,9 +680,9 @@ function runTsup(options) {
644
680
  return;
645
681
  }
646
682
  const outDir = userConfig.tsup.outDir || "lib";
647
- const outPath = import_path11.default.posix.join(root, outDir);
648
- import_fs_extra7.default.ensureDirSync(outPath);
649
- import_fs_extra7.default.emptyDirSync(outPath);
683
+ const outPath = import_path12.default.posix.join(root, outDir);
684
+ import_fs_extra8.default.ensureDirSync(outPath);
685
+ import_fs_extra8.default.emptyDirSync(outPath);
650
686
  for (const target of userConfig.tsup.targets) {
651
687
  yield (0, import_tsup.build)(__spreadValues({
652
688
  entry: [
@@ -656,15 +692,13 @@ function runTsup(options) {
656
692
  "!**/__tests__",
657
693
  "!**/*.test.*"
658
694
  ],
659
- outDir: import_path11.default.posix.join(root, outDir, "cjs", target.relativeOutDir || ""),
695
+ outDir: import_path12.default.posix.join(root, outDir, "cjs", target.relativeOutDir || ""),
660
696
  format: ["cjs"],
661
697
  dts: true,
662
698
  sourcemap: false,
663
699
  clean: false,
664
700
  minify: false,
665
701
  bundle: false,
666
- target: "node16",
667
- platform: "node",
668
702
  outExtension: () => ({ js: ".js", dts: ".d.ts" })
669
703
  }, userConfig.tsup.options));
670
704
  }
@@ -677,15 +711,13 @@ function runTsup(options) {
677
711
  "!**/__tests__",
678
712
  "!**/*.test.*"
679
713
  ],
680
- outDir: import_path11.default.posix.join(root, outDir, "esm", target.relativeOutDir || ""),
714
+ outDir: import_path12.default.posix.join(root, outDir, "esm", target.relativeOutDir || ""),
681
715
  format: ["esm"],
682
716
  dts: true,
683
717
  sourcemap: false,
684
718
  clean: false,
685
719
  minify: false,
686
720
  bundle: false,
687
- target: "node16",
688
- platform: "node",
689
721
  outExtension: () => ({ js: ".js", dts: ".d.ts" })
690
722
  }, userConfig.tsup.options));
691
723
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@l-comedy/core",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "bin": {
@@ -40,6 +40,7 @@
40
40
  "commander": "^14.0.2",
41
41
  "css-loader": "7.1.2",
42
42
  "esbuild": "^0.27.1",
43
+ "fast-glob": "^3.3.3",
43
44
  "fs-extra": "^11.3.2",
44
45
  "html-webpack-plugin": "^5.6.5",
45
46
  "less": "4.4.2",
@@ -50,8 +51,10 @@
50
51
  },
51
52
  "optionalDependencies": {
52
53
  "@l-comedy/jest-preset": "^0.1.0",
54
+ "@reduxjs/toolkit": "^2.11.2",
53
55
  "react": "^18.0.0 || ^19.0.0",
54
56
  "react-dom": "^18.0.0 || ^19.0.0",
57
+ "react-redux": "^9.2.0",
55
58
  "react-router": "^7.0.0",
56
59
  "tsup": "^8.5.1"
57
60
  },