ko 5.3.10 → 6.0.0
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/build.js +47 -52
- package/lib/actions/dev.js +78 -84
- package/lib/actions/factory.js +23 -0
- package/lib/actions/lints.js +70 -0
- package/lib/cli.js +17 -33
- package/lib/core/commander.js +65 -0
- package/lib/core/config.js +56 -0
- package/lib/core/hooks.js +40 -0
- package/lib/core/service.js +23 -0
- package/lib/types.js +8 -0
- package/lib/utils/index.js +22 -0
- package/lib/webpack/index.js +98 -60
- package/lib/webpack/loaders/babel/index.js +75 -0
- package/lib/webpack/loaders/index.js +5 -1
- package/lib/webpack/loaders/script.js +48 -54
- package/lib/webpack/loaders/style.js +159 -80
- package/lib/webpack/plugins.js +63 -22
- package/package.json +33 -32
- package/lib/actions/creator.js +0 -42
- package/lib/interfaces.js +0 -2
- package/lib/utils/config.js +0 -43
package/lib/webpack/plugins.js
CHANGED
|
@@ -4,38 +4,79 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const webpack_1 = require("webpack");
|
|
7
|
-
const case_sensitive_paths_webpack_plugin_1 = __importDefault(require("case-sensitive-paths-webpack-plugin"));
|
|
8
7
|
const mini_css_extract_plugin_1 = __importDefault(require("mini-css-extract-plugin"));
|
|
8
|
+
const case_sensitive_paths_webpack_plugin_1 = __importDefault(require("case-sensitive-paths-webpack-plugin"));
|
|
9
9
|
const react_refresh_webpack_plugin_1 = __importDefault(require("@pmmmwh/react-refresh-webpack-plugin"));
|
|
10
10
|
const webpackbar_1 = __importDefault(require("webpackbar"));
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
const clean_webpack_plugin_1 = require("clean-webpack-plugin");
|
|
12
|
+
const copy_webpack_plugin_1 = __importDefault(require("copy-webpack-plugin"));
|
|
13
|
+
const html_webpack_plugin_1 = __importDefault(require("html-webpack-plugin"));
|
|
14
|
+
const webpack_bundle_analyzer_1 = require("webpack-bundle-analyzer");
|
|
15
|
+
function getPlugins(opts) {
|
|
16
|
+
const { isProd, htmlTemplate, copy, analyzer } = opts;
|
|
17
|
+
return [
|
|
15
18
|
new webpack_1.IgnorePlugin({
|
|
16
19
|
resourceRegExp: /^\.\/locale$/,
|
|
17
20
|
contextRegExp: /moment$/,
|
|
18
21
|
}),
|
|
19
|
-
|
|
22
|
+
isProd &&
|
|
23
|
+
new webpack_1.optimize.SplitChunksPlugin({
|
|
24
|
+
chunks: 'all',
|
|
25
|
+
minSize: 30000,
|
|
26
|
+
maxSize: 600000,
|
|
27
|
+
minChunks: 1,
|
|
28
|
+
automaticNameDelimiter: '_',
|
|
29
|
+
cacheGroups: {
|
|
30
|
+
baseCommon: {
|
|
31
|
+
test: new RegExp(`[\\/]node_modules[\\/](${[
|
|
32
|
+
'react',
|
|
33
|
+
'react-router',
|
|
34
|
+
'react-dom',
|
|
35
|
+
'react-redux',
|
|
36
|
+
'redux',
|
|
37
|
+
'react-router-redux',
|
|
38
|
+
].join('|')})`),
|
|
39
|
+
priority: 1,
|
|
40
|
+
},
|
|
41
|
+
antd: {
|
|
42
|
+
name: 'antd',
|
|
43
|
+
test: /[\\/]node_modules[\\/]antd[\\/]/,
|
|
44
|
+
chunks: 'initial',
|
|
45
|
+
},
|
|
46
|
+
lodash: {
|
|
47
|
+
name: 'lodash',
|
|
48
|
+
test: /[\\/]node_modules[\\/]lodash[\\/]/,
|
|
49
|
+
chunks: 'initial',
|
|
50
|
+
priority: -10,
|
|
51
|
+
},
|
|
52
|
+
default: {
|
|
53
|
+
minChunks: 2,
|
|
54
|
+
priority: -20,
|
|
55
|
+
reuseExistingChunk: true,
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
}),
|
|
20
59
|
new mini_css_extract_plugin_1.default({
|
|
21
|
-
filename: 'css/[name].[contenthash].css',
|
|
22
|
-
chunkFilename: 'css/[id].[contenthash].css',
|
|
60
|
+
filename: isProd ? 'css/[name].[contenthash].css' : 'css/[name].css',
|
|
61
|
+
chunkFilename: isProd ? 'css/[id].[contenthash].css' : 'css/[id].css',
|
|
23
62
|
}),
|
|
24
63
|
new case_sensitive_paths_webpack_plugin_1.default(),
|
|
25
|
-
new
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const prodPlugins = [
|
|
32
|
-
new CleanWebpackPlugin({
|
|
33
|
-
verbose: false,
|
|
34
|
-
dry: false,
|
|
64
|
+
new html_webpack_plugin_1.default({
|
|
65
|
+
template: htmlTemplate,
|
|
66
|
+
}),
|
|
67
|
+
copy &&
|
|
68
|
+
new copy_webpack_plugin_1.default({
|
|
69
|
+
patterns: copy,
|
|
35
70
|
}),
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
71
|
+
new webpackbar_1.default(),
|
|
72
|
+
new clean_webpack_plugin_1.CleanWebpackPlugin({
|
|
73
|
+
verbose: false,
|
|
74
|
+
dry: false,
|
|
75
|
+
}),
|
|
76
|
+
new react_refresh_webpack_plugin_1.default({
|
|
77
|
+
overlay: false,
|
|
78
|
+
}),
|
|
79
|
+
analyzer && new webpack_bundle_analyzer_1.BundleAnalyzerPlugin(),
|
|
80
|
+
].filter(Boolean);
|
|
40
81
|
}
|
|
41
82
|
exports.default = getPlugins;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ko",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0",
|
|
4
4
|
"description": "build & lint library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ko",
|
|
@@ -31,59 +31,60 @@
|
|
|
31
31
|
"ko": "./lib/cli.js"
|
|
32
32
|
},
|
|
33
33
|
"files": [
|
|
34
|
-
"scripts/*",
|
|
35
34
|
"lib/*"
|
|
36
35
|
],
|
|
37
36
|
"dependencies": {
|
|
38
|
-
"@babel/core": "^7.
|
|
39
|
-
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.
|
|
40
|
-
"autoprefixer": "^10.4.
|
|
41
|
-
"babel-loader": "^8.2.
|
|
37
|
+
"@babel/core": "^7.18.0",
|
|
38
|
+
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.7",
|
|
39
|
+
"autoprefixer": "^10.4.7",
|
|
40
|
+
"babel-loader": "^8.2.5",
|
|
41
|
+
"babel-plugin-treasure": "^0.9.0",
|
|
42
42
|
"babel-preset-ko-app": "^1.0.0",
|
|
43
43
|
"buffer": "^6.0.3",
|
|
44
44
|
"case-sensitive-paths-webpack-plugin": "^2.4.0",
|
|
45
45
|
"chalk": "^4.1.2",
|
|
46
|
-
"clean-webpack-plugin": "4.0.0",
|
|
47
|
-
"commander": "^9.
|
|
46
|
+
"clean-webpack-plugin": "^4.0.0",
|
|
47
|
+
"commander": "^9.2.0",
|
|
48
|
+
"copy-webpack-plugin": "^11.0.0",
|
|
48
49
|
"crypto-browserify": "^3.12.0",
|
|
49
|
-
"css-loader": "^6.
|
|
50
|
-
"css-minimizer-webpack-plugin": "^
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"inquirer": "^8.2.0",
|
|
50
|
+
"css-loader": "^6.7.1",
|
|
51
|
+
"css-minimizer-webpack-plugin": "^4.0.0",
|
|
52
|
+
"esbuild-loader": "^2.19.0",
|
|
53
|
+
"html-webpack-plugin": "^5.5.0",
|
|
54
54
|
"less": "^3.13.1",
|
|
55
55
|
"less-loader": "^9.1.0",
|
|
56
|
-
"
|
|
56
|
+
"lodash": "^4.17.21",
|
|
57
|
+
"mini-css-extract-plugin": "^2.6.0",
|
|
57
58
|
"os-browserify": "^0.3.0",
|
|
58
|
-
"postcss": "^8.4.
|
|
59
|
-
"postcss-loader": "^
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"sass
|
|
59
|
+
"postcss": "^8.4.14",
|
|
60
|
+
"postcss-loader": "^7.0.0",
|
|
61
|
+
"postcss-url": "^10.1.3",
|
|
62
|
+
"ko-lints": "^2.0.0",
|
|
63
|
+
"react-refresh": "^0.13.0",
|
|
64
|
+
"sass": "^1.52.1",
|
|
65
|
+
"sass-loader": "^13.0.0",
|
|
64
66
|
"stream-browserify": "^3.0.0",
|
|
65
67
|
"string_decoder": "^1.3.0",
|
|
68
|
+
"style-loader": "^3.3.1",
|
|
69
|
+
"tapable": "^2.2.1",
|
|
66
70
|
"thread-loader": "^3.0.4",
|
|
67
|
-
"
|
|
68
|
-
"webpack": "^5.69.1",
|
|
71
|
+
"webpack": "^5.72.1",
|
|
69
72
|
"webpack-bundle-analyzer": "^4.5.0",
|
|
70
|
-
"webpack-dev-server": "
|
|
71
|
-
"webpack-merge": "^5.8.0",
|
|
73
|
+
"webpack-dev-server": "4.9.0",
|
|
72
74
|
"webpackbar": "^5.0.2",
|
|
73
75
|
"worker-loader": "^3.0.8"
|
|
74
76
|
},
|
|
75
77
|
"devDependencies": {
|
|
76
78
|
"@types/case-sensitive-paths-webpack-plugin": "^2.1.6",
|
|
77
|
-
"@types/
|
|
78
|
-
"@types/
|
|
79
|
-
"@types/
|
|
80
|
-
"
|
|
81
|
-
"jest": "^
|
|
82
|
-
"
|
|
83
|
-
"typescript": "^4.6.2"
|
|
79
|
+
"@types/jest": "^27.5.1",
|
|
80
|
+
"@types/lodash": "^4.14.182",
|
|
81
|
+
"@types/webpack-bundle-analyzer": "^4.4.1",
|
|
82
|
+
"jest": "^28.1.0",
|
|
83
|
+
"ts-jest": "^28.0.3",
|
|
84
|
+
"typescript": "^4.6.4"
|
|
84
85
|
},
|
|
85
86
|
"engines": {
|
|
86
|
-
"node": ">=
|
|
87
|
+
"node": ">=14"
|
|
87
88
|
},
|
|
88
89
|
"scripts": {
|
|
89
90
|
"debug": "tsc -w --sourceMap",
|
package/lib/actions/creator.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.WebpackCreator = void 0;
|
|
7
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
-
const webpack_merge_1 = require("webpack-merge");
|
|
9
|
-
const webpack_1 = __importDefault(require("../webpack"));
|
|
10
|
-
const config_1 = __importDefault(require("../utils/config"));
|
|
11
|
-
class Creator {
|
|
12
|
-
}
|
|
13
|
-
class WebpackCreator extends Creator {
|
|
14
|
-
constructor(opts) {
|
|
15
|
-
super();
|
|
16
|
-
this.opts = opts;
|
|
17
|
-
this.baseConfig = this.initConfig(opts);
|
|
18
|
-
}
|
|
19
|
-
pluginsUnique(pluginNames) {
|
|
20
|
-
return (0, webpack_merge_1.unique)('plugins', pluginNames, (plugin) => plugin.constructor && plugin.constructor.name);
|
|
21
|
-
}
|
|
22
|
-
initConfig(opts) {
|
|
23
|
-
this.baseConfig = (0, webpack_1.default)(opts);
|
|
24
|
-
return (0, webpack_merge_1.mergeWithCustomize)({
|
|
25
|
-
customizeArray: this.pluginsUnique(['HtmlWebpackPlugin']),
|
|
26
|
-
})(this.baseConfig, config_1.default.userConf);
|
|
27
|
-
}
|
|
28
|
-
mergeConfig(conf) {
|
|
29
|
-
return (0, webpack_merge_1.merge)(conf);
|
|
30
|
-
}
|
|
31
|
-
successStdout(log) {
|
|
32
|
-
console.log(chalk_1.default.green(log));
|
|
33
|
-
}
|
|
34
|
-
linkStdout(link) {
|
|
35
|
-
console.log(chalk_1.default.underline(link));
|
|
36
|
-
}
|
|
37
|
-
errorStdout(log) {
|
|
38
|
-
console.log(chalk_1.default.red(log));
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
exports.WebpackCreator = WebpackCreator;
|
|
42
|
-
exports.default = Creator;
|
package/lib/interfaces.js
DELETED
package/lib/utils/config.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const path_1 = require("path");
|
|
4
|
-
const fs_1 = require("fs");
|
|
5
|
-
class Config {
|
|
6
|
-
constructor() {
|
|
7
|
-
this.babelPlugins = [];
|
|
8
|
-
this.cwd = process.cwd();
|
|
9
|
-
}
|
|
10
|
-
static getInstance() {
|
|
11
|
-
if (!Config.instance) {
|
|
12
|
-
Config.instance = Object.freeze(new Config());
|
|
13
|
-
}
|
|
14
|
-
return Config.instance;
|
|
15
|
-
}
|
|
16
|
-
getFileRealPath(path) {
|
|
17
|
-
return (0, path_1.isAbsolute)(path) ? path : (0, path_1.resolve)(this.cwd, path);
|
|
18
|
-
}
|
|
19
|
-
get userConf() {
|
|
20
|
-
const userConfPath = this.getFileRealPath('ko.config.js');
|
|
21
|
-
if ((0, fs_1.existsSync)(userConfPath)) {
|
|
22
|
-
const userConf = require(userConfPath);
|
|
23
|
-
return userConf;
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
throw new Error('user config file not exist, please check it!');
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
get defaultPaths() {
|
|
30
|
-
return {
|
|
31
|
-
src: this.getFileRealPath('src'),
|
|
32
|
-
dist: this.getFileRealPath('dist'),
|
|
33
|
-
public: this.getFileRealPath('public'),
|
|
34
|
-
html: this.getFileRealPath('public/index.html'),
|
|
35
|
-
tsconfig: this.getFileRealPath('tsconfig.json'),
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
get isProductionEnv() {
|
|
39
|
-
const PROD = 'production';
|
|
40
|
-
return process.env.NODE_ENV === PROD;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
exports.default = Config.getInstance();
|