ko 5.3.9 → 6.0.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/README.md +36 -1
- 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 +160 -79
- package/lib/webpack/plugins.js +63 -22
- package/package.json +34 -33
- package/lib/actions/creator.js +0 -42
- package/lib/interfaces.js +0 -2
- package/lib/utils/config.js +0 -43
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
const commander_1 = __importDefault(require("./commander"));
|
|
7
|
+
const hooks_1 = __importDefault(require("./hooks"));
|
|
8
|
+
const config_1 = __importDefault(require("./config"));
|
|
9
|
+
class Service extends hooks_1.default {
|
|
10
|
+
constructor() {
|
|
11
|
+
super();
|
|
12
|
+
this.commander = new commander_1.default();
|
|
13
|
+
this.config = new config_1.default().generate();
|
|
14
|
+
this.config.plugins && this.config.plugins.forEach(p => this.register(p));
|
|
15
|
+
}
|
|
16
|
+
freezeCliOptsWith(cliOpts) {
|
|
17
|
+
this.cliOpts = Object.freeze(cliOpts);
|
|
18
|
+
}
|
|
19
|
+
run() {
|
|
20
|
+
this.commander.parse();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.default = Service;
|
package/lib/types.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
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.assert = exports.getResolvePath = exports.getCacheIdentifier = void 0;
|
|
7
|
+
function getCacheIdentifier(env, pkgs) {
|
|
8
|
+
let cacheIdentifier = env || '';
|
|
9
|
+
Object.values(pkgs).forEach(pkgName => {
|
|
10
|
+
cacheIdentifier += `:${pkgName}@`;
|
|
11
|
+
cacheIdentifier += require(`${pkgName}/package.json`).version || '';
|
|
12
|
+
});
|
|
13
|
+
return cacheIdentifier;
|
|
14
|
+
}
|
|
15
|
+
exports.getCacheIdentifier = getCacheIdentifier;
|
|
16
|
+
function getResolvePath(name) {
|
|
17
|
+
const resolvePath = require.resolve(name);
|
|
18
|
+
return resolvePath;
|
|
19
|
+
}
|
|
20
|
+
exports.getResolvePath = getResolvePath;
|
|
21
|
+
var assert_1 = require("assert");
|
|
22
|
+
Object.defineProperty(exports, "assert", { enumerable: true, get: function () { return __importDefault(assert_1).default; } });
|
package/lib/webpack/index.js
CHANGED
|
@@ -3,67 +3,105 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
7
|
-
const
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
const fs_1 = require("fs");
|
|
8
|
+
const lodash_1 = require("lodash");
|
|
8
9
|
const loaders_1 = __importDefault(require("./loaders"));
|
|
9
10
|
const plugins_1 = __importDefault(require("./plugins"));
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
11
|
+
const utils_1 = require("../utils");
|
|
12
|
+
class WebpackConfig {
|
|
13
|
+
constructor(service) {
|
|
14
|
+
this.extensions = [
|
|
15
|
+
'.ts',
|
|
16
|
+
'.tsx',
|
|
17
|
+
'.js',
|
|
18
|
+
'.jsx',
|
|
19
|
+
'.css',
|
|
20
|
+
'.scss',
|
|
21
|
+
'.sass',
|
|
22
|
+
'.less',
|
|
23
|
+
'.json',
|
|
24
|
+
'.html',
|
|
25
|
+
];
|
|
26
|
+
this.opts = { ...service.config, ...service.cliOpts };
|
|
27
|
+
this.env =
|
|
28
|
+
process.env.NODE_ENV === 'production' ? 'production' : 'development';
|
|
29
|
+
}
|
|
30
|
+
merge(...opts) {
|
|
31
|
+
return (0, lodash_1.merge)(this.base, ...opts);
|
|
32
|
+
}
|
|
33
|
+
get cache() {
|
|
34
|
+
const { experiment } = this.opts;
|
|
35
|
+
const type = experiment?.speedUp
|
|
36
|
+
? 'filesystem'
|
|
37
|
+
: this.isProd
|
|
38
|
+
? 'filesystem'
|
|
39
|
+
: 'memory';
|
|
40
|
+
const cache = {
|
|
41
|
+
type,
|
|
42
|
+
};
|
|
43
|
+
if (type === 'filesystem') {
|
|
44
|
+
cache.version = this.projectVersion;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
cache.maxGenerations = 1;
|
|
48
|
+
}
|
|
49
|
+
return cache;
|
|
50
|
+
}
|
|
51
|
+
get projectVersion() {
|
|
52
|
+
const pkgPath = (0, path_1.join)(this.opts.cwd, 'package.json');
|
|
53
|
+
(0, utils_1.assert)((0, fs_1.existsSync)(pkgPath), 'project package.json file not found');
|
|
54
|
+
return require(pkgPath).version;
|
|
55
|
+
}
|
|
56
|
+
get base() {
|
|
57
|
+
const { cwd, publicPath, entry, outputPath, alias, hash, analyzer } = this.opts;
|
|
58
|
+
const webpackBaseConf = {
|
|
59
|
+
mode: this.env,
|
|
60
|
+
target: 'web',
|
|
61
|
+
context: cwd,
|
|
62
|
+
entry,
|
|
63
|
+
output: {
|
|
64
|
+
path: outputPath,
|
|
65
|
+
filename: `js/[name].${hash ? '[contenthash].' : ''}js`,
|
|
66
|
+
publicPath,
|
|
55
67
|
},
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
+
module: {
|
|
69
|
+
rules: (0, loaders_1.default)({
|
|
70
|
+
isProd: this.isProd,
|
|
71
|
+
...this.opts,
|
|
72
|
+
}),
|
|
73
|
+
},
|
|
74
|
+
plugins: (0, plugins_1.default)({
|
|
75
|
+
isProd: this.isProd,
|
|
76
|
+
analyzer,
|
|
77
|
+
...this.opts,
|
|
78
|
+
}),
|
|
79
|
+
resolve: {
|
|
80
|
+
extensions: this.extensions,
|
|
81
|
+
alias,
|
|
82
|
+
fallback: {
|
|
83
|
+
fs: false,
|
|
84
|
+
path: false,
|
|
85
|
+
events: false,
|
|
86
|
+
os: require.resolve('os-browserify/browser'),
|
|
87
|
+
crypto: require.resolve('crypto-browserify'),
|
|
88
|
+
stream: require.resolve('stream-browserify'),
|
|
89
|
+
buffer: require.resolve('buffer/'),
|
|
90
|
+
string_decoder: require.resolve('string_decoder/'),
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
performance: {
|
|
94
|
+
hints: false,
|
|
95
|
+
},
|
|
96
|
+
cache: this.cache,
|
|
97
|
+
stats: {
|
|
98
|
+
cachedModules: false,
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
return webpackBaseConf;
|
|
102
|
+
}
|
|
103
|
+
get isProd() {
|
|
104
|
+
return this.env === 'production';
|
|
105
|
+
}
|
|
68
106
|
}
|
|
69
|
-
exports.default =
|
|
107
|
+
exports.default = WebpackConfig;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const utils_1 = require("../../../utils");
|
|
4
|
+
class BabelLoader {
|
|
5
|
+
constructor(opts) {
|
|
6
|
+
this.BABEL_LOADER = (0, utils_1.getResolvePath)('babel-loader');
|
|
7
|
+
this.opts = opts;
|
|
8
|
+
}
|
|
9
|
+
get config() {
|
|
10
|
+
return {
|
|
11
|
+
loader: this.BABEL_LOADER,
|
|
12
|
+
options: {
|
|
13
|
+
presets: [
|
|
14
|
+
[
|
|
15
|
+
(0, utils_1.getResolvePath)('babel-preset-ko-app'),
|
|
16
|
+
{
|
|
17
|
+
useAbsoluteRuntime: true,
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
],
|
|
21
|
+
plugins: this.plugins,
|
|
22
|
+
babelrc: false,
|
|
23
|
+
configFile: false,
|
|
24
|
+
cacheIdentifier: this.cacheIdentifier,
|
|
25
|
+
cacheDirectory: !this.speedUp,
|
|
26
|
+
cacheCompression: false,
|
|
27
|
+
compact: this.opts.isProd,
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
get treasurePluginConfig() {
|
|
32
|
+
const babelPluginTreasurePath = (0, utils_1.getResolvePath)('babel-plugin-treasure');
|
|
33
|
+
return [
|
|
34
|
+
[
|
|
35
|
+
babelPluginTreasurePath,
|
|
36
|
+
{
|
|
37
|
+
libraryName: 'antd',
|
|
38
|
+
libraryDirectory: 'lib',
|
|
39
|
+
style: 'css',
|
|
40
|
+
},
|
|
41
|
+
'antd',
|
|
42
|
+
],
|
|
43
|
+
[
|
|
44
|
+
babelPluginTreasurePath,
|
|
45
|
+
{
|
|
46
|
+
libraryName: 'dt-react-component',
|
|
47
|
+
libraryDirectory: '/src/components/',
|
|
48
|
+
camel2DashComponentName: 'lower',
|
|
49
|
+
},
|
|
50
|
+
'drc',
|
|
51
|
+
],
|
|
52
|
+
//TODO: check lodash tree shaking in webpack 5
|
|
53
|
+
// [
|
|
54
|
+
// babelPluginTreasurePath,
|
|
55
|
+
// {
|
|
56
|
+
// libraryName: 'lodash',
|
|
57
|
+
// libraryDirectory: '/',
|
|
58
|
+
// camel2DashComponentName: false,
|
|
59
|
+
// },
|
|
60
|
+
// 'lodash',
|
|
61
|
+
// ],
|
|
62
|
+
];
|
|
63
|
+
}
|
|
64
|
+
get plugins() {
|
|
65
|
+
return [...this.treasurePluginConfig].filter(Boolean);
|
|
66
|
+
}
|
|
67
|
+
get cacheIdentifier() {
|
|
68
|
+
return (0, utils_1.getCacheIdentifier)(this.opts.isProd ? 'production' : '', [
|
|
69
|
+
'ko',
|
|
70
|
+
'babel-preset-ko-app',
|
|
71
|
+
'babel-plugin-treasure',
|
|
72
|
+
]);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.default = BabelLoader;
|
|
@@ -6,5 +6,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const style_1 = __importDefault(require("./style"));
|
|
7
7
|
const asset_1 = __importDefault(require("./asset"));
|
|
8
8
|
const script_1 = __importDefault(require("./script"));
|
|
9
|
-
const loaders =
|
|
9
|
+
const loaders = (opts) => {
|
|
10
|
+
const scripts = new script_1.default(opts);
|
|
11
|
+
const style = new style_1.default(opts);
|
|
12
|
+
return [...asset_1.default, ...style.config, ...scripts.config];
|
|
13
|
+
};
|
|
10
14
|
exports.default = loaders;
|
|
@@ -3,64 +3,58 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
test: /\.(t|j)sx?$/,
|
|
21
|
-
include: (input) => {
|
|
22
|
-
// internal modules dt-common compatible
|
|
23
|
-
if (input.includes('node_modules/dt-common/src/')) {
|
|
24
|
-
return true;
|
|
25
|
-
}
|
|
26
|
-
else if (input.includes('node_modules')) {
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
return true;
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
use: [
|
|
6
|
+
const babel_1 = __importDefault(require("./babel"));
|
|
7
|
+
class Script {
|
|
8
|
+
constructor(opts) {
|
|
9
|
+
this.THREAD_LOADER = require.resolve('thread-loader');
|
|
10
|
+
this.WORKER_LOADER = require.resolve('worker-loader');
|
|
11
|
+
this.ESBUILD_LOADER = require.resolve('esbuild-loader');
|
|
12
|
+
this.opts = opts;
|
|
13
|
+
this.BABEL_LOADER = new babel_1.default(opts);
|
|
14
|
+
}
|
|
15
|
+
get config() {
|
|
16
|
+
const scriptLoader = [
|
|
34
17
|
{
|
|
35
|
-
|
|
18
|
+
test: /\.worker.[jt]s$/,
|
|
19
|
+
loader: this.WORKER_LOADER,
|
|
36
20
|
options: {
|
|
37
|
-
|
|
38
|
-
name: 'ko-js-pool',
|
|
21
|
+
inline: 'fallback',
|
|
39
22
|
},
|
|
40
23
|
},
|
|
41
24
|
{
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
: [],
|
|
55
|
-
babelrc: false,
|
|
56
|
-
configFile: false,
|
|
57
|
-
cacheIdentifier: (0, getCacheIdentifier_1.default)(config_1.default.isProductionEnv ? 'production' : '', ['babel-preset-ko-app', 'react-dev-utils', 'ko']),
|
|
58
|
-
cacheDirectory: true,
|
|
59
|
-
cacheCompression: false,
|
|
60
|
-
compact: config_1.default.isProductionEnv,
|
|
25
|
+
test: /\.(t|j)sx?$/,
|
|
26
|
+
include: (input) => {
|
|
27
|
+
// internal modules dt-common compatible
|
|
28
|
+
if (input.includes('node_modules/dt-common/src/')) {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
else if (input.includes('node_modules')) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
61
37
|
},
|
|
38
|
+
use: [
|
|
39
|
+
{
|
|
40
|
+
loader: this.THREAD_LOADER,
|
|
41
|
+
options: {
|
|
42
|
+
name: 'ko-js-pool',
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
this.opts.experiment?.speedUp
|
|
46
|
+
? {
|
|
47
|
+
loader: this.ESBUILD_LOADER,
|
|
48
|
+
options: {
|
|
49
|
+
loader: 'tsx',
|
|
50
|
+
target: 'es2020',
|
|
51
|
+
},
|
|
52
|
+
}
|
|
53
|
+
: this.BABEL_LOADER.config,
|
|
54
|
+
].filter(Boolean),
|
|
62
55
|
},
|
|
63
|
-
]
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
56
|
+
];
|
|
57
|
+
return scriptLoader;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.default = Script;
|