ko 5.3.0 → 5.3.3

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.
@@ -13,32 +13,31 @@ const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
13
13
  class Dev extends creator_1.WebpackCreator {
14
14
  constructor(opts) {
15
15
  super(opts);
16
- }
17
- devSerConf() {
18
- const userDefinedDevServerConfig = config_1.default.userConf.devServer || {};
19
16
  const { port, host } = this.opts;
20
- const defaultDevServerConfig = {
17
+ const userDefinedDevServerConfig = config_1.default.userConf.devServer || {};
18
+ this.devServerConf = {
21
19
  port,
22
20
  host,
23
21
  historyApiFallback: true,
24
- allowedHosts: "all",
25
- hot: true,
22
+ allowedHosts: 'all',
26
23
  static: {
27
- directory: config_1.default.defaultPaths.dist,
28
24
  publicPath: '/',
29
- watch: true,
30
25
  },
31
- open: true,
26
+ client: {
27
+ overlay: {
28
+ errors: true,
29
+ warnings: false,
30
+ },
31
+ },
32
+ setupExitSignals: true,
33
+ ...userDefinedDevServerConfig,
32
34
  };
33
- return { ...defaultDevServerConfig, ...userDefinedDevServerConfig };
34
35
  }
35
36
  config() {
36
37
  const conf = {
37
38
  devtool: 'cheap-module-source-map',
38
- plugins: [
39
- new webpack_1.default.HotModuleReplacementPlugin(),
40
- this.opts.analyzer && new BundleAnalyzerPlugin(),
41
- ].filter(Boolean),
39
+ plugins: [this.opts.analyzer && new BundleAnalyzerPlugin()].filter(Boolean),
40
+ devServer: this.devServerConf,
42
41
  };
43
42
  return this.mergeConfig([this.baseConfig, conf]);
44
43
  }
@@ -67,34 +66,22 @@ class Dev extends creator_1.WebpackCreator {
67
66
  return this.changePort(newPort, port);
68
67
  }
69
68
  }
70
- getUrlHost(host) {
71
- const regex = /^https?:\/\/(([a-zA-Z0-9_-])+(\.)?)*$/i;
72
- return regex.test(host) ? host : `http://${host}`;
73
- }
74
69
  async action() {
75
- const { port, host } = this.devSerConf();
70
+ const { port } = this.devServerConf;
76
71
  const newPort = await this.checkPort(parseInt(port));
77
- if (!newPort)
78
- return;
79
- const compiler = (0, webpack_1.default)(this.config());
80
- const devServer = new webpack_dev_server_1.default(this.devSerConf(), compiler);
81
- let isFirstCompile = true;
82
- compiler.hooks.done.tap('done', stats => {
83
- if (isFirstCompile) {
84
- isFirstCompile = false;
85
- this.successStdout('development server has been started');
86
- console.log(`server starts at: ${this.linkStdout(this.getUrlHost(host) + ':' + port)}`);
87
- }
88
- if (stats.hasErrors()) {
89
- console.log(stats.toString({
90
- colors: true,
91
- }));
92
- }
93
- });
94
- compiler.hooks.invalid.tap('invalid', () => {
95
- console.log('Compiling...');
72
+ if (!newPort) {
73
+ process.exit(0);
74
+ }
75
+ this.devServerConf.port = newPort;
76
+ const config = this.config();
77
+ const compiler = (0, webpack_1.default)(config);
78
+ const devServer = new webpack_dev_server_1.default(config.devServer, compiler);
79
+ await devServer.start();
80
+ process.stdin.on('end', () => {
81
+ devServer.stop();
82
+ process.exit(0);
96
83
  });
97
- devServer.start();
84
+ process.stdin.resume();
98
85
  }
99
86
  }
100
87
  exports.default = Dev;
package/lib/cli.js CHANGED
@@ -5,7 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  };
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  const commander_1 = require("commander");
8
- const ko_lints_1 = __importDefault(require("ko-lints"));
9
8
  const build_1 = __importDefault(require("./actions/build"));
10
9
  const dev_1 = __importDefault(require("./actions/dev"));
11
10
  const program = new commander_1.Command();
@@ -21,6 +20,7 @@ program
21
20
  .option('-t,--ts,--typescript', 'support typescript')
22
21
  .option('-e,--esbuild', 'enable esbuild')
23
22
  .action((opts) => {
23
+ process.env.NODE_ENV = 'production';
24
24
  const buildInstance = new build_1.default(opts);
25
25
  buildInstance.action();
26
26
  });
@@ -36,6 +36,4 @@ program
36
36
  const devInstance = new dev_1.default(opts);
37
37
  devInstance.action();
38
38
  });
39
- //attach lint features to program
40
- (0, ko_lints_1.default)(program);
41
39
  program.parse();
@@ -4,22 +4,23 @@ const path_1 = require("path");
4
4
  const fs_1 = require("fs");
