swico 2.6.0-beta.1 → 2.6.0-beta.11

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swico",
3
- "version": "2.6.0-beta.1",
3
+ "version": "2.6.0-beta.11",
4
4
  "description": "Simple, efficient, and practical front-end framework",
5
5
  "main": "./src/index.js",
6
6
  "types": "./src/index.d.ts",
@@ -39,6 +39,7 @@
39
39
  "eslint-rspack-plugin": "4.2.1",
40
40
  "fs-extra": "11.3.0",
41
41
  "html-loader": "5.1.0",
42
+ "html-webpack-plugin": "5.6.4",
42
43
  "less": "4.3.0",
43
44
  "less-loader": "12.2.0",
44
45
  "ora": "5.4.1",
@@ -26,7 +26,7 @@ const dev_server_1 = require("@rspack/dev-server");
26
26
  const fs_extra_1 = __importDefault(require("fs-extra"));
27
27
  const core_1 = require("@rspack/core");
28
28
  let currentPort, currentRouterBase = '/';
29
- const handleWatch = (projectPath, devServer, env, templateType) => {
29
+ const handleWatch = (projectPath, devServer, env) => {
30
30
  const envPath = env === 'dev' ? '/.dev/' : '/.prod/';
31
31
  const configFilesWatcher = chokidar_1.default
32
32
  .watch([path_1.default.join(projectPath, '/config/*.ts'), path_1.default.join(projectPath, '/.eslint.config.mjs')], {
@@ -69,7 +69,7 @@ const handleWatch = (projectPath, devServer, env, templateType) => {
69
69
  yield (0, main_config_1.updateIndexFileText)(envPath, replaceIndexText);
70
70
  break;
71
71
  case filePath === loadingFilePath:
72
- replaceIndexText = yield (0, main_config_1.handleLoadingFile)(projectPath, templateType, replaceIndexText);
72
+ replaceIndexText = yield (0, main_config_1.handleLoadingFile)(projectPath, replaceIndexText);
73
73
  yield (0, main_config_1.updateIndexFileText)(envPath, replaceIndexText);
74
74
  }
75
75
  }
@@ -79,7 +79,7 @@ const restartServer = () => {
79
79
  const result = cross_spawn_1.default.sync('cross-env', [
80
80
  'SWICO_DEV_RESTART=true',
81
81
  `SWICO_DEV_PORT=${currentPort}`,
82
- `SWICO_DEV_ROUTER_BASE =${currentRouterBase}`,
82
+ `SWICO_DEV_ROUTER_BASE=${currentRouterBase}`,
83
83
  'swico',
84
84
  'start'
85
85
  ], {
@@ -156,7 +156,7 @@ function start() {
156
156
  process.env.SWICO_DEV_PORT = availablePort.toString();
157
157
  createCompileListener(compiler);
158
158
  compiler.getInfrastructureLogger = oriLogger;
159
- handleWatch(projectPath, devServer, env, templateType);
159
+ handleWatch(projectPath, devServer, env);
160
160
  if (SWICO_DEV_RESTART !== 'true' ||
161
161
  (SWICO_DEV_RESTART === 'true' && newRouterBase !== SWICO_DEV_ROUTER_BASE)) {
162
162
  utils_1.toast.info(`Project is running at:${chalk_1.default.hex('#29abe0')(`${startConfig.devServer.server}://localhost:${availablePort}${newRouterBase}`)}`);
@@ -2,11 +2,11 @@ import { GlobalData, GlobalSwicoConfigType } from './main-config';
2
2
  import { App } from 'vue';
3
3
  import { Router } from 'vue-router';
4
4
  export type CustomConfigType = GlobalData['customConfig'];
5
- export { RouterView as Outlet } from 'vue-router';
5
+ export { RouterView } from 'vue-router';
6
6
  export { useLocation, useNav } from './project-path/.swico-vue/hooks';
7
7
  export { history } from './mock-history';
8
8
  export type { GlobalSwicoConfigType };
9
- export { default as Link } from './project-path/.swico-vue/Link';
9
+ export declare const Outlet: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
10
10
  export interface DefineSwicoConfigType {
11
11
  (env: 'base', config: CustomConfigType['base']): any;
12
12
  (env: 'dev', config: CustomConfigType['dev']): any;
package/src/index.vue.js CHANGED
@@ -1,18 +1,18 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.defineGlobal = exports.defineConfig = exports.Link = exports.history = exports.useNav = exports.useLocation = exports.Outlet = void 0;
3
+ exports.defineGlobal = exports.defineConfig = exports.Outlet = exports.history = exports.useNav = exports.useLocation = exports.RouterView = void 0;
4
+ const vue_1 = require("vue");
7
5
  var vue_router_1 = require("vue-router");
8
- Object.defineProperty(exports, "Outlet", { enumerable: true, get: function () { return vue_router_1.RouterView; } });
6
+ Object.defineProperty(exports, "RouterView", { enumerable: true, get: function () { return vue_router_1.RouterView; } });
9
7
  var hooks_1 = require("./project-path/.swico-vue/hooks");
10
8
  Object.defineProperty(exports, "useLocation", { enumerable: true, get: function () { return hooks_1.useLocation; } });
11
9
  Object.defineProperty(exports, "useNav", { enumerable: true, get: function () { return hooks_1.useNav; } });
12
10
  var mock_history_1 = require("./mock-history");
13
11
  Object.defineProperty(exports, "history", { enumerable: true, get: function () { return mock_history_1.history; } });
14
- var Link_1 = require("./project-path/.swico-vue/Link");
15
- Object.defineProperty(exports, "Link", { enumerable: true, get: function () { return __importDefault(Link_1).default; } });
12
+ exports.Outlet = (0, vue_1.defineComponent)({
13
+ name: 'Outlet',
14
+ template: '<RouterView v-slot="{ Component }"><template v-if="Component"><Suspense><component :is="Component"></component><template #fallback></template></Suspense></template></RouterView>'
15
+ });
16
16
  const defineConfig = (env, config) => config;
17
17
  exports.defineConfig = defineConfig;
18
18
  const defineGlobal = (config) => config;
@@ -44,7 +44,7 @@ export interface GlobalData {
44
44
  };
45
45
  }
46
46
  export declare const getProjectConfig: (env: GlobalData['env']) => Promise<GlobalData>;
47
- export declare const handleLoadingFile: (projectPath: any, templateType: GlobalData["templateType"], replaceIndexText: any) => Promise<any>;
47
+ export declare const handleLoadingFile: (projectPath: any, replaceIndexText: any) => Promise<any>;
48
48
  export declare const handleGlobalStyleFile: (replaceIndexText: any) => any;
49
49
  export declare const updateIndexFileText: (envPath: any, newFileText: any) => Promise<void>;
50
50
  export declare const getFormatDefineVars: (defineVarsConfigData: any) => Promise<{}>;
@@ -50,6 +50,29 @@ const fs_extra_1 = __importDefault(require("fs-extra"));
50
50
  const path_1 = __importDefault(require("path"));
51
51
  const chalk_1 = __importDefault(require("chalk"));
52
52
  const utils_1 = require("../utils");
53
+ const getFormatRouter = (projectPath, routes, templateType) => {
54
+ const _main = (item) => {
55
+ const { component, name, children, redirect, decorator } = item;
56
+ return decorator
57
+ ? Object.assign(Object.assign({}, item), { component: `()=>import('${projectPath}/src/pages/${decorator}${templateType === 'vue' ? '.vue' : ''}')`, children: [
58
+ {
59
+ path: '',
60
+ component: component
61
+ ? `()=>import('${projectPath}/src/pages/${component}${templateType === 'vue' ? '.vue' : ''}')`
62
+ : undefined,
63
+ name,
64
+ redirect,
65
+ children: children ? children === null || children === void 0 ? void 0 : children.map((item) => _main(item)) : undefined
66
+ }
67
+ ] }) : Object.assign(Object.assign({}, item), { component: component
68
+ ? `()=>import('${projectPath}/src/pages/${component}${templateType === 'vue' ? '.vue' : ''}')`
69
+ : undefined, name,
70
+ redirect, children: children ? children === null || children === void 0 ? void 0 : children.map((item) => _main(item)) : undefined });
71
+ };
72
+ return routes.map((item) => {
73
+ return _main(item);
74
+ });
75
+ };
53
76
  const getProjectConfig = (env) => __awaiter(void 0, void 0, void 0, function* () {
54
77
  var _a, _b;
55
78
  const projectPath = process.cwd();
@@ -152,7 +175,7 @@ const formatRouterConfig = ({ routes = [], type = 'browser', base = '/' }, templ
152
175
  const projectPath = process.cwd();
153
176
  const envPath = env === 'dev' ? '/.dev/' : '/.prod/';
154
177
  return new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
155
- const formatRouter = (0, utils_1.getFormatRouter)(projectPath, routes, templateType);
178
+ const formatRouter = getFormatRouter(projectPath, routes, templateType);
156
179
  const textData = `"use strict";
157
180
  Object.defineProperty(exports, "__esModule", { value: true });
158
181
  exports.default = ${JSON.stringify(formatRouter)};`;
@@ -198,14 +221,14 @@ const getGlobalStyleFilePath = () => {
198
221
  }
199
222
  return { filePath, fileType };
200
223
  };
201
- const handleLoadingFile = (projectPath, templateType, replaceIndexText) => __awaiter(void 0, void 0, void 0, function* () {
224
+ const handleLoadingFile = (projectPath, replaceIndexText) => __awaiter(void 0, void 0, void 0, function* () {
202
225
  let newReplaceIndexText = replaceIndexText;
203
226
  try {
204
- yield fs_extra_1.default.access(path_1.default.resolve(projectPath, `./src/loading/${templateType === 'react' ? 'index.tsx' : 'Loading.vue'}`), fs_extra_1.default.constants.F_OK);
205
- newReplaceIndexText = newReplaceIndexText.replace('"../loading"', `"../../src/${templateType === 'react' ? 'loading' : 'loading/Loading'}"`);
227
+ yield fs_extra_1.default.access(path_1.default.resolve(projectPath, './src/loading/index.tsx'), fs_extra_1.default.constants.F_OK);
228
+ newReplaceIndexText = newReplaceIndexText.replace('"../loading"', '"../../src/loading"');
206
229
  }
207
230
  catch (e) {
208
- newReplaceIndexText = newReplaceIndexText.replace(`"../../src/${templateType === 'react' ? 'loading' : 'loading/Loading'}"`, '"../loading"');
231
+ newReplaceIndexText = newReplaceIndexText.replace('"../../src/loading', '"../loading"');
209
232
  }
210
233
  return newReplaceIndexText;
211
234
  });
@@ -244,8 +267,10 @@ const initTemplateConfig = (routerConfig, templateType, env) => {
244
267
  yield fs_extra_1.default.writeFile(hooksFilePath, replaceHooksText);
245
268
  let replaceIndexText = yield fs_extra_1.default.readFile(path_1.default.resolve(projectPath, `./.swico${envPath}index.js`), 'utf8');
246
269
  replaceIndexText = (0, exports.handleGlobalStyleFile)(replaceIndexText);
247
- const newReplaceIndexText = yield (0, exports.handleLoadingFile)(projectPath, templateType, replaceIndexText);
248
- yield (0, exports.updateIndexFileText)(envPath, newReplaceIndexText);
270
+ if (templateType === 'react') {
271
+ replaceIndexText = yield (0, exports.handleLoadingFile)(projectPath, replaceIndexText);
272
+ }
273
+ yield (0, exports.updateIndexFileText)(envPath, replaceIndexText);
249
274
  resolve(null);
250
275
  }));
251
276
  };
@@ -7,7 +7,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
7
7
  const vue_1 = require("vue");
8
8
  const Layout_1 = __importDefault(require("../../src/layout/Layout"));
9
9
  const global_1 = __importDefault(require("../../src/global"));
10
- const loading_1 = __importDefault(require("../loading"));
11
10
  const history_1 = require("./history");
12
11
  const Container = (0, vue_1.defineComponent)({
13
12
  name: 'Container',
@@ -19,21 +18,11 @@ const Container = (0, vue_1.defineComponent)({
19
18
  });
20
19
  return { error };
21
20
  },
22
- template: ' <Layout v-if="!error">\n' +
23
- ' <Suspense>\n' +
24
- ' <template #default>\n' +
25
- ' <RouterView />\n' +
26
- ' </template>\n' +
27
- ' <template #fallback>\n' +
28
- ' <Loading />\n' +
29
- ' </template>\n' +
30
- ' </Suspense>\n' +
31
- ' </Layout>'
21
+ template: '<SwicoLayout v-if="!error"></SwicoLayout>'
32
22
  });
33
23
  const router = (0, history_1.getRouter)();
34
24
  const app = (0, vue_1.createApp)(Container);
35
- app.component('Layout', Layout_1.default);
36
- app.component('Loading', loading_1.default);
25
+ app.component('SwicoLayout', Layout_1.default);
37
26
  app.use(router);
38
27
  (_a = global_1.default === null || global_1.default === void 0 ? void 0 : global_1.default.onInit) === null || _a === void 0 ? void 0 : _a.call(global_1.default, app, router);
39
28
  app.mount('#root');
@@ -16,6 +16,7 @@ exports.default = default_1;
16
16
  const path_1 = __importDefault(require("path"));
17
17
  const main_config_1 = require("../main-config");
18
18
  const core_1 = require("@rspack/core");
19
+ const html_webpack_plugin_1 = __importDefault(require("html-webpack-plugin"));
19
20
  const lessLoader = require.resolve('less-loader');
20
21
  const sassLoader = require.resolve('sass-loader');
21
22
  const postcssLoader = require.resolve('postcss-loader');
@@ -35,6 +36,12 @@ function default_1(_a) {
35
36
  };
36
37
  const publicPath = (_b = customBaseConfig === null || customBaseConfig === void 0 ? void 0 : customBaseConfig.publicPath) !== null && _b !== void 0 ? _b : main_config_1.initConfig.publicPath;
37
38
  const routerBase = (_d = (_c = customBaseConfig === null || customBaseConfig === void 0 ? void 0 : customBaseConfig.router) === null || _c === void 0 ? void 0 : _c.base) !== null && _d !== void 0 ? _d : main_config_1.initConfig.router.base;
39
+ const initialDefineVarsConfig = {
40
+ SWICO_ENV: JSON.stringify(env),
41
+ SWICO_ROUTER_BASE: JSON.stringify(routerBase),
42
+ SWICO_PUBLIC_PATH: JSON.stringify(publicPath)
43
+ };
44
+ const customDefineVarsConfig = yield (0, main_config_1.getFormatDefineVars)((_e = customBaseConfig === null || customBaseConfig === void 0 ? void 0 : customBaseConfig.define) !== null && _e !== void 0 ? _e : {});
38
45
  return {
39
46
  entry: entryPath,
40
47
  output: {
@@ -143,18 +150,14 @@ function default_1(_a) {
143
150
  },
144
151
  externals: customConfig.base.externals,
145
152
  plugins: [
146
- new core_1.rspack.HtmlRspackPlugin({
153
+ new html_webpack_plugin_1.default({
147
154
  template: path_1.default.join(projectPath, '/src/index.ejs'),
148
155
  filename: 'index.html',
149
156
  minify: true,
150
- templateParameters: {
151
- SWICO_ENV: env,
152
- SWICO_ROUTER_BASE: routerBase,
153
- SWICO_PUBLIC_PATH: publicPath
154
- },
157
+ templateParameters: initialDefineVarsConfig,
155
158
  hash: true
156
159
  }),
157
- new core_1.rspack.DefinePlugin(Object.assign({ SWICO_ENV: env, SWICO_ROUTER_BASE: routerBase, SWICO_PUBLIC_PATH: publicPath }, (0, main_config_1.getFormatDefineVars)((_e = customConfig.base.define) !== null && _e !== void 0 ? _e : {}))),
160
+ new core_1.rspack.DefinePlugin(Object.assign(Object.assign({}, initialDefineVarsConfig), customDefineVarsConfig)),
158
161
  ...((_f = customBaseConfig === null || customBaseConfig === void 0 ? void 0 : customBaseConfig.plugins) !== null && _f !== void 0 ? _f : main_config_1.initConfig.plugins)
159
162
  ]
160
163
  };
@@ -17,6 +17,7 @@ const path_1 = __importDefault(require("path"));
17
17
  const main_config_1 = require("../main-config");
18
18
  const vue_loader_1 = require("vue-loader");
19
19
  const core_1 = require("@rspack/core");
20
+ const html_webpack_plugin_1 = __importDefault(require("html-webpack-plugin"));
20
21
  const vueStyleLoader = require.resolve('vue-style-loader');
21
22
  const cssLoader = require.resolve('css-loader');
22
23
  const lessLoader = require.resolve('less-loader');
@@ -38,6 +39,12 @@ function default_1(_a) {
38
39
  };
39
40
  const publicPath = (_b = customBaseConfig === null || customBaseConfig === void 0 ? void 0 : customBaseConfig.publicPath) !== null && _b !== void 0 ? _b : main_config_1.initConfig.publicPath;
40
41
  const routerBase = (_d = (_c = customBaseConfig === null || customBaseConfig === void 0 ? void 0 : customBaseConfig.router) === null || _c === void 0 ? void 0 : _c.base) !== null && _d !== void 0 ? _d : main_config_1.initConfig.router.base;
42
+ const initialDefineVarsConfig = {
43
+ SWICO_ENV: JSON.stringify(env),
44
+ SWICO_ROUTER_BASE: JSON.stringify(routerBase),
45
+ SWICO_PUBLIC_PATH: JSON.stringify(publicPath)
46
+ };
47
+ const customDefineVarsConfig = yield (0, main_config_1.getFormatDefineVars)((_e = customBaseConfig === null || customBaseConfig === void 0 ? void 0 : customBaseConfig.define) !== null && _e !== void 0 ? _e : {});
41
48
  return {
42
49
  entry: entryPath,
43
50
  output: {
@@ -256,16 +263,12 @@ function default_1(_a) {
256
263
  ignoreOrder: true
257
264
  }),
258
265
  new vue_loader_1.VueLoaderPlugin(),
259
- new core_1.DefinePlugin(Object.assign({ __VUE_OPTIONS_API__: true, __VUE_PROD_DEVTOOLS__: false, __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: false, SWICO_ENV: env, SWICO_ROUTER_BASE: routerBase, SWICO_PUBLIC_PATH: publicPath }, (0, main_config_1.getFormatDefineVars)((_e = customConfig.base.define) !== null && _e !== void 0 ? _e : {}))),
260
- new core_1.HtmlRspackPlugin({
266
+ new core_1.DefinePlugin(Object.assign(Object.assign({ __VUE_OPTIONS_API__: true, __VUE_PROD_DEVTOOLS__: false, __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: false }, initialDefineVarsConfig), customDefineVarsConfig)),
267
+ new html_webpack_plugin_1.default({
261
268
  template: path_1.default.join(projectPath, '/src/index.ejs'),
262
269
  filename: 'index.html',
263
270
  minify: true,
264
- templateParameters: {
265
- SWICO_ENV: env,
266
- SWICO_ROUTER_BASE: routerBase,
267
- SWICO_PUBLIC_PATH: publicPath
268
- },
271
+ templateParameters: initialDefineVarsConfig,
269
272
  hash: true
270
273
  }),
271
274
  ...((_f = customBaseConfig === null || customBaseConfig === void 0 ? void 0 : customBaseConfig.plugins) !== null && _f !== void 0 ? _f : main_config_1.initConfig.plugins)
package/src/utils.d.ts CHANGED
@@ -1,6 +1,4 @@
1
- import { ConfigRouterType } from './main-config';
2
1
  export declare const copyDirFiles: (src: any, dest: any, filter?: (fileName: any) => boolean) => Promise<void>;
3
- export declare const getFormatRouter: (projectPath: string, routes: ConfigRouterType["routes"], templateType: any) => any[];
4
2
  export declare const getPort: () => Promise<number>;
5
3
  export declare const colorConfig: {
6
4
  theme: string;
package/src/utils.js CHANGED
@@ -19,7 +19,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
19
19
  return (mod && mod.__esModule) ? mod : { "default": mod };
20
20
  };
21
21
  Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.toast = exports.colorConfig = exports.getPort = exports.getFormatRouter = exports.copyDirFiles = void 0;
22
+ exports.toast = exports.colorConfig = exports.getPort = exports.copyDirFiles = void 0;
23
23
  const portfinder_1 = __importDefault(require("portfinder"));
24
24
  const fs_extra_1 = __importDefault(require("fs-extra"));
25
25
  const path_1 = __importDefault(require("path"));
@@ -63,30 +63,6 @@ const copyDirFiles = (src, dest, filter) => __awaiter(void 0, void 0, void 0, fu
63
63
  yield _copy(src, dest);
64
64
  });
65
65
  exports.copyDirFiles = copyDirFiles;
66
- const getFormatRouter = (projectPath, routes, templateType) => {
67
- const _main = (item) => {
68
- const { component, name, children, redirect, decorator } = item;
69
- return decorator
70
- ? Object.assign(Object.assign({}, item), { component: `()=>import('${projectPath}/src/pages/${decorator}${templateType === 'vue' ? '.vue' : ''}')`, children: [
71
- {
72
- path: '',
73
- component: component
74
- ? `()=>import('${projectPath}/src/pages/${component}${templateType === 'vue' ? '.vue' : ''}')`
75
- : undefined,
76
- name,
77
- redirect,
78
- children: children ? children === null || children === void 0 ? void 0 : children.map((item) => _main(item)) : undefined
79
- }
80
- ] }) : Object.assign(Object.assign({}, item), { component: component
81
- ? `()=>import('${projectPath}/src/pages/${component}${templateType === 'vue' ? '.vue' : ''}')`
82
- : undefined, name,
83
- redirect, children: children ? children === null || children === void 0 ? void 0 : children.map((item) => _main(item)) : undefined });
84
- };
85
- return routes.map((item) => {
86
- return _main(item);
87
- });
88
- };
89
- exports.getFormatRouter = getFormatRouter;
90
66
  const getPort = () => {
91
67
  return portfinder_1.default.getPortPromise({
92
68
  port: 3000,
@@ -1,2 +0,0 @@
1
- declare const _default: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
2
- export default _default;
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const vue_1 = require("vue");
4
- exports.default = (0, vue_1.defineComponent)({
5
- name: 'Loading',
6
- template: ''
7
- });