ko 6.5.0 → 6.5.2
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/lib/actions/dev.js +31 -2
- package/lib/cli.js +1 -1
- package/lib/webpack/loaders/style.js +0 -28
- package/lib/webpack/plugins.js +9 -1
- package/package.json +7 -1
package/lib/actions/dev.js
CHANGED
|
@@ -7,13 +7,15 @@ const webpack_1 = __importDefault(require("webpack"));
|
|
|
7
7
|
const webpack_dev_server_1 = __importDefault(require("webpack-dev-server"));
|
|
8
8
|
const webpack_2 = __importDefault(require("../webpack"));
|
|
9
9
|
const factory_1 = __importDefault(require("./factory"));
|
|
10
|
+
const detect_port_1 = __importDefault(require("detect-port"));
|
|
11
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
10
12
|
class Dev extends factory_1.default {
|
|
11
13
|
constructor(service) {
|
|
12
14
|
super(service);
|
|
13
15
|
}
|
|
14
16
|
get devServerConfig() {
|
|
15
17
|
const { serve, publicPath, logLevel } = this.service.config;
|
|
16
|
-
const { host, port, proxy, staticPath } = serve;
|
|
18
|
+
const { host, port, proxy, staticPath, historyApiFallback = false } = serve;
|
|
17
19
|
return {
|
|
18
20
|
port,
|
|
19
21
|
host,
|
|
@@ -30,6 +32,7 @@ class Dev extends factory_1.default {
|
|
|
30
32
|
overlay: false,
|
|
31
33
|
logging: logLevel,
|
|
32
34
|
},
|
|
35
|
+
historyApiFallback,
|
|
33
36
|
};
|
|
34
37
|
}
|
|
35
38
|
async generateConfig() {
|
|
@@ -84,13 +87,39 @@ class Dev extends factory_1.default {
|
|
|
84
87
|
});
|
|
85
88
|
this.service.commander.bindAction(cmdName, this.action.bind(this));
|
|
86
89
|
}
|
|
90
|
+
async changePort(newPort, port) {
|
|
91
|
+
const question = {
|
|
92
|
+
type: 'confirm',
|
|
93
|
+
name: 'changePort',
|
|
94
|
+
message: `port: ${port} has been used,use new port ${newPort} instead?`,
|
|
95
|
+
default: true,
|
|
96
|
+
};
|
|
97
|
+
const answer = await inquirer_1.default.prompt([question]);
|
|
98
|
+
if (answer.changePort) {
|
|
99
|
+
return newPort;
|
|
100
|
+
}
|
|
101
|
+
this.errorStdout(`so sorry, ${port} already in use!!`);
|
|
102
|
+
process.exit(0);
|
|
103
|
+
}
|
|
104
|
+
async checkPort(port) {
|
|
105
|
+
const newPort = await (0, detect_port_1.default)(port);
|
|
106
|
+
if (newPort === port) {
|
|
107
|
+
return newPort;
|
|
108
|
+
}
|
|
109
|
+
const isInteractive = process.stdout.isTTY;
|
|
110
|
+
if (isInteractive) {
|
|
111
|
+
return this.changePort(newPort, port);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
87
114
|
async action(cliOpts) {
|
|
88
115
|
process.title = 'ko-dev';
|
|
89
116
|
process.env.NODE_ENV = 'development';
|
|
90
117
|
this.service.freezeCliOptsWith(cliOpts);
|
|
91
118
|
const config = await this.generateConfig();
|
|
119
|
+
const port = config.devServer?.port;
|
|
120
|
+
const newPort = (await this.checkPort(port));
|
|
92
121
|
const compiler = (0, webpack_1.default)(config);
|
|
93
|
-
const devServer = new webpack_dev_server_1.default(config.devServer, compiler);
|
|
122
|
+
const devServer = new webpack_dev_server_1.default({ ...config.devServer, port: newPort }, compiler);
|
|
94
123
|
await devServer.start();
|
|
95
124
|
const exitProcess = (callback) => () => {
|
|
96
125
|
callback && callback();
|
package/lib/cli.js
CHANGED
|
@@ -4,7 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const path_1 = require("path");
|
|
7
|
-
const fs_1 = require("fs");
|
|
8
7
|
const mini_css_extract_plugin_1 = require("mini-css-extract-plugin");
|
|
9
8
|
const autoprefixer_1 = __importDefault(require("autoprefixer"));
|
|
10
9
|
const postCssUrl = require('postcss-url');
|
|
@@ -46,7 +45,6 @@ class Style {
|
|
|
46
45
|
enableCssModule && this.sassCssModuleConfig,
|
|
47
46
|
{
|
|
48
47
|
test: /\.less$/,
|
|
49
|
-
exclude: [this.realAntdV4Path],
|
|
50
48
|
use: [
|
|
51
49
|
this.styleLoader,
|
|
52
50
|
this.cssLoader,
|
|
@@ -54,16 +52,6 @@ class Style {
|
|
|
54
52
|
this.lessLoader,
|
|
55
53
|
],
|
|
56
54
|
},
|
|
57
|
-
{
|
|
58
|
-
test: /\.less$/,
|
|
59
|
-
include: [this.realAntdV4Path],
|
|
60
|
-
use: [
|
|
61
|
-
this.styleLoader,
|
|
62
|
-
this.cssLoader,
|
|
63
|
-
this.postCSSLoader,
|
|
64
|
-
this.antdV4LessLoader,
|
|
65
|
-
],
|
|
66
|
-
},
|
|
67
55
|
];
|
|
68
56
|
}
|
|
69
57
|
get sassCssModuleConfig() {
|
|
@@ -88,12 +76,6 @@ class Style {
|
|
|
88
76
|
],
|
|
89
77
|
};
|
|
90
78
|
}
|
|
91
|
-
//TODO: remove when upgrade to antd v4
|
|
92
|
-
get realAntdV4Path() {
|
|
93
|
-
const antdV4Path = (0, path_1.join)(this.opts.cwd, 'node_modules/antd-v4');
|
|
94
|
-
const ret = (0, fs_1.existsSync)(antdV4Path) ? (0, fs_1.realpathSync)(antdV4Path) : antdV4Path;
|
|
95
|
-
return ret;
|
|
96
|
-
}
|
|
97
79
|
get styleLoader() {
|
|
98
80
|
return {
|
|
99
81
|
loader: this.opts.isProd ? mini_css_extract_plugin_1.loader : this.STYLE_LOADER,
|
|
@@ -125,16 +107,6 @@ class Style {
|
|
|
125
107
|
},
|
|
126
108
|
};
|
|
127
109
|
}
|
|
128
|
-
get antdV4LessLoader() {
|
|
129
|
-
const { antdV4LessOptions = {} } = this.opts;
|
|
130
|
-
return {
|
|
131
|
-
loader: this.LESS_LOADER,
|
|
132
|
-
options: {
|
|
133
|
-
sourceMap: true,
|
|
134
|
-
lessOptions: antdV4LessOptions,
|
|
135
|
-
},
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
110
|
get postCSSLoader() {
|
|
139
111
|
return {
|
|
140
112
|
loader: this.POSTCSS_LOADER,
|
package/lib/webpack/plugins.js
CHANGED
|
@@ -13,8 +13,9 @@ const copy_webpack_plugin_1 = __importDefault(require("copy-webpack-plugin"));
|
|
|
13
13
|
const html_webpack_plugin_1 = __importDefault(require("html-webpack-plugin"));
|
|
14
14
|
const webpack_bundle_analyzer_1 = require("webpack-bundle-analyzer");
|
|
15
15
|
const auto_polyfills_webpack_plugin_1 = __importDefault(require("auto-polyfills-webpack-plugin"));
|
|
16
|
+
const friendly_errors_webpack_plugin_1 = __importDefault(require("@nuxt/friendly-errors-webpack-plugin"));
|
|
16
17
|
function getPlugins(opts) {
|
|
17
|
-
const { isProd, htmlTemplate, copy, analyzer, autoPolyfills } = opts;
|
|
18
|
+
const { isProd, htmlTemplate, copy, analyzer, autoPolyfills, serve: { host, port, compilationSuccessInfo }, } = opts;
|
|
18
19
|
return [
|
|
19
20
|
new webpack_1.IgnorePlugin({
|
|
20
21
|
resourceRegExp: /^\.\/locale$/,
|
|
@@ -79,6 +80,13 @@ function getPlugins(opts) {
|
|
|
79
80
|
overlay: false,
|
|
80
81
|
}),
|
|
81
82
|
analyzer && new webpack_bundle_analyzer_1.BundleAnalyzerPlugin(),
|
|
83
|
+
!isProd &&
|
|
84
|
+
new friendly_errors_webpack_plugin_1.default({
|
|
85
|
+
compilationSuccessInfo: compilationSuccessInfo ?? {
|
|
86
|
+
messages: [`Your application is running at http://${host}:${port}`],
|
|
87
|
+
notes: [],
|
|
88
|
+
},
|
|
89
|
+
}),
|
|
82
90
|
isProd &&
|
|
83
91
|
autoPolyfills &&
|
|
84
92
|
(typeof autoPolyfills === 'boolean'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ko",
|
|
3
|
-
"version": "6.5.
|
|
3
|
+
"version": "6.5.2",
|
|
4
4
|
"description": "build & lint library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ko",
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"bugs": {
|
|
21
21
|
"url": "https://github.com/DTStack/ko/issues"
|
|
22
22
|
},
|
|
23
|
+
"typings": "index.d.ts",
|
|
23
24
|
"repository": {
|
|
24
25
|
"type": "git",
|
|
25
26
|
"url": "https://github.com/DTStack/ko",
|
|
@@ -35,6 +36,7 @@
|
|
|
35
36
|
],
|
|
36
37
|
"dependencies": {
|
|
37
38
|
"@babel/core": "^7.18.0",
|
|
39
|
+
"@nuxt/friendly-errors-webpack-plugin": "^2.5.2",
|
|
38
40
|
"@parcel/css": "^1.12.2",
|
|
39
41
|
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.7",
|
|
40
42
|
"auto-polyfills-webpack-plugin": "^1.1.0",
|
|
@@ -51,9 +53,11 @@
|
|
|
51
53
|
"crypto-browserify": "^3.12.0",
|
|
52
54
|
"css-loader": "^6.7.1",
|
|
53
55
|
"css-minimizer-webpack-plugin": "^4.0.0",
|
|
56
|
+
"detect-port": "^1.3.0",
|
|
54
57
|
"dynamic-resolve-webpack-plugin": "^2.0.0",
|
|
55
58
|
"esbuild-loader": "^2.19.0",
|
|
56
59
|
"html-webpack-plugin": "^5.5.0",
|
|
60
|
+
"inquirer": "^8.2.2",
|
|
57
61
|
"ko-lints": "^4.0.0",
|
|
58
62
|
"less": "^3.13.1",
|
|
59
63
|
"less-loader": "^9.1.0",
|
|
@@ -80,6 +84,8 @@
|
|
|
80
84
|
},
|
|
81
85
|
"devDependencies": {
|
|
82
86
|
"@types/case-sensitive-paths-webpack-plugin": "^2.1.6",
|
|
87
|
+
"@types/detect-port": "^1.3.2",
|
|
88
|
+
"@types/inquirer": "^8.2.2",
|
|
83
89
|
"@types/jest": "^27.5.1",
|
|
84
90
|
"@types/lodash": "^4.14.182",
|
|
85
91
|
"@types/webpack-bundle-analyzer": "^4.4.1",
|