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.
@@ -3,95 +3,176 @@ 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 path_1 = __importDefault(require("path"));
6
+ const path_1 = require("path");
7
7
  const fs_1 = require("fs");
8
8
  const mini_css_extract_plugin_1 = require("mini-css-extract-plugin");
9
9
  const autoprefixer_1 = __importDefault(require("autoprefixer"));
10
- const CSS_LOADER = require.resolve('css-loader');
11
- const LESS_LOADER = require.resolve('less-loader');
12
- const SASS_LOADER = require.resolve('sass-loader');
13
- const POSTCSS_LOADER = require.resolve('postcss-loader');
14
- const antdV4Path = path_1.default.join(process.cwd(), 'node_modules/antd-v4');
15
- const antdV4RealPath = (0, fs_1.realpathSync)(antdV4Path);
16
- const styleLoader = {
17
- loader: mini_css_extract_plugin_1.loader,
18
- };
19
- const cssLoader = {
20
- loader: CSS_LOADER,
21
- options: {
22
- sourceMap: true,
23
- },
24
- };
25
- //TODO: check postcss-loader should use sourceMap option
26
- const postcssLoader = {
27
- loader: POSTCSS_LOADER,
28
- options: {
29
- sourceMap: true,
30
- postcssOptions: {
31
- plugins: [(0, autoprefixer_1.default)()],
32
- },
33
- },
34
- };
35
- const styleLoaders = [
36
- {
37
- test: /\.css$/,
38
- use: [styleLoader, cssLoader, postcssLoader],
39
- },
40
- {
41
- test: /\.s[ac]ss$/,
42
- use: [
43
- styleLoader,
44
- cssLoader,
45
- postcssLoader,
10
+ const postCssUrl = require('postcss-url');
11
+ const utils_1 = require("../../utils");
12
+ class Style {
13
+ constructor(opts) {
14
+ this.CSS_LOADER = (0, utils_1.getResolvePath)('css-loader');
15
+ this.SASS_LOADER = (0, utils_1.getResolvePath)('sass-loader');
16
+ this.LESS_LOADER = (0, utils_1.getResolvePath)('less-loader');
17
+ this.POSTCSS_LOADER = (0, utils_1.getResolvePath)('postcss-loader');
18
+ this.CSS_MODULE_FILE_SUFFIX_REGEX = /\.module.s[ac]ss$/;
19
+ this.opts = opts;
20
+ }
21
+ get config() {
22
+ const enableCssModule = this.opts?.experiment?.enableCssModule;
23
+ return [
46
24
  {
47
- loader: SASS_LOADER,
48
- options: {
49
- sourceMap: true,
50
- },
25
+ test: /\.css$/,
26
+ use: [this.styleLoader, this.cssLoader, this.postCSSLoader],
51
27
  },
52
- ],
53
- },
54
- {
55
- test: /\.less$/,
56
- exclude: [antdV4RealPath],
57
- use: [
58
- styleLoader,
59
- cssLoader,
60
- postcssLoader,
61
28
  {
62
- loader: LESS_LOADER,
63
- options: {
64
- lessOptions: {
65
- javascriptEnabled: true,
66
- },
67
- sourceMap: true,
29
+ test: /\.s[ac]ss$/,
30
+ exclude: (input) => {
31
+ if (enableCssModule) {
32
+ return this.CSS_MODULE_FILE_SUFFIX_REGEX.test(input);
33
+ }
34
+ else {
35
+ return false;
36
+ }
68
37
  },
38
+ use: [
39
+ this.styleLoader,
40
+ this.cssLoader,
41
+ this.postCSSLoader,
42
+ this.sassLoader,
43
+ ],
69
44
  },
70
- ],
71
- },
72
- {
73
- test: /\.less$/,
74
- include: [antdV4RealPath],
75
- use: [
76
- styleLoader,
77
- cssLoader,
78
- postcssLoader,
45
+ enableCssModule && this.sassCssModuleConfig,
79
46
  {
80
- loader: LESS_LOADER,
81
- options: {
82
- sourceMap: true,
83
- lessOptions: {
84
- modifyVars: {
85
- '@ant-prefix': 'ant-v4',
86
- '@font-size-base': '12px',
87
- '@border-color-base': '#ddd',
88
- '@font-family': "-apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'",
47
+ test: /\.less$/,
48
+ exclude: [this.realAntdV4Path],
49
+ use: [
50
+ this.styleLoader,
51
+ this.cssLoader,
52
+ this.postCSSLoader,
53
+ this.lessLoader,
54
+ ],
55
+ },
56
+ {
57
+ test: /\.less$/,
58
+ include: [this.realAntdV4Path],
59
+ use: [
60
+ this.styleLoader,
61
+ this.cssLoader,
62
+ this.postCSSLoader,
63
+ this.antdV4LessLoader,
64
+ ],
65
+ },
66
+ ];
67
+ }
68
+ get sassCssModuleConfig() {
69
+ return {
70
+ test: /\.module.s[ac]ss$/,
71
+ use: [
72
+ this.styleLoader,
73
+ {
74
+ loader: this.CSS_LOADER,
75
+ options: {
76
+ esModule: true,
77
+ modules: {
78
+ namedExport: true,
79
+ localIdentName: this.opts.isProd
80
+ ? '[path][name]__[local]'
81
+ : '[local]_[hash:base64]',
89
82
  },
90
- javascriptEnabled: true,
91
83
  },
92
84
  },
85
+ this.postCSSLoader,
86
+ this.sassLoader,
87
+ ],
88
+ };
89
+ }
90
+ //TODO: remove when upgrade to antd v4
91
+ get realAntdV4Path() {
92
+ const antdV4Path = (0, path_1.join)(this.opts.cwd, 'node_modules/antd-v4');
93
+ const ret = (0, fs_1.existsSync)(antdV4Path) ? (0, fs_1.realpathSync)(antdV4Path) : antdV4Path;
94
+ return ret;
95
+ }
96
+ get styleLoader() {
97
+ return {
98
+ loader: mini_css_extract_plugin_1.loader,
99
+ };
100
+ }
101
+ get cssLoader() {
102
+ return {
103
+ loader: this.CSS_LOADER,
104
+ options: {
105
+ sourceMap: true,
106
+ },
107
+ };
108
+ }
109
+ get sassLoader() {
110
+ return {
111
+ loader: this.SASS_LOADER,
112
+ options: {
113
+ sourceMap: true,
93
114
  },
94
- ],
95
- },
96
- ];
97
- exports.default = styleLoaders;
115
+ };
116
+ }
117
+ get lessLoader() {
118
+ const { lessOptions = {} } = this.opts;
119
+ return {
120
+ loader: this.LESS_LOADER,
121
+ options: {
122
+ sourceMap: true,
123
+ lessOptions,
124
+ },
125
+ };
126
+ }
127
+ get antdV4LessLoader() {
128
+ const { antdV4LessOptions = {} } = this.opts;
129
+ return {
130
+ loader: this.LESS_LOADER,
131
+ options: {
132
+ sourceMap: true,
133
+ lessOptions: antdV4LessOptions,
134
+ },
135
+ };
136
+ }
137
+ get postCSSLoader() {
138
+ return {
139
+ loader: this.POSTCSS_LOADER,
140
+ options: {
141
+ sourceMap: true,
142
+ postcssOptions: {
143
+ plugins: this.postCSSPlugins,
144
+ },
145
+ },
146
+ };
147
+ }
148
+ get postCSSPlugins() {
149
+ const extraPostCSSPlugins = this.opts.extraPostCSSPlugins || [];
150
+ return [
151
+ (0, autoprefixer_1.default)(),
152
+ postCssUrl([
153
+ {
154
+ filter: '**/src/public/img/**/*',
155
+ url: (args) => {
156
+ const originUrl = args?.originUrl;
157
+ return originUrl
158
+ ? (0, path_1.join)(this.opts.cwd, originUrl)
159
+ : args.absolutePath;
160
+ },
161
+ basePath: '/',
162
+ },
163
+ {
164
+ filter: '**/src/public/font/**/*',
165
+ url: (args) => {
166
+ const originUrl = args?.originUrl;
167
+ return originUrl
168
+ ? (0, path_1.join)(this.opts.cwd, originUrl)
169
+ : args.absolutePath;
170
+ },
171
+ basePath: '/',
172
+ },
173
+ ]),
174
+ ...extraPostCSSPlugins,
175
+ ].filter(Boolean);
176
+ }
177
+ }
178
+ exports.default = Style;
@@ -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 config_1 = __importDefault(require("../utils/config"));
12
- function getPlugins() {
13
- const { userConf } = config_1.default;
14
- let plugins = [
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
- //TODO: check if mini-css-extract-plugin should use base name if enable HMR
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 react_refresh_webpack_plugin_1.default(),
26
- new webpackbar_1.default(),
27
- ];
28
- plugins = plugins.concat(userConf.plugins || []);
29
- if (config_1.default.isProductionEnv) {
30
- const { CleanWebpackPlugin } = require('clean-webpack-plugin');
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
- plugins.concat(prodPlugins);
38
- }
39
- return plugins;
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": "5.3.9",
3
+ "version": "6.0.1",
4
4
  "description": "build & lint library",
5
5
  "keywords": [
6
6
  "ko",
@@ -31,64 +31,65 @@
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.17.5",
39
- "@pmmmwh/react-refresh-webpack-plugin": "^0.5.4",
40
- "autoprefixer": "^10.4.2",
41
- "babel-loader": "^8.2.3",
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.0.0",
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.6.0",
50
- "css-minimizer-webpack-plugin": "^3.4.1",
51
- "detect-port": "^1.3.0",
52
- "esbuild-loader": "^2.18.0",
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
- "mini-css-extract-plugin": "^2.5.3",
56
+ "lodash": "^4.17.21",
57
+ "mini-css-extract-plugin": "^2.6.0",
57
58
  "os-browserify": "^0.3.0",
58
- "postcss": "^8.4.7",
59
- "postcss-loader": "^6.2.1",
60
- "react-dev-utils": "^12.0.0",
61
- "react-refresh": "^0.11.0",
62
- "sass": "^1.49.9",
63
- "sass-loader": "^12.6.0",
59
+ "postcss": "^8.4.14",
60
+ "postcss-loader": "^7.0.0",
61
+ "postcss-url": "^10.1.3",
62
+ "ko-lints": "^3.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
- "tsconfig-paths-webpack-plugin": "^3.5.2",
68
- "webpack": "^5.69.1",
71
+ "webpack": "^5.72.1",
69
72
  "webpack-bundle-analyzer": "^4.5.0",
70
- "webpack-dev-server": "3.11.3",
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/detect-port": "^1.3.2",
78
- "@types/inquirer": "^8.2.0",
79
- "@types/jest": "^27.4.1",
80
- "@types/react-dev-utils": "^9.0.10",
81
- "jest": "^27.5.1",
82
- "ts-jest": "^27.1.3",
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": ">=10.13.0"
87
+ "node": ">=14"
87
88
  },
88
89
  "scripts": {
89
90
  "debug": "tsc -w --sourceMap",
90
91
  "test": "jest",
91
92
  "build": "tsc"
92
93
  },
93
- "readme": "# ko\n\nbuild & lint library\n"
94
+ "readme": "# ko\n\n## Simple, yet powerful, tool for managing your react applications. \n\n<a href=\"https://www.npmjs.com/package/ko\"><img alt=\"NPM Status\" src=\"https://img.shields.io/npm/v/ko.svg?style=flat\"></a>\n\n## Features\n\n* Support building applications on top of **webpack v5** and **esbuild**\n* Customize ko to work exactly the way you need it for your applications \n* Built-in popular linting tools to lint your source code\n* Built-in support typescript\n\n## Installation\n\nYou can install ko using npm, yarn or pnpm:\n``` bash\nnpm install ko --save-dev\n# or\nyarn add ko --dev\n# or \npnpm add ko --save-dev\n```\n\n## Documents\n* [Introduction](https://dtstack.github.io/ko/docs/introduction)\n* [Getting Started](https://dtstack.github.io/ko/docs/getting-started)\n* [FAQ](https://dtstack.github.io/ko/docs/FAQ)\n\n## Contributing\n\nWe'd love to have your helping hand on `ko`! See [CONTRIBUTING](https://dtstack.github.io/ko/docs/contributing/) for more information on how to get started.\n\n## License\n\nCopyright © DTStack. All rights reserved.\n\nLicensed under the MIT license.\n"
94
95
  }
@@ -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
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -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();