5
5
  class Config {
6
6
  constructor() {
7
+ this.babelPlugins = [];
7
8
  this.cwd = process.cwd();
8
9
  }
9
10
  static getInstance() {
10
11
  if (!Config.instance) {
11
- Config.instance = new Config();
12
+ Config.instance = Object.freeze(new Config());
12
13
  }
13
14
  return Config.instance;
14
15
  }
15
16
  getFileRealPath(path) {
16
17
  return (0, path_1.isAbsolute)(path) ? path : (0, path_1.resolve)(this.cwd, path);
17
18
  }
18
- //TODO: define userConf
19
19
  get userConf() {
20
20
  const userConfPath = this.getFileRealPath('ko.config.js');
21
21
  if ((0, fs_1.existsSync)(userConfPath)) {
22
- return userConfPath ? require(userConfPath) : {};
22
+ const userConf = require(userConfPath);
23
+ return userConf;
23
24
  }
24
25
  else {
25
26
  throw new Error('user config file not exist, please check it!');
@@ -48,7 +48,7 @@ function getWebpackBaseConf(opts) {
48
48
  hints: false,
49
49
  },
50
50
  cache: {
51
- type: 'filesystem',
51
+ type: config_1.default.isProductionEnv ? 'filesystem' : 'memory',
52
52
  },
53
53
  };
54
54
  return webpackBaseConf;
@@ -8,6 +8,13 @@ const config_1 = __importDefault(require("../../utils/config"));
8
8
  const THREAD_LOADER = require.resolve('thread-loader');
9
9
  const BABEL_LOADER = require.resolve('babel-loader');
10
10
  const scriptLoader = [
11
+ {
12
+ test: /\.worker.[jt]s$/,
13
+ loader: 'worker-loader',
14
+ options: {
15
+ inline: 'fallback',
16
+ },
17
+ },
11
18
  {
12
19
  test: /\.(t|j)sx?$/,
13
20
  exclude: {
@@ -27,6 +34,9 @@ const scriptLoader = [
27
34
  },
28
35
  ],
29
36
  ],
37
+ plugins: config_1.default.isProductionEnv
38
+ ? [require.resolve('react-refresh/babel')]
39
+ : [],
30
40
  babelrc: false,
31
41
  configFile: false,
32
42
  cacheIdentifier: (0, getCacheIdentifier_1.default)(config_1.default.isProductionEnv ? 'production' : '', ['babel-preset-ko-app', 'react-dev-utils', 'ko']),
@@ -6,33 +6,24 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const webpack_1 = require("webpack");
7
7
  const case_sensitive_paths_webpack_plugin_1 = __importDefault(require("case-sensitive-paths-webpack-plugin"));
8
8
  const mini_css_extract_plugin_1 = __importDefault(require("mini-css-extract-plugin"));
9
- const html_webpack_plugin_1 = __importDefault(require("html-webpack-plugin"));
9
+ const react_refresh_webpack_plugin_1 = __importDefault(require("@pmmmwh/react-refresh-webpack-plugin"));
10
+ const webpackbar_1 = __importDefault(require("webpackbar"));
10
11
  const config_1 = __importDefault(require("../utils/config"));
11
12
  function getPlugins() {
12
- const { userConf, defaultPaths } = config_1.default;
13
- const publicPath = userConf.output && userConf.output.publicPath
14
- ? userConf.output.publicPath
15
- : '/';
13
+ const { userConf } = config_1.default;
16
14
  let plugins = [
17
15
  new webpack_1.IgnorePlugin({
18
16
  resourceRegExp: /^\.\/locale$/,
19
17
  contextRegExp: /moment$/,
20
18
  }),
21
- new webpack_1.ProgressPlugin(),
22
19
  //TODO: check if mini-css-extract-plugin should use base name if enable HMR
23
20
  new mini_css_extract_plugin_1.default({
24
21
  filename: 'css/[name].[contenthash].css',
25
22
  chunkFilename: 'css/[id].[contenthash].css',
26
23
  }),
27
24
  new case_sensitive_paths_webpack_plugin_1.default(),
28
- new html_webpack_plugin_1.default({
29
- template: defaultPaths.html,
30
- title: 'Ko App',
31
- templateParameters: {
32
- configPath: `${publicPath}config/config.js`,
33
- },
34
- inject: 'body',
35
- }),
25
+ new react_refresh_webpack_plugin_1.default(),
26
+ new webpackbar_1.default(),
36
27
  ];
37
28
  plugins = plugins.concat(userConf.plugins || []);
38
29
  if (config_1.default.isProductionEnv) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ko",
3
- "version": "5.3.0",
3
+ "version": "5.3.3",
4
4
  "description": "build & lint library",
5
5
  "keywords": [
6
6
  "ko",
@@ -48,9 +48,7 @@
48
48
  "css-minimizer-webpack-plugin": "^3.4.1",
49
49
  "detect-port": "^1.3.0",
50
50
  "esbuild-loader": "^2.18.0",
51
- "html-webpack-plugin": "^5.5.0",
52
51
  "inquirer": "^8.2.0",
53
- "ko-lints": "^1.0.0",
54
52
  "less": "^3.13.1",
55
53
  "less-loader": "^9.1.0",
56
54
  "mini-css-extract-plugin": "^2.5.3",
@@ -65,7 +63,9 @@
65
63
  "webpack": "^5.69.1",
66
64
  "webpack-bundle-analyzer": "^4.5.0",
67
65
  "webpack-dev-server": "^4.7.4",
68
- "webpack-merge": "^5.8.0"
66
+ "webpack-merge": "^5.8.0",
67
+ "webpackbar": "^5.0.2",
68
+ "worker-loader": "^3.0.8"
69
69
  },
70
70
  "devDependencies": {
71
71
  "@types/case-sensitive-paths-webpack-plugin": "^2.1.6",