swico 2.5.0-beta.5 → 2.6.0-beta.1

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.5.0-beta.5",
3
+ "version": "2.6.0-beta.1",
4
4
  "description": "Simple, efficient, and practical front-end framework",
5
5
  "main": "./src/index.js",
6
6
  "types": "./src/index.d.ts",
@@ -13,17 +13,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.default = default_1;
16
- const rspack_prod_1 = __importDefault(require("../config/rspack.prod"));
17
- const config_1 = require("../utils/config");
18
- const tools_1 = require("../utils/tools");
16
+ const rspack_prod_1 = __importDefault(require("../rspack-config/rspack.prod"));
17
+ const main_config_1 = require("../main-config");
18
+ const utils_1 = require("../utils");
19
19
  const package_json_1 = __importDefault(require("../../package.json"));
20
20
  const core_1 = require("@rspack/core");
21
21
  function default_1() {
22
22
  return __awaiter(this, void 0, void 0, function* () {
23
23
  process.env.SWICO_ENV = 'prod';
24
- tools_1.toast.info(`Swico v${package_json_1.default.version}`);
25
- tools_1.toast.info('Initializing production config...');
26
- const projectConfig = yield (0, config_1.getProjectConfig)('prod');
24
+ utils_1.toast.info(`Swico v${package_json_1.default.version}`);
25
+ utils_1.toast.info('Initializing production config...');
26
+ const projectConfig = yield (0, main_config_1.getProjectConfig)('prod');
27
27
  const { entryPath, templatePath, projectPath, customConfig, templateType } = projectConfig;
28
28
  const buildConfig = yield (0, rspack_prod_1.default)({
29
29
  entryPath,
@@ -33,24 +33,24 @@ function default_1() {
33
33
  templateType
34
34
  });
35
35
  const compiler = (0, core_1.rspack)(buildConfig);
36
- tools_1.toast.info('Building...');
36
+ utils_1.toast.info('Building...');
37
37
  const now = Date.now();
38
38
  compiler.run((err, stats) => {
39
39
  if (err) {
40
- tools_1.toast.error(err.stack || err.toString());
40
+ utils_1.toast.error(err.stack || err.toString());
41
41
  return;
42
42
  }
43
43
  if (stats.hasErrors()) {
44
44
  const info = stats.toJson();
45
- tools_1.toast.error(info.errors.map((item) => item.stack || item.message));
45
+ utils_1.toast.error(info.errors.map((item) => item.stack || item.message));
46
46
  return;
47
47
  }
48
48
  if (stats.hasWarnings()) {
49
49
  const info = stats.toJson();
50
- tools_1.toast.warning(info.warnings.map((item) => item.stack || item.message));
50
+ utils_1.toast.warning(info.warnings.map((item) => item.stack || item.message));
51
51
  }
52
52
  const duration = Date.now() - now;
53
- tools_1.toast.success(`Build complete in ${(duration / 1000).toFixed(2)}s`);
53
+ utils_1.toast.success(`Build complete in ${(duration / 1000).toFixed(2)}s`);
54
54
  });
55
55
  });
56
56
  }
@@ -13,20 +13,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.default = start;
16
- const rsbpack_dev_1 = __importDefault(require("../config/rsbpack.dev"));
17
- const tools_1 = require("../utils/tools");
18
- const config_1 = require("../utils/config");
16
+ const rsbpack_dev_1 = __importDefault(require("../rspack-config/rsbpack.dev"));
17
+ const utils_1 = require("../utils");
18
+ const main_config_1 = require("../main-config");
19
19
  const chokidar_1 = __importDefault(require("chokidar"));
20
20
  const cross_spawn_1 = __importDefault(require("cross-spawn"));
21
21
  const path_1 = __importDefault(require("path"));
22
- const { SWICO_PORT, SWICO_RESTART, SWICO_ROUTER_BASE } = process.env;
22
+ const { SWICO_DEV_PORT, SWICO_DEV_RESTART, SWICO_DEV_ROUTER_BASE } = process.env;
23
23
  const package_json_1 = __importDefault(require("../../package.json"));
24
24
  const chalk_1 = __importDefault(require("chalk"));
25
25
  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) => {
29
+ const handleWatch = (projectPath, devServer, env, templateType) => {
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')], {
@@ -36,7 +36,7 @@ const handleWatch = (projectPath, devServer, env) => {
36
36
  ignored: [path_1.default.join(projectPath, '/config/swico.prod.ts')]
37
37
  })
38
38
  .on('all', (path, stats) => __awaiter(void 0, void 0, void 0, function* () {
39
- tools_1.toast.warning('Configuration files changed, restarting server...', {
39
+ utils_1.toast.warning('Configuration files changed, restarting server...', {
40
40
  inline: true
41
41
  });
42
42
  yield devServer.stop();
@@ -65,28 +65,28 @@ const handleWatch = (projectPath, devServer, env) => {
65
65
  restartServer();
66
66
  break;
67
67
  case globalStyleFilesPathList.includes(filePath):
68
- replaceIndexText = (0, config_1.handleGlobalStyleFile)(replaceIndexText);
69
- yield (0, config_1.updateIndexFileText)(envPath, replaceIndexText);
68
+ replaceIndexText = (0, main_config_1.handleGlobalStyleFile)(replaceIndexText);
69
+ yield (0, main_config_1.updateIndexFileText)(envPath, replaceIndexText);
70
70
  break;
71
71
  case filePath === loadingFilePath:
72
- replaceIndexText = yield (0, config_1.handleLoadingFile)(replaceIndexText, envPath);
73
- yield (0, config_1.updateIndexFileText)(envPath, replaceIndexText);
72
+ replaceIndexText = yield (0, main_config_1.handleLoadingFile)(projectPath, templateType, replaceIndexText);
73
+ yield (0, main_config_1.updateIndexFileText)(envPath, replaceIndexText);
74
74
  }
75
75
  }
76
76
  }));
77
77
  };
78
78
  const restartServer = () => {
79
79
  const result = cross_spawn_1.default.sync('cross-env', [
80
- 'SWICO_RESTART=true',
81
- `SWICO_PORT=${currentPort}`,
82
- `SWICO_ROUTER_BASE=${currentRouterBase}`,
80
+ 'SWICO_DEV_RESTART=true',
81
+ `SWICO_DEV_PORT=${currentPort}`,
82
+ `SWICO_DEV_ROUTER_BASE =${currentRouterBase}`,
83
83
  'swico',
84
84
  'start'
85
85
  ], {
86
86
  stdio: 'inherit'
87
87
  });
88
88
  if (result.error) {
89
- tools_1.toast.error(result.error.message);
89
+ utils_1.toast.error(result.error.message);
90
90
  process.exit(1);
91
91
  }
92
92
  };
@@ -110,12 +110,12 @@ const createCompileListener = (compiler) => {
110
110
  let now = Date.now();
111
111
  compiler.hooks.beforeCompile.tap('beforeCompile', () => {
112
112
  now = Date.now();
113
- tools_1.toast.info('Compiling...');
113
+ utils_1.toast.info('Compiling...');
114
114
  });
115
115
  compiler.hooks.done.tap('done', (stats) => {
116
116
  if (stats === null || stats === void 0 ? void 0 : stats.hasErrors()) {
117
117
  const info = stats === null || stats === void 0 ? void 0 : stats.toJson();
118
- tools_1.toast.error(info === null || info === void 0 ? void 0 : info.errors.map((item) => item.message || item.stack).filter((item1) => !filterStyleFileList.find((item2) => item1.includes(item2))));
118
+ utils_1.toast.error(info === null || info === void 0 ? void 0 : info.errors.map((item) => item.message || item.stack).filter((item1) => !filterStyleFileList.find((item2) => item1.includes(item2))));
119
119
  return;
120
120
  }
121
121
  if (stats === null || stats === void 0 ? void 0 : stats.hasWarnings()) {
@@ -124,27 +124,27 @@ const createCompileListener = (compiler) => {
124
124
  warnings.some((item) => {
125
125
  const msg = item.message || item.stack;
126
126
  if (msg.includes('[eslint]')) {
127
- tools_1.toast.warning(msg, { title: 'ESLint errors' });
127
+ utils_1.toast.warning(msg, { title: 'ESLint errors' });
128
128
  return;
129
129
  }
130
130
  });
131
131
  }
132
132
  const duration = Date.now() - now;
133
- tools_1.toast.info(`Compiled ${duration ? `in ${(duration / 1000).toFixed(2)}s` : ''}`);
133
+ utils_1.toast.info(`Compiled ${duration ? `in ${(duration / 1000).toFixed(2)}s` : ''}`);
134
134
  });
135
135
  };
136
136
  function start() {
137
137
  return __awaiter(this, void 0, void 0, function* () {
138
138
  var _a, _b, _c, _d, _e, _f;
139
139
  process.env.SWICO_ENV = 'dev';
140
- if (SWICO_RESTART !== 'true') {
140
+ if (SWICO_DEV_RESTART !== 'true') {
141
141
  console.log('\n');
142
- tools_1.toast.info(`Swico v${package_json_1.default.version}`);
143
- tools_1.toast.info('Initializing development config...');
142
+ utils_1.toast.info(`Swico v${package_json_1.default.version}`);
143
+ utils_1.toast.info('Initializing development config...');
144
144
  }
145
- const availablePort = SWICO_RESTART === 'true' ? Number(SWICO_PORT) : yield (0, tools_1.getPort)();
146
- const projectConfig = yield (0, config_1.getProjectConfig)('dev');
147
- const { projectPath, customConfig, env } = projectConfig;
145
+ const availablePort = SWICO_DEV_RESTART === 'true' ? Number(SWICO_DEV_PORT) : yield (0, utils_1.getPort)();
146
+ const projectConfig = yield (0, main_config_1.getProjectConfig)('dev');
147
+ const { projectPath, customConfig, env, templateType } = projectConfig;
148
148
  const newRouterBase = (_f = (_c = (_b = (_a = customConfig['dev']) === null || _a === void 0 ? void 0 : _a.router) === null || _b === void 0 ? void 0 : _b.base) !== null && _c !== void 0 ? _c : (_e = (_d = customConfig['base']) === null || _d === void 0 ? void 0 : _d.router) === null || _e === void 0 ? void 0 : _e.base) !== null && _f !== void 0 ? _f : '/';
149
149
  const startConfig = yield (0, rsbpack_dev_1.default)(projectConfig);
150
150
  const compiler = (0, core_1.rspack)(startConfig);
@@ -153,13 +153,13 @@ function start() {
153
153
  const devServer = new dev_server_1.RspackDevServer(Object.assign(Object.assign({}, startConfig.devServer), { port: availablePort }), compiler);
154
154
  try {
155
155
  yield devServer.start();
156
- process.env.SWICO_PORT = availablePort.toString();
156
+ process.env.SWICO_DEV_PORT = availablePort.toString();
157
157
  createCompileListener(compiler);
158
158
  compiler.getInfrastructureLogger = oriLogger;
159
- handleWatch(projectPath, devServer, env);
160
- if (SWICO_RESTART !== 'true' ||
161
- (SWICO_RESTART === 'true' && newRouterBase !== SWICO_ROUTER_BASE)) {
162
- tools_1.toast.info(`Project is running at:${chalk_1.default.hex('#29abe0')(`${startConfig.devServer.server}://localhost:${availablePort}${newRouterBase}`)}`);
159
+ handleWatch(projectPath, devServer, env, templateType);
160
+ if (SWICO_DEV_RESTART !== 'true' ||
161
+ (SWICO_DEV_RESTART === 'true' && newRouterBase !== SWICO_DEV_ROUTER_BASE)) {
162
+ utils_1.toast.info(`Project is running at:${chalk_1.default.hex('#29abe0')(`${startConfig.devServer.server}://localhost:${availablePort}${newRouterBase}`)}`);
163
163
  }
164
164
  currentRouterBase = newRouterBase;
165
165
  currentPort = availablePort;
@@ -167,7 +167,7 @@ function start() {
167
167
  catch (e) {
168
168
  const strErr = e.toString();
169
169
  if (!filterStyleFileList.find((item) => strErr.includes(item))) {
170
- tools_1.toast.error(strErr);
170
+ utils_1.toast.error(strErr);
171
171
  }
172
172
  }
173
173
  });
package/src/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { GlobalData, GlobalSwicoConfigType } from './utils/config';
1
+ import { GlobalData, GlobalSwicoConfigType } from './main-config';
2
2
  import { UseLocationType, UseNavType } from './typings/global-type';
3
3
  export type CustomConfigType = GlobalData['customConfig'];
4
4
  export type { GlobalSwicoConfigType };
@@ -1,4 +1,4 @@
1
- import { GlobalData, GlobalSwicoConfigType } from './utils/config';
1
+ import { GlobalData, GlobalSwicoConfigType } from './main-config';
2
2
  export type CustomConfigType = GlobalData['customConfig'];
3
3
  export type { GlobalSwicoConfigType };
4
4
  export { default as Link } from './project-path/.swico-react/Link';
@@ -1,4 +1,4 @@
1
- import { GlobalData, GlobalSwicoConfigType } from './utils/config';
1
+ 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'];
@@ -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: (replaceIndexText: any, envPath: any) => Promise<any>;
47
+ export declare const handleLoadingFile: (projectPath: any, templateType: GlobalData["templateType"], 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<{}>;
@@ -49,7 +49,7 @@ exports.initConfig = exports.getFormatDefineVars = exports.updateIndexFileText =
49
49
  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
- const tools_1 = require("./tools");
52
+ const utils_1 = require("../utils");
53
53
  const getProjectConfig = (env) => __awaiter(void 0, void 0, void 0, function* () {
54
54
  var _a, _b;
55
55
  const projectPath = process.cwd();
@@ -96,19 +96,19 @@ const getProjectConfig = (env) => __awaiter(void 0, void 0, void 0, function* ()
96
96
  supportedFieldList = ['plugins', 'console', 'copy', 'devtool', 'router'];
97
97
  configFileName = 'swico.prod.ts';
98
98
  }
99
- const toastTitle = `Swico config file => ${chalk_1.default.hex(tools_1.colorConfig.theme)(configFileName)}`;
99
+ const toastTitle = `Swico config file => ${chalk_1.default.hex(utils_1.colorConfig.theme)(configFileName)}`;
100
100
  const unSupportedField = configFields.find((field) => !supportedFieldList.includes(field));
101
101
  if (configFields.length > 0 && unSupportedField) {
102
102
  const msgText = `The Swico configuration file '${chalk_1.default.blue(configFileName)}' does not support the field '${chalk_1.default.red(unSupportedField)}' `;
103
- tools_1.toast.error(msgText);
103
+ utils_1.toast.error(msgText);
104
104
  process.exit(1);
105
105
  }
106
106
  if (key === 'base' && !['vue', 'react'].includes(configObj['template'])) {
107
- tools_1.toast.error(`The field '${chalk_1.default.blue('template')}' does not support the value '${chalk_1.default.red(configObj['template'])}',the value should be 'vue' or 'react' `, { title: toastTitle });
107
+ utils_1.toast.error(`The field '${chalk_1.default.blue('template')}' does not support the value '${chalk_1.default.red(configObj['template'])}',the value should be 'vue' or 'react' `, { title: toastTitle });
108
108
  process.exit(1);
109
109
  }
110
110
  if (!['hash', 'browser'].includes((_b = (_a = configObj['router']) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : exports.initConfig.router.type)) {
111
- tools_1.toast.error(`The field '${chalk_1.default.blue('router.type')}' does not support the value '${chalk_1.default.red(configObj['router'].type)}',the value should be 'browser' or 'hash' `, { title: toastTitle });
111
+ utils_1.toast.error(`The field '${chalk_1.default.blue('router.type')}' does not support the value '${chalk_1.default.red(configObj['router'].type)}',the value should be 'browser' or 'hash' `, { title: toastTitle });
112
112
  process.exit(1);
113
113
  }
114
114
  customConfig[key] = (yield Promise.resolve(`${curConfigFilePath}`).then(s => __importStar(require(s)))).default;
@@ -152,7 +152,7 @@ const formatRouterConfig = ({ routes = [], type = 'browser', base = '/' }, templ
152
152
  const projectPath = process.cwd();
153
153
  const envPath = env === 'dev' ? '/.dev/' : '/.prod/';
154
154
  return new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
155
- const formatRouter = (0, tools_1.getFormatRouter)(projectPath, routes, templateType);
155
+ const formatRouter = (0, utils_1.getFormatRouter)(projectPath, routes, templateType);
156
156
  const textData = `"use strict";
157
157
  Object.defineProperty(exports, "__esModule", { value: true });
158
158
  exports.default = ${JSON.stringify(formatRouter)};`;
@@ -198,15 +198,14 @@ const getGlobalStyleFilePath = () => {
198
198
  }
199
199
  return { filePath, fileType };
200
200
  };
201
- const handleLoadingFile = (replaceIndexText, envPath) => __awaiter(void 0, void 0, void 0, function* () {
202
- const projectPath = process.cwd();
201
+ const handleLoadingFile = (projectPath, templateType, replaceIndexText) => __awaiter(void 0, void 0, void 0, function* () {
203
202
  let newReplaceIndexText = replaceIndexText;
204
203
  try {
205
- yield fs_extra_1.default.access(path_1.default.resolve(projectPath, './src/loading/index.tsx'), fs_extra_1.default.constants.F_OK);
206
- newReplaceIndexText = newReplaceIndexText.replace('"../loading"', '"../../src/loading"');
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'}"`);
207
206
  }
208
207
  catch (e) {
209
- newReplaceIndexText = newReplaceIndexText.replace('"../../src/loading"', '"../loading"');
208
+ newReplaceIndexText = newReplaceIndexText.replace(`"../../src/${templateType === 'react' ? 'loading' : 'loading/Loading'}"`, '"../loading"');
210
209
  }
211
210
  return newReplaceIndexText;
212
211
  });
@@ -234,8 +233,8 @@ const initTemplateConfig = (routerConfig, templateType, env) => {
234
233
  const envPath = env === 'dev' ? '/.dev/' : '/.prod/';
235
234
  return new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
236
235
  const copyTargetPath = path_1.default.resolve(projectPath, `./.swico${envPath}`);
237
- yield (0, tools_1.copyDirFiles)(path_1.default.resolve(__dirname, `../project-path/.swico-${templateType}/$env`), copyTargetPath, (fileName) => !fileName.endsWith('.d.ts') && !['hooks.js'].includes(fileName));
238
- yield (0, tools_1.copyDirFiles)(path_1.default.resolve(__dirname, `../project-path/.swico-${templateType}`), path_1.default.resolve(projectPath, './.swico'), (fileName) => ['hooks.js', 'Link.js', 'loading.js'].includes(fileName));
236
+ yield (0, utils_1.copyDirFiles)(path_1.default.resolve(__dirname, `../project-path/.swico-${templateType}/$env`), copyTargetPath, (fileName) => !fileName.endsWith('.d.ts') && !['hooks.js'].includes(fileName));
237
+ yield (0, utils_1.copyDirFiles)(path_1.default.resolve(__dirname, `../project-path/.swico-${templateType}`), path_1.default.resolve(projectPath, './.swico'), (fileName) => ['hooks.js', 'Link.js', 'loading.js'].includes(fileName));
239
238
  const entryFilePath = path_1.default.resolve(projectPath, './.swico/index.js');
240
239
  yield fs_extra_1.default.copyFile(path_1.default.resolve(__dirname, `../index.${templateType}.js`), entryFilePath);
241
240
  yield formatRouterConfig(routerConfig, templateType, env);
@@ -245,13 +244,8 @@ const initTemplateConfig = (routerConfig, templateType, env) => {
245
244
  yield fs_extra_1.default.writeFile(hooksFilePath, replaceHooksText);
246
245
  let replaceIndexText = yield fs_extra_1.default.readFile(path_1.default.resolve(projectPath, `./.swico${envPath}index.js`), 'utf8');
247
246
  replaceIndexText = (0, exports.handleGlobalStyleFile)(replaceIndexText);
248
- if (templateType === 'vue') {
249
- yield (0, exports.updateIndexFileText)(envPath, replaceIndexText);
250
- }
251
- else if (templateType === 'react') {
252
- const newReplaceIndexText = yield (0, exports.handleLoadingFile)(replaceIndexText, envPath);
253
- yield (0, exports.updateIndexFileText)(envPath, newReplaceIndexText);
254
- }
247
+ const newReplaceIndexText = yield (0, exports.handleLoadingFile)(projectPath, templateType, replaceIndexText);
248
+ yield (0, exports.updateIndexFileText)(envPath, newReplaceIndexText);
255
249
  resolve(null);
256
250
  }));
257
251
  };
@@ -1,3 +1,3 @@
1
- import { ConfigRouterType } from '../../../utils/config';
1
+ import { ConfigRouterType } from '../../../main-config';
2
2
  export declare const routerType: ConfigRouterType['type'];
3
3
  export declare const routerBase: ConfigRouterType['base'];
@@ -1,3 +1,3 @@
1
- import { ConfigRouterType } from '../../../utils/config';
1
+ import { ConfigRouterType } from '../../../main-config';
2
2
  export declare const routerType: ConfigRouterType['type'];
3
3
  export declare const routerBase: ConfigRouterType['base'];
@@ -5,13 +5,35 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  var _a;
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  const vue_1 = require("vue");
8
- const Container_1 = __importDefault(require("../Container"));
9
8
  const Layout_1 = __importDefault(require("../../src/layout/Layout"));
10
9
  const global_1 = __importDefault(require("../../src/global"));
10
+ const loading_1 = __importDefault(require("../loading"));
11
11
  const history_1 = require("./history");
12
+ const Container = (0, vue_1.defineComponent)({
13
+ name: 'Container',
14
+ setup(props) {
15
+ const error = (0, vue_1.ref)(null);
16
+ (0, vue_1.onErrorCaptured)((err) => {
17
+ error.value = err.toString();
18
+ return false;
19
+ });
20
+ return { error };
21
+ },
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>'
32
+ });
12
33
  const router = (0, history_1.getRouter)();
13
- const app = (0, vue_1.createApp)(Container_1.default);
34
+ const app = (0, vue_1.createApp)(Container);
14
35
  app.component('Layout', Layout_1.default);
36
+ app.component('Loading', loading_1.default);
15
37
  app.use(router);
16
38
  (_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);
17
39
  app.mount('#root');
@@ -0,0 +1,2 @@
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;
@@ -0,0 +1,7 @@
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
+ });
@@ -1,2 +1,2 @@
1
- import { GlobalData } from '../utils/config';
1
+ import { GlobalData } from '../main-config';
2
2
  export default function (options: GlobalData): Promise<any>;
@@ -46,12 +46,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
46
46
  };
47
47
  Object.defineProperty(exports, "__esModule", { value: true });
48
48
  exports.default = default_1;
49
- const config_1 = require("../utils/config");
49
+ const main_config_1 = require("../main-config");
50
50
  const path_1 = __importDefault(require("path"));
51
51
  const webpack_merge_1 = require("webpack-merge");
52
52
  const eslint_rspack_plugin_1 = __importDefault(require("eslint-rspack-plugin"));
53
53
  const ts_checker_rspack_plugin_1 = require("ts-checker-rspack-plugin");
54
- const tools_1 = require("../utils/tools");
54
+ const utils_1 = require("../utils");
55
55
  function default_1(options) {
56
56
  return __awaiter(this, void 0, void 0, function* () {
57
57
  var _a, _b, _c, _d, _e, _f, _g;
@@ -74,8 +74,8 @@ function default_1(options) {
74
74
  progress: false,
75
75
  overlay: false
76
76
  },
77
- headers: (_c = (_b = customConfig === null || customConfig === void 0 ? void 0 : customConfig.dev) === null || _b === void 0 ? void 0 : _b.responseHeaders) !== null && _c !== void 0 ? _c : config_1.initConfig.responseHeaders,
78
- proxy: (_e = (_d = customConfig === null || customConfig === void 0 ? void 0 : customConfig.dev) === null || _d === void 0 ? void 0 : _d.proxy) !== null && _e !== void 0 ? _e : config_1.initConfig.proxy,
77
+ headers: (_c = (_b = customConfig === null || customConfig === void 0 ? void 0 : customConfig.dev) === null || _b === void 0 ? void 0 : _b.responseHeaders) !== null && _c !== void 0 ? _c : main_config_1.initConfig.responseHeaders,
78
+ proxy: (_e = (_d = customConfig === null || customConfig === void 0 ? void 0 : customConfig.dev) === null || _d === void 0 ? void 0 : _d.proxy) !== null && _e !== void 0 ? _e : main_config_1.initConfig.proxy,
79
79
  compress: true,
80
80
  hot: true,
81
81
  open: false,
@@ -90,7 +90,7 @@ function default_1(options) {
90
90
  logger: {
91
91
  log: () => { },
92
92
  error: (message) => {
93
- tools_1.toast.error(message, { title: 'TypeScript errors' });
93
+ utils_1.toast.error(message, { title: 'TypeScript errors' });
94
94
  }
95
95
  },
96
96
  typescript: {
@@ -1,4 +1,4 @@
1
- import { GlobalData } from '../utils/config';
1
+ import { GlobalData } from '../main-config';
2
2
  export default function ({ projectPath, entryPath, env, customConfig }: GlobalData): Promise<{
3
3
  entry: string;
4
4
  output: {
@@ -14,14 +14,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.default = default_1;
16
16
  const path_1 = __importDefault(require("path"));
17
- const config_1 = require("../utils/config");
17
+ const main_config_1 = require("../main-config");
18
18
  const core_1 = require("@rspack/core");
19
19
  const lessLoader = require.resolve('less-loader');
20
20
  const sassLoader = require.resolve('sass-loader');
21
21
  const postcssLoader = require.resolve('postcss-loader');
22
22
  function default_1(_a) {
23
23
  return __awaiter(this, arguments, void 0, function* ({ projectPath, entryPath, env, customConfig }) {
24
- var _b, _c, _d, _e, _f, _g;
24
+ var _b, _c, _d, _e, _f;
25
25
  const customBaseConfig = customConfig.base;
26
26
  const getCustomAliasConfig = () => {
27
27
  const { alias } = customBaseConfig || {};
@@ -33,14 +33,8 @@ function default_1(_a) {
33
33
  }
34
34
  return custAliasConfig;
35
35
  };
36
- const publicPath = (_b = customBaseConfig === null || customBaseConfig === void 0 ? void 0 : customBaseConfig.publicPath) !== null && _b !== void 0 ? _b : config_1.initConfig.publicPath;
37
- 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 : config_1.initConfig.router.base;
38
- const basicPlugins = [];
39
- const defineConfigData = (_f = (_e = customConfig === null || customConfig === void 0 ? void 0 : customConfig.base) === null || _e === void 0 ? void 0 : _e.define) !== null && _f !== void 0 ? _f : {};
40
- const formatObj = yield (0, config_1.getFormatDefineVars)(defineConfigData);
41
- if (Object.keys(formatObj).length !== 0) {
42
- basicPlugins.push(new core_1.rspack.DefinePlugin(formatObj));
43
- }
36
+ const publicPath = (_b = customBaseConfig === null || customBaseConfig === void 0 ? void 0 : customBaseConfig.publicPath) !== null && _b !== void 0 ? _b : main_config_1.initConfig.publicPath;
37
+ 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;
44
38
  return {
45
39
  entry: entryPath,
46
40
  output: {
@@ -149,18 +143,19 @@ function default_1(_a) {
149
143
  },
150
144
  externals: customConfig.base.externals,
151
145
  plugins: [
152
- ...basicPlugins,
153
146
  new core_1.rspack.HtmlRspackPlugin({
154
147
  template: path_1.default.join(projectPath, '/src/index.ejs'),
155
148
  filename: 'index.html',
156
149
  minify: true,
157
150
  templateParameters: {
158
- publicPath,
159
- routerBase
151
+ SWICO_ENV: env,
152
+ SWICO_ROUTER_BASE: routerBase,
153
+ SWICO_PUBLIC_PATH: publicPath
160
154
  },
161
155
  hash: true
162
156
  }),
163
- ...((_g = customBaseConfig === null || customBaseConfig === void 0 ? void 0 : customBaseConfig.plugins) !== null && _g !== void 0 ? _g : config_1.initConfig.plugins)
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 : {}))),
158
+ ...((_f = customBaseConfig === null || customBaseConfig === void 0 ? void 0 : customBaseConfig.plugins) !== null && _f !== void 0 ? _f : main_config_1.initConfig.plugins)
164
159
  ]
165
160
  };
166
161
  });
@@ -1,4 +1,4 @@
1
- import { GlobalData } from '../utils/config';
1
+ import { GlobalData } from '../main-config';
2
2
  export default function ({ projectPath, entryPath, env, customConfig }: GlobalData): Promise<{
3
3
  entry: string;
4
4
  output: {
@@ -14,7 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.default = default_1;
16
16
  const path_1 = __importDefault(require("path"));
17
- const config_1 = require("../utils/config");
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
20
  const vueStyleLoader = require.resolve('vue-style-loader');
@@ -36,14 +36,8 @@ function default_1(_a) {
36
36
  }
37
37
  return custAliasConfig;
38
38
  };
39
- const publicPath = (_b = customBaseConfig === null || customBaseConfig === void 0 ? void 0 : customBaseConfig.publicPath) !== null && _b !== void 0 ? _b : config_1.initConfig.publicPath;
40
- 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 : config_1.initConfig.router.base;
41
- const basicPlugins = [];
42
- const defineConfigData = (_e = customBaseConfig === null || customBaseConfig === void 0 ? void 0 : customBaseConfig.define) !== null && _e !== void 0 ? _e : {};
43
- const formatObj = yield (0, config_1.getFormatDefineVars)(defineConfigData);
44
- if (Object.keys(formatObj).length !== 0) {
45
- basicPlugins.push(new core_1.DefinePlugin(formatObj));
46
- }
39
+ const publicPath = (_b = customBaseConfig === null || customBaseConfig === void 0 ? void 0 : customBaseConfig.publicPath) !== null && _b !== void 0 ? _b : main_config_1.initConfig.publicPath;
40
+ 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;
47
41
  return {
48
42
  entry: entryPath,
49
43
  output: {
@@ -257,28 +251,24 @@ function default_1(_a) {
257
251
  },
258
252
  externals: customBaseConfig === null || customBaseConfig === void 0 ? void 0 : customBaseConfig.externals,
259
253
  plugins: [
260
- ...basicPlugins,
261
254
  new core_1.CssExtractRspackPlugin({
262
255
  filename: env === 'dev' ? 'css/[name].css' : 'css/[name].[contenthash].css',
263
256
  ignoreOrder: true
264
257
  }),
265
258
  new vue_loader_1.VueLoaderPlugin(),
266
- new core_1.DefinePlugin({
267
- __VUE_OPTIONS_API__: true,
268
- __VUE_PROD_DEVTOOLS__: false,
269
- __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: false
270
- }),
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 : {}))),
271
260
  new core_1.HtmlRspackPlugin({
272
261
  template: path_1.default.join(projectPath, '/src/index.ejs'),
273
262
  filename: 'index.html',
274
263
  minify: true,
275
264
  templateParameters: {
276
- publicPath,
277
- routerBase
265
+ SWICO_ENV: env,
266
+ SWICO_ROUTER_BASE: routerBase,
267
+ SWICO_PUBLIC_PATH: publicPath
278
268
  },
279
269
  hash: true
280
270
  }),
281
- ...((_f = customBaseConfig === null || customBaseConfig === void 0 ? void 0 : customBaseConfig.plugins) !== null && _f !== void 0 ? _f : config_1.initConfig.plugins)
271
+ ...((_f = customBaseConfig === null || customBaseConfig === void 0 ? void 0 : customBaseConfig.plugins) !== null && _f !== void 0 ? _f : main_config_1.initConfig.plugins)
282
272
  ]
283
273
  };
284
274
  });
@@ -1,2 +1,2 @@
1
- import { GlobalData } from '../utils/config';
1
+ import { GlobalData } from '../main-config';
2
2
  export default function (options: GlobalData): Promise<any>;
@@ -49,7 +49,7 @@ exports.default = default_1;
49
49
  const webpack_bundle_analyzer_1 = __importDefault(require("webpack-bundle-analyzer"));
50
50
  const path_1 = __importDefault(require("path"));
51
51
  const fs_extra_1 = __importDefault(require("fs-extra"));
52
- const config_1 = require("../utils/config");
52
+ const main_config_1 = require("../main-config");
53
53
  const webpack_merge_1 = require("webpack-merge");
54
54
  const core_1 = require("@rspack/core");
55
55
  const BundleAnalyzerPlugin = webpack_bundle_analyzer_1.default.BundleAnalyzerPlugin;
@@ -60,9 +60,9 @@ function default_1(options) {
60
60
  const { projectPath, customConfig, templateType } = options;
61
61
  const getBaseConfig = (yield Promise.resolve(`${templateType === 'vue' ? './rspack.base.vue' : './rspack.base.react'}`).then(s => __importStar(require(s)))).default;
62
62
  const baseConfig = yield getBaseConfig(Object.assign(Object.assign({}, options), { env: 'prod' }));
63
- const consoleAvailable = (_b = (_a = customConfig.prod) === null || _a === void 0 ? void 0 : _a.console) !== null && _b !== void 0 ? _b : config_1.initConfig.console;
63
+ const consoleAvailable = (_b = (_a = customConfig.prod) === null || _a === void 0 ? void 0 : _a.console) !== null && _b !== void 0 ? _b : main_config_1.initConfig.console;
64
64
  const isPublicDirExist = yield fs_extra_1.default.exists(path_1.default.join(projectPath, '/public'));
65
- const copyConfig = (_d = (_c = customConfig.prod) === null || _c === void 0 ? void 0 : _c.copy) !== null && _d !== void 0 ? _d : config_1.initConfig.copy;
65
+ const copyConfig = (_d = (_c = customConfig.prod) === null || _c === void 0 ? void 0 : _c.copy) !== null && _d !== void 0 ? _d : main_config_1.initConfig.copy;
66
66
  const customDevtool = (_e = customConfig.prod.devtool) !== null && _e !== void 0 ? _e : customConfig.base.devtool;
67
67
  return (0, webpack_merge_1.merge)(baseConfig, {
68
68
  output: {
@@ -1,4 +1,4 @@
1
- import { ConfigRouterType } from './config';
1
+ import { ConfigRouterType } from './main-config';
2
2
  export declare const copyDirFiles: (src: any, dest: any, filter?: (fileName: any) => boolean) => Promise<void>;
3
3
  export declare const getFormatRouter: (projectPath: string, routes: ConfigRouterType["routes"], templateType: any) => any[];
4
4
  export declare const getPort: () => Promise<number>;
@@ -1,4 +0,0 @@
1
- declare const _default: import("vue").DefineComponent<{}, {
2
- error: import("vue").Ref<string, string>;
3
- }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
4
- export default _default;
@@ -1,15 +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: 'Container',
6
- setup(props) {
7
- const error = (0, vue_1.ref)(null);
8
- (0, vue_1.onErrorCaptured)((err) => {
9
- error.value = err.toString();
10
- return false;
11
- });
12
- return { error };
13
- },
14
- template: '<Layout v-if="!error"><RouterView /></Layout>'
15
- });
File without changes