@codelet/cli-service 0.0.4 → 0.0.6

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/dist/config.d.ts CHANGED
@@ -9,4 +9,6 @@ export interface Config {
9
9
  /** webpack 配置 */
10
10
  webpack?: Configuration;
11
11
  }
12
- export declare function getDefaultConfig(options?: Pick<Config, 'entryPath' | 'source' | 'pageIndex'>): Required<Config>;
12
+ export declare function getDefaultConfig(options?: Pick<Config, 'entryPath' | 'source' | 'pageIndex'> & {
13
+ isDev?: boolean;
14
+ }): Required<Config>;
package/dist/config.js CHANGED
@@ -6,22 +6,65 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getDefaultConfig = void 0;
7
7
  const webpackbar_1 = __importDefault(require("webpackbar"));
8
8
  const mini_css_extract_plugin_1 = __importDefault(require("mini-css-extract-plugin"));
9
+ const hmr_webpack_plugin_1 = __importDefault(require("@codelet/hmr-webpack-plugin"));
9
10
  const inject_chunk_webpack_plugin_1 = __importDefault(require("@codelet/inject-chunk-webpack-plugin"));
10
11
  const app_json_webpack_plugin_1 = __importDefault(require("@codelet/app-json-webpack-plugin"));
11
12
  const terser_webpack_plugin_1 = __importDefault(require("terser-webpack-plugin"));
12
13
  const utils_1 = require("./utils");
13
14
  function getDefaultConfig(options) {
14
- const { entryPath, source, pageIndex } = Object.assign({
15
+ const { entryPath, source, pageIndex, isDev } = Object.assign({
16
+ isDev: false,
15
17
  pageIndex: '',
16
18
  entryPath: './src',
17
19
  source: ['app.(js|ts)', 'pages/**/*.(js|ts)', 'components/**/*.(js|ts)'],
18
20
  }, options);
21
+ // 模式
22
+ const mode = isDev ? 'development' : 'production';
23
+ // 插件
24
+ const plugins = [
25
+ new mini_css_extract_plugin_1.default({
26
+ filename: '[name].wxss',
27
+ }),
28
+ new inject_chunk_webpack_plugin_1.default(),
29
+ new app_json_webpack_plugin_1.default({
30
+ pageIndex,
31
+ }),
32
+ new webpackbar_1.default(),
33
+ ];
34
+ if (isDev) {
35
+ plugins.push(new hmr_webpack_plugin_1.default());
36
+ }
37
+ // 优化
38
+ const optimization = {
39
+ splitChunks: {
40
+ chunks: 'all',
41
+ minChunks: 2,
42
+ minSize: 0,
43
+ cacheGroups: {
44
+ main: {
45
+ name: 'bundle',
46
+ minChunks: 2,
47
+ chunks: 'all',
48
+ },
49
+ },
50
+ },
51
+ };
52
+ // 生产环境
53
+ if (!isDev) {
54
+ optimization.minimize = true;
55
+ optimization.minimizer = [
56
+ new terser_webpack_plugin_1.default({
57
+ // 不生成 license 文件
58
+ extractComments: false,
59
+ }),
60
+ ];
61
+ }
19
62
  return {
20
63
  pageIndex,
21
64
  entryPath,
22
65
  source,
23
66
  webpack: {
24
- mode: 'production',
67
+ mode,
25
68
  devtool: false,
26
69
  output: {
27
70
  filename: '[name].js',
@@ -88,36 +131,8 @@ function getDefaultConfig(options) {
88
131
  },
89
132
  ],
90
133
  },
91
- plugins: [
92
- new mini_css_extract_plugin_1.default({
93
- filename: '[name].wxss',
94
- }),
95
- new inject_chunk_webpack_plugin_1.default(),
96
- new app_json_webpack_plugin_1.default({
97
- pageIndex,
98
- }),
99
- new webpackbar_1.default(),
100
- ],
101
- optimization: {
102
- minimize: true,
103
- minimizer: [
104
- new terser_webpack_plugin_1.default({
105
- extractComments: false, // 不生成 license 文件
106
- }),
107
- ],
108
- splitChunks: {
109
- chunks: 'all',
110
- minChunks: 2,
111
- minSize: 0,
112
- cacheGroups: {
113
- main: {
114
- name: 'bundle',
115
- minChunks: 2,
116
- chunks: 'all',
117
- },
118
- },
119
- },
120
- },
134
+ plugins,
135
+ optimization,
121
136
  },
122
137
  };
123
138
  }
package/dist/utils.d.ts CHANGED
@@ -12,9 +12,11 @@ export declare function parseArgv(argv: string[]): {
12
12
  configPath: string;
13
13
  isWatch: boolean;
14
14
  pageIndex: string;
15
+ isDev: boolean;
15
16
  };
16
17
  export declare function getConfig(options: {
17
18
  configPath: string;
18
19
  isWatch: boolean;
20
+ isDev: boolean;
19
21
  pageIndex: string;
20
22
  }): Configuration;
package/dist/utils.js CHANGED
@@ -36,10 +36,11 @@ function getOptionValue(argv, option) {
36
36
  exports.getOptionValue = getOptionValue;
37
37
  function parseArgv(argv) {
38
38
  const isWatch = argv.includes('--watch');
39
+ const isDev = argv.includes('dev');
39
40
  const pageIndex = getOptionValue(argv, '--pageIndex') || '';
40
41
  const configRelativePath = getOptionValue(argv, '--config') || 'codelet.config.js';
41
42
  const configPath = (0, exports.resolve)(configRelativePath);
42
- return { configPath, isWatch, pageIndex };
43
+ return { configPath, isWatch, pageIndex, isDev };
43
44
  }
44
45
  exports.parseArgv = parseArgv;
45
46
  function getConfig(options) {
@@ -55,6 +56,9 @@ function getConfig(options) {
55
56
  if (options.pageIndex) {
56
57
  cfg.pageIndex = options.pageIndex;
57
58
  }
59
+ if (options.isDev) {
60
+ cfg.isDev = options.isDev;
61
+ }
58
62
  config = (0, config_1.getDefaultConfig)(cfg);
59
63
  config = {
60
64
  ...config,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codelet/cli-service",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "cli-service",
5
5
  "bin": {
6
6
  "codelet-cli-service": "./bin/codelet-cli-service.js"
@@ -39,10 +39,11 @@
39
39
  "webpack": "^5.89.0",
40
40
  "webpack-merge": "^5.10.0",
41
41
  "webpackbar": "^6.0.0",
42
- "@codelet/app-json-webpack-plugin": "^0.0.4",
43
- "@codelet/copy-loader": "^0.0.4",
44
- "@codelet/wxml-loader": "^0.0.4",
45
- "@codelet/inject-chunk-webpack-plugin": "^0.0.4"
42
+ "@codelet/hmr-webpack-plugin": "^0.0.1",
43
+ "@codelet/inject-chunk-webpack-plugin": "^0.0.6",
44
+ "@codelet/app-json-webpack-plugin": "^0.0.6",
45
+ "@codelet/copy-loader": "^0.0.6",
46
+ "@codelet/wxml-loader": "^0.0.6"
46
47
  },
47
48
  "devDependencies": {
48
49
  "rimraf": "^5.0.5"