swico 1.7.3 → 2.0.0-beta.10
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 +10 -21
- package/src/bin.js +6 -6
- package/src/command/build.js +33 -73
- package/src/command/start.js +100 -192
- package/src/config/rsbpack.dev.js +104 -0
- package/src/config/{webpack.base.react.d.ts → rspack.base.react.d.ts} +43 -6
- package/src/config/rspack.base.react.js +195 -0
- package/src/config/{webpack.base.vue.d.ts → rspack.base.vue.d.ts} +32 -32
- package/src/config/rspack.base.vue.js +167 -0
- package/src/config/rspack.prod.js +122 -0
- package/src/index.js +3 -5
- package/src/index.react.js +5 -10
- package/src/index.vue.js +4 -6
- package/src/project-path/.swico-react/$env/history.js +65 -66
- package/src/project-path/.swico-react/$env/index.js +29 -47
- package/src/project-path/.swico-react/loading.js +1 -1
- package/src/project-path/.swico-react/react-hooks.js +24 -37
- package/src/project-path/.swico-vue/$env/history.js +25 -36
- package/src/project-path/.swico-vue/$env/index.js +7 -7
- package/src/project-path/.swico-vue/Container.js +1 -1
- package/src/project-path/.swico-vue/vue-hooks.js +17 -28
- package/src/project-path/src/layout/Layout.js +1 -1
- package/src/project-path/src/layout/index.js +3 -3
- package/src/task.js +13 -58
- package/src/utils/config.js +185 -349
- package/src/utils/tools.js +103 -199
- package/src/config/webpack.base.react.js +0 -315
- package/src/config/webpack.base.vue.js +0 -338
- package/src/config/webpack.dev.js +0 -159
- package/src/config/webpack.prod.js +0 -193
- /package/src/config/{webpack.dev.d.ts → rsbpack.dev.d.ts} +0 -0
- /package/src/config/{webpack.prod.d.ts → rspack.prod.d.ts} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "swico",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-beta.10",
|
|
4
4
|
"description": "Simple, efficient, and practical front-end framework",
|
|
5
5
|
"main": "./src/index.js",
|
|
6
6
|
"types": "./src/index.d.ts",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"cli",
|
|
14
14
|
"swico",
|
|
15
15
|
"template",
|
|
16
|
-
"
|
|
16
|
+
"rspack"
|
|
17
17
|
],
|
|
18
18
|
"bin": {
|
|
19
19
|
"swico": "./src/bin.js"
|
|
@@ -30,47 +30,37 @@
|
|
|
30
30
|
"author": "scw",
|
|
31
31
|
"license": "ISC",
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@
|
|
34
|
-
"@
|
|
33
|
+
"@rspack/core": "1.3.4",
|
|
34
|
+
"@rspack/dev-server": "^1.1.1",
|
|
35
35
|
"@vue/compiler-sfc": "3.4.14",
|
|
36
36
|
"autoprefixer": "10.3.7",
|
|
37
37
|
"chalk": "4.1.2",
|
|
38
38
|
"chokidar": "3.6.0",
|
|
39
39
|
"commander": "12.0.0",
|
|
40
|
-
"copy-webpack-plugin": "12.0.2",
|
|
41
40
|
"cross-spawn": "7.0.5",
|
|
42
41
|
"css-loader": "6.3.0",
|
|
43
|
-
"esbuild-loader": "4.0.3",
|
|
44
|
-
"eslint-plugin-react": "7.33.2",
|
|
45
|
-
"eslint-plugin-react-hooks": "4.3.0",
|
|
46
|
-
"eslint-plugin-vue": "9.19.2",
|
|
47
42
|
"eslint-webpack-plugin": "4.0.0",
|
|
48
|
-
"fork-ts-checker-webpack-plugin": "9.0.2",
|
|
49
43
|
"fs-extra": "11.3.0",
|
|
50
44
|
"html-loader": "5.0.0",
|
|
51
|
-
"html-webpack-plugin": "5.3.2",
|
|
52
45
|
"less": "4.1.2",
|
|
53
46
|
"less-loader": "12.2.0",
|
|
54
|
-
"mini-css-extract-plugin": "2.4.2",
|
|
55
47
|
"ora": "5.4.1",
|
|
56
48
|
"portfinder": "1.0.32",
|
|
57
49
|
"postcss-loader": "8.1.0",
|
|
58
50
|
"postcss-preset-env": "9.3.0",
|
|
59
51
|
"qs": "6.13.0",
|
|
60
52
|
"react-router-dom": "6.23.0",
|
|
61
|
-
"sass": "1.
|
|
62
|
-
"sass-loader": "
|
|
53
|
+
"sass-embedded": "^1.86.3",
|
|
54
|
+
"sass-loader": "16.0.5",
|
|
63
55
|
"style-loader": "3.3.0",
|
|
64
|
-
"
|
|
56
|
+
"ts-checker-rspack-plugin": "^1.1.1",
|
|
65
57
|
"ts-node": "10.9.1",
|
|
66
58
|
"vue-loader": "17.4.2",
|
|
67
59
|
"vue-router": "^4.2.5",
|
|
68
60
|
"vue-style-loader": "4.1.3",
|
|
69
61
|
"webpack-bundle-analyzer": "4.9.1",
|
|
70
|
-
"webpack-
|
|
71
|
-
"
|
|
72
|
-
"webpack-merge": "5.9.0",
|
|
73
|
-
"webpackbar": "6.0.1"
|
|
62
|
+
"webpack-merge": "^6.0.1",
|
|
63
|
+
"webpackbar": "^7.0.0"
|
|
74
64
|
},
|
|
75
65
|
"devDependencies": {
|
|
76
66
|
"@types/node": "22.13.10",
|
|
@@ -82,7 +72,6 @@
|
|
|
82
72
|
"react": "~18.2.0",
|
|
83
73
|
"react-dom": "~18.2.0",
|
|
84
74
|
"typescript": "5.3.3",
|
|
85
|
-
"vue": "~3.4.14"
|
|
86
|
-
"webpack": "5.94.0"
|
|
75
|
+
"vue": "~3.4.14"
|
|
87
76
|
}
|
|
88
77
|
}
|
package/src/bin.js
CHANGED
|
@@ -27,20 +27,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
27
27
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
28
28
|
};
|
|
29
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
Promise.resolve().then(
|
|
30
|
+
const commander_1 = require("commander");
|
|
31
|
+
const start_1 = __importDefault(require("./command/start"));
|
|
32
|
+
const build_1 = __importDefault(require("./command/build"));
|
|
33
|
+
Promise.resolve().then(() => __importStar(require('ts-node/register')));
|
|
34
34
|
commander_1.program
|
|
35
35
|
.command('start')
|
|
36
36
|
.description('start the development environment service')
|
|
37
|
-
.action(
|
|
37
|
+
.action(() => {
|
|
38
38
|
(0, start_1.default)();
|
|
39
39
|
});
|
|
40
40
|
commander_1.program
|
|
41
41
|
.command('build')
|
|
42
42
|
.description('package to build the output product')
|
|
43
|
-
.action(
|
|
43
|
+
.action(() => {
|
|
44
44
|
(0, build_1.default)();
|
|
45
45
|
});
|
|
46
46
|
commander_1.program.parse(process.argv);
|
package/src/command/build.js
CHANGED
|
@@ -8,85 +8,45 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
13
|
};
|
|
41
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
15
|
+
const rspack_prod_1 = __importDefault(require("../config/rspack.prod"));
|
|
16
|
+
const config_1 = require("../utils/config");
|
|
17
|
+
const tools_1 = require("../utils/tools");
|
|
18
|
+
const package_json_1 = __importDefault(require("../../package.json"));
|
|
19
|
+
const core_1 = require("@rspack/core");
|
|
47
20
|
function default_1() {
|
|
48
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
tools_1.toast.error(err.stack || err.toString());
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
var info = stats.toJson();
|
|
79
|
-
if (stats.hasErrors()) {
|
|
80
|
-
tools_1.toast.error(info.errors.map(function (item) { return item.stack || item.message; }));
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
if (stats.hasWarnings()) {
|
|
84
|
-
tools_1.toast.warning(info.warnings.map(function (item) { return item.stack || item.message; }));
|
|
85
|
-
}
|
|
86
|
-
tools_1.toast.success('Build complete');
|
|
87
|
-
});
|
|
88
|
-
return [2];
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
process.env.SWICO_ENV = 'prod';
|
|
23
|
+
tools_1.toast.info(`Swico v${package_json_1.default.version}`);
|
|
24
|
+
tools_1.toast.info('Initializing production config...');
|
|
25
|
+
yield (0, tools_1.initIndexFile)();
|
|
26
|
+
const projectConfig = yield (0, config_1.getProjectConfig)('prod');
|
|
27
|
+
const { entryPath, templatePath, projectPath, customConfig, templateType } = projectConfig;
|
|
28
|
+
const buildConfig = yield (0, rspack_prod_1.default)({
|
|
29
|
+
entryPath,
|
|
30
|
+
templatePath,
|
|
31
|
+
projectPath,
|
|
32
|
+
customConfig,
|
|
33
|
+
templateType
|
|
34
|
+
});
|
|
35
|
+
const compiler = (0, core_1.rspack)(buildConfig);
|
|
36
|
+
compiler.run((err, stats) => {
|
|
37
|
+
if (err) {
|
|
38
|
+
tools_1.toast.error(err.stack || err.toString());
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const info = stats.toJson();
|
|
42
|
+
if (stats.hasErrors()) {
|
|
43
|
+
tools_1.toast.error(info.errors.map((item) => item.stack || item.message));
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (stats.hasWarnings()) {
|
|
47
|
+
tools_1.toast.warning(info.warnings.map((item) => item.stack || item.message));
|
|
89
48
|
}
|
|
49
|
+
tools_1.toast.success('Build complete');
|
|
90
50
|
});
|
|
91
51
|
});
|
|
92
52
|
}
|
package/src/command/start.js
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -19,135 +8,77 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
19
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
9
|
});
|
|
21
10
|
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
13
|
};
|
|
52
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
15
|
+
const rsbpack_dev_1 = __importDefault(require("../config/rsbpack.dev"));
|
|
16
|
+
const tools_1 = require("../utils/tools");
|
|
17
|
+
const config_1 = require("../utils/config");
|
|
18
|
+
const chokidar_1 = __importDefault(require("chokidar"));
|
|
19
|
+
const cross_spawn_1 = __importDefault(require("cross-spawn"));
|
|
20
|
+
const path_1 = __importDefault(require("path"));
|
|
21
|
+
const { SWICO_PORT, SWICO_RESTART, SWICO_ROUTER_BASE } = process.env;
|
|
22
|
+
const package_json_1 = __importDefault(require("../../package.json"));
|
|
23
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
24
|
+
const dev_server_1 = require("@rspack/dev-server");
|
|
25
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
26
|
+
const core_1 = require("@rspack/core");
|
|
27
|
+
let currentPort, currentRouterBase = '/';
|
|
28
|
+
const handleWatch = (projectPath, devServer, env) => {
|
|
29
|
+
const envPath = env === 'dev' ? '/.dev/' : '/.prod/';
|
|
30
|
+
const configFilesWatcher = chokidar_1.default
|
|
69
31
|
.watch([path_1.default.join(projectPath, '/config/*.ts'), path_1.default.join(projectPath, '/.eslintrc')], {
|
|
70
32
|
interval: 500,
|
|
71
33
|
binaryInterval: 500,
|
|
72
34
|
ignoreInitial: true,
|
|
73
35
|
ignored: [path_1.default.join(projectPath, '/config/swico.prod.ts')]
|
|
74
36
|
})
|
|
75
|
-
.on('all',
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
case 0:
|
|
79
|
-
tools_1.toast.warning('Swico configuration files changed, restarting server...', {
|
|
80
|
-
inline: true
|
|
81
|
-
});
|
|
82
|
-
return [4, devServer.stop()];
|
|
83
|
-
case 1:
|
|
84
|
-
_a.sent();
|
|
85
|
-
return [4, configFilesWatcher.close()];
|
|
86
|
-
case 2:
|
|
87
|
-
_a.sent();
|
|
88
|
-
restartServer();
|
|
89
|
-
return [2];
|
|
90
|
-
}
|
|
37
|
+
.on('all', (path, stats) => __awaiter(void 0, void 0, void 0, function* () {
|
|
38
|
+
tools_1.toast.warning('Configuration files changed, restarting server...', {
|
|
39
|
+
inline: true
|
|
91
40
|
});
|
|
92
|
-
|
|
93
|
-
|
|
41
|
+
yield devServer.stop();
|
|
42
|
+
yield configFilesWatcher.close();
|
|
43
|
+
restartServer();
|
|
44
|
+
}));
|
|
45
|
+
const globalStyleFilesPathList = [
|
|
94
46
|
path_1.default.join(projectPath, '/src/global.css'),
|
|
95
47
|
path_1.default.join(projectPath, '/src/global.less'),
|
|
96
48
|
path_1.default.join(projectPath, '/src/global.scss')
|
|
97
49
|
];
|
|
98
|
-
|
|
99
|
-
|
|
50
|
+
const loadingFilePath = path_1.default.join(projectPath, '/src/loading/index.tsx');
|
|
51
|
+
const tsTypingsWatcher = chokidar_1.default
|
|
100
52
|
.watch([path_1.default.join(projectPath, '/src/**/*')], {
|
|
101
53
|
interval: 500,
|
|
102
54
|
binaryInterval: 500,
|
|
103
55
|
ignoreInitial: true
|
|
104
56
|
})
|
|
105
|
-
.on('all',
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
switch (
|
|
109
|
-
case
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
if (!['add', 'unlink'].includes(eventName)) return [3, 10];
|
|
113
|
-
_a = true;
|
|
114
|
-
switch (_a) {
|
|
115
|
-
case filePath.endsWith('.d.ts'): return [3, 2];
|
|
116
|
-
case globalStyleFilesPathList.includes(filePath): return [3, 5];
|
|
117
|
-
case filePath === loadingFilePath: return [3, 7];
|
|
118
|
-
}
|
|
119
|
-
return [3, 10];
|
|
120
|
-
case 2: return [4, devServer.stop()];
|
|
121
|
-
case 3:
|
|
122
|
-
_b.sent();
|
|
123
|
-
return [4, tsTypingsWatcher.close()];
|
|
124
|
-
case 4:
|
|
125
|
-
_b.sent();
|
|
57
|
+
.on('all', (eventName, filePath, stats) => __awaiter(void 0, void 0, void 0, function* () {
|
|
58
|
+
let replaceIndexText = yield fs_extra_1.default.readFile(path_1.default.resolve(projectPath, `./.swico${envPath}index.js`), 'utf8');
|
|
59
|
+
if (['add', 'unlink'].includes(eventName)) {
|
|
60
|
+
switch (true) {
|
|
61
|
+
case filePath.endsWith('.d.ts'):
|
|
62
|
+
yield devServer.stop();
|
|
63
|
+
yield tsTypingsWatcher.close();
|
|
126
64
|
restartServer();
|
|
127
|
-
|
|
128
|
-
case
|
|
65
|
+
break;
|
|
66
|
+
case globalStyleFilesPathList.includes(filePath):
|
|
129
67
|
replaceIndexText = (0, config_1.handleGlobalStyleFile)(replaceIndexText);
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
case 8:
|
|
136
|
-
replaceIndexText = _b.sent();
|
|
137
|
-
return [4, (0, config_1.updateIndexFileText)(envPath, replaceIndexText)];
|
|
138
|
-
case 9:
|
|
139
|
-
_b.sent();
|
|
140
|
-
_b.label = 10;
|
|
141
|
-
case 10: return [2];
|
|
68
|
+
yield (0, config_1.updateIndexFileText)(envPath, replaceIndexText);
|
|
69
|
+
break;
|
|
70
|
+
case filePath === loadingFilePath:
|
|
71
|
+
replaceIndexText = yield (0, config_1.handleLoadingFile)(replaceIndexText, envPath);
|
|
72
|
+
yield (0, config_1.updateIndexFileText)(envPath, replaceIndexText);
|
|
142
73
|
}
|
|
143
|
-
}
|
|
144
|
-
})
|
|
74
|
+
}
|
|
75
|
+
}));
|
|
145
76
|
};
|
|
146
|
-
|
|
147
|
-
|
|
77
|
+
const restartServer = () => {
|
|
78
|
+
const result = cross_spawn_1.default.sync('cross-env', [
|
|
148
79
|
'SWICO_RESTART=true',
|
|
149
|
-
|
|
150
|
-
|
|
80
|
+
`SWICO_PORT=${currentPort}`,
|
|
81
|
+
`SWICO_ROUTER_BASE=${currentRouterBase}`,
|
|
151
82
|
'swico',
|
|
152
83
|
'start'
|
|
153
84
|
], {
|
|
@@ -158,106 +89,83 @@ var restartServer = function () {
|
|
|
158
89
|
process.exit(1);
|
|
159
90
|
}
|
|
160
91
|
};
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
return
|
|
165
|
-
return
|
|
92
|
+
const getMockGetLogger = (compiler) => {
|
|
93
|
+
const logger = compiler.getInfrastructureLogger('name');
|
|
94
|
+
const { log, debug, error, warn } = logger;
|
|
95
|
+
return (name) => {
|
|
96
|
+
return Object.assign(Object.assign({}, logger), { log,
|
|
97
|
+
debug,
|
|
98
|
+
error,
|
|
99
|
+
warn, info: () => { } });
|
|
166
100
|
};
|
|
167
101
|
};
|
|
168
|
-
|
|
102
|
+
const filterStyleFileList = [
|
|
169
103
|
'Can\'t resolve \'../../src/global.less\'',
|
|
170
104
|
'Can\'t resolve \'../../src/global.css\'',
|
|
171
105
|
'Can\'t resolve \'../../src/global.scss\'',
|
|
172
106
|
'Can\'t resolve \'../../src/loading\''
|
|
173
107
|
];
|
|
174
|
-
|
|
175
|
-
compiler.hooks.beforeCompile.tap('beforeCompile',
|
|
108
|
+
const createCompileListener = (compiler) => {
|
|
109
|
+
compiler.hooks.beforeCompile.tap('beforeCompile', () => {
|
|
176
110
|
tools_1.toast.info('Compiling...');
|
|
177
111
|
});
|
|
178
|
-
compiler.hooks.done.tap('done',
|
|
179
|
-
|
|
112
|
+
compiler.hooks.done.tap('done', (stats) => {
|
|
113
|
+
const info = stats === null || stats === void 0 ? void 0 : stats.toJson();
|
|
180
114
|
if (stats === null || stats === void 0 ? void 0 : stats.hasErrors()) {
|
|
181
|
-
tools_1.toast.error(info === null || info === void 0 ? void 0 : info.errors.map(
|
|
115
|
+
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))));
|
|
182
116
|
return;
|
|
183
117
|
}
|
|
184
118
|
if (stats === null || stats === void 0 ? void 0 : stats.hasWarnings()) {
|
|
185
|
-
|
|
186
|
-
warnings.some(
|
|
187
|
-
|
|
188
|
-
if (msg.
|
|
119
|
+
const warnings = info.warnings;
|
|
120
|
+
warnings.some((item) => {
|
|
121
|
+
const msg = item.message || item.stack;
|
|
122
|
+
if (msg.includes('[eslint]')) {
|
|
189
123
|
tools_1.toast.warning(msg, { title: 'ESLint errors' });
|
|
190
124
|
return;
|
|
191
125
|
}
|
|
192
126
|
});
|
|
193
127
|
}
|
|
194
|
-
tools_1.toast.info(
|
|
128
|
+
tools_1.toast.info(`Compiled ${(info === null || info === void 0 ? void 0 : info.time) ? `in ${(info.time / 1000).toFixed(2)}s` : ''}`);
|
|
195
129
|
});
|
|
196
130
|
};
|
|
197
131
|
function start() {
|
|
198
132
|
var _a, _b, _c, _d, _e, _f;
|
|
199
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
projectPath = projectConfig.projectPath, customConfig = projectConfig.customConfig, env = projectConfig.env;
|
|
226
|
-
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 : '/';
|
|
227
|
-
return [4, (0, webpack_dev_1.default)(projectConfig)];
|
|
228
|
-
case 6:
|
|
229
|
-
startConfig = _h.sent();
|
|
230
|
-
compiler = (0, webpack_1.default)(startConfig);
|
|
231
|
-
oriLogger = compiler.getInfrastructureLogger;
|
|
232
|
-
compiler.getInfrastructureLogger = getMockGetLogger(compiler);
|
|
233
|
-
devServer = new webpack_dev_server_1.default(__assign(__assign({}, startConfig.devServer), { port: availablePort }), compiler);
|
|
234
|
-
_h.label = 7;
|
|
235
|
-
case 7:
|
|
236
|
-
_h.trys.push([7, 9, , 10]);
|
|
237
|
-
return [4, devServer.start()];
|
|
238
|
-
case 8:
|
|
239
|
-
_h.sent();
|
|
240
|
-
process.env.SWICO_PORT = availablePort.toString();
|
|
241
|
-
createCompileListener(compiler);
|
|
242
|
-
compiler.getInfrastructureLogger = oriLogger;
|
|
243
|
-
handleWatch(projectPath, devServer, env);
|
|
244
|
-
if (SWICO_RESTART !== 'true' ||
|
|
245
|
-
(SWICO_RESTART === 'true' && newRouterBase !== SWICO_ROUTER_BASE)) {
|
|
246
|
-
tools_1.toast.info("Project is running at\uFF1A".concat(chalk_1.default.hex('#29abe0')("".concat(startConfig.devServer.server, "://localhost:").concat(availablePort).concat(newRouterBase))));
|
|
247
|
-
}
|
|
248
|
-
currentRouterBase = newRouterBase;
|
|
249
|
-
currentPort = availablePort;
|
|
250
|
-
return [3, 10];
|
|
251
|
-
case 9:
|
|
252
|
-
e_1 = _h.sent();
|
|
253
|
-
strErr_1 = e_1.toString();
|
|
254
|
-
if (!filterStyleFileList.find(function (item) { return strErr_1.includes(item); })) {
|
|
255
|
-
tools_1.toast.error(strErr_1);
|
|
256
|
-
}
|
|
257
|
-
return [3, 10];
|
|
258
|
-
case 10: return [2];
|
|
133
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
134
|
+
process.env.SWICO_ENV = 'dev';
|
|
135
|
+
if (SWICO_RESTART !== 'true') {
|
|
136
|
+
console.log('\n');
|
|
137
|
+
tools_1.toast.info(`Swico v${package_json_1.default.version}`);
|
|
138
|
+
tools_1.toast.info('Initializing development config...');
|
|
139
|
+
}
|
|
140
|
+
yield (0, tools_1.initIndexFile)();
|
|
141
|
+
const availablePort = SWICO_RESTART === 'true' ? Number(SWICO_PORT) : yield (0, tools_1.getPort)();
|
|
142
|
+
const projectConfig = yield (0, config_1.getProjectConfig)('dev');
|
|
143
|
+
const { projectPath, customConfig, env } = projectConfig;
|
|
144
|
+
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 : '/';
|
|
145
|
+
const startConfig = yield (0, rsbpack_dev_1.default)(projectConfig);
|
|
146
|
+
const compiler = (0, core_1.rspack)(startConfig);
|
|
147
|
+
const oriLogger = compiler.getInfrastructureLogger;
|
|
148
|
+
compiler.getInfrastructureLogger = getMockGetLogger(compiler);
|
|
149
|
+
const devServer = new dev_server_1.RspackDevServer(Object.assign(Object.assign({}, startConfig.devServer), { port: availablePort }), compiler);
|
|
150
|
+
try {
|
|
151
|
+
yield devServer.start();
|
|
152
|
+
process.env.SWICO_PORT = availablePort.toString();
|
|
153
|
+
createCompileListener(compiler);
|
|
154
|
+
compiler.getInfrastructureLogger = oriLogger;
|
|
155
|
+
handleWatch(projectPath, devServer, env);
|
|
156
|
+
if (SWICO_RESTART !== 'true' ||
|
|
157
|
+
(SWICO_RESTART === 'true' && newRouterBase !== SWICO_ROUTER_BASE)) {
|
|
158
|
+
tools_1.toast.info(`Project is running at:${chalk_1.default.hex('#29abe0')(`${startConfig.devServer.server}://localhost:${availablePort}${newRouterBase}`)}`);
|
|
259
159
|
}
|
|
260
|
-
|
|
160
|
+
currentRouterBase = newRouterBase;
|
|
161
|
+
currentPort = availablePort;
|
|
162
|
+
}
|
|
163
|
+
catch (e) {
|
|
164
|
+
const strErr = e.toString();
|
|
165
|
+
if (!filterStyleFileList.find((item) => strErr.includes(item))) {
|
|
166
|
+
tools_1.toast.error(strErr);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
261
169
|
});
|
|
262
170
|
}
|
|
263
171
|
exports.default = start;
|