@codelet/cli-service 0.0.2 → 0.0.4

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
@@ -1,10 +1,12 @@
1
1
  import type { Configuration } from 'webpack';
2
- export interface Config extends Configuration {
2
+ export interface Config {
3
3
  /** 开发路径默认 src */
4
4
  entryPath?: string;
5
+ /** 入口文件 */
5
6
  source?: string[];
7
+ /** 第一页 */
8
+ pageIndex?: string;
9
+ /** webpack 配置 */
10
+ webpack?: Configuration;
6
11
  }
7
- export declare function getDefaultConfig(): Configuration & {
8
- entryPath: string;
9
- source: string[];
10
- };
12
+ export declare function getDefaultConfig(options?: Pick<Config, 'entryPath' | 'source' | 'pageIndex'>): Required<Config>;
package/dist/config.js CHANGED
@@ -10,102 +10,111 @@ const inject_chunk_webpack_plugin_1 = __importDefault(require("@codelet/inject-c
10
10
  const app_json_webpack_plugin_1 = __importDefault(require("@codelet/app-json-webpack-plugin"));
11
11
  const terser_webpack_plugin_1 = __importDefault(require("terser-webpack-plugin"));
12
12
  const utils_1 = require("./utils");
13
- function getDefaultConfig() {
14
- const entryPath = './src';
13
+ function getDefaultConfig(options) {
14
+ const { entryPath, source, pageIndex } = Object.assign({
15
+ pageIndex: '',
16
+ entryPath: './src',
17
+ source: ['app.(js|ts)', 'pages/**/*.(js|ts)', 'components/**/*.(js|ts)'],
18
+ }, options);
15
19
  return {
20
+ pageIndex,
16
21
  entryPath,
17
- source: ['app.(js|ts)', 'pages/**/*.(js|ts)', 'components/**/*.(js|ts)'],
18
- mode: 'production',
19
- devtool: false,
20
- output: {
21
- filename: '[name].js',
22
- path: (0, utils_1.resolve)('dist'),
23
- publicPath: '/',
24
- clean: true,
25
- },
26
- resolve: {
27
- alias: {
28
- '@': (0, utils_1.resolve)('src'),
22
+ source,
23
+ webpack: {
24
+ mode: 'production',
25
+ devtool: false,
26
+ output: {
27
+ filename: '[name].js',
28
+ path: (0, utils_1.resolve)('dist'),
29
+ publicPath: '/',
30
+ clean: true,
29
31
  },
30
- extensions: ['.js', '.ts'],
31
- },
32
- module: {
33
- rules: [
34
- {
35
- oneOf: [
36
- {
37
- test: /\.(css|wxss)$/,
38
- use: [mini_css_extract_plugin_1.default.loader, 'css-loader'],
39
- },
40
- {
41
- test: /\.s(a|c)ss$/,
42
- use: [mini_css_extract_plugin_1.default.loader, 'css-loader', 'sass-loader'],
43
- },
44
- {
45
- test: /\.(wxml|html)$/,
46
- loader: '@codelet/wxml-loader',
47
- options: {
48
- entryPath,
32
+ resolve: {
33
+ alias: {
34
+ '@': (0, utils_1.resolve)('src'),
35
+ },
36
+ extensions: ['.js', '.ts'],
37
+ },
38
+ module: {
39
+ rules: [
40
+ {
41
+ oneOf: [
42
+ {
43
+ test: /\.(css|wxss)$/,
44
+ use: [mini_css_extract_plugin_1.default.loader, 'css-loader'],
49
45
  },
50
- },
51
- {
52
- test: /\.wxs$/,
53
- loader: '@codelet/copy-loader',
54
- options: {
55
- entryPath,
46
+ {
47
+ test: /\.s(a|c)ss$/,
48
+ use: [mini_css_extract_plugin_1.default.loader, 'css-loader', 'sass-loader'],
56
49
  },
57
- },
58
- {
59
- test: /\.json$/,
60
- type: 'javascript/auto',
61
- loader: '@codelet/copy-loader',
62
- options: {
63
- entryPath,
50
+ {
51
+ test: /\.(wxml|html)$/,
52
+ loader: '@codelet/wxml-loader',
53
+ options: {
54
+ entryPath,
55
+ },
64
56
  },
65
- },
66
- {
67
- test: /\.(png|jpe?g|gif|svg)$/,
68
- type: 'asset/resource',
69
- generator: {
70
- filename: 'assets/images/[name][ext]',
57
+ {
58
+ test: /\.wxs$/,
59
+ loader: '@codelet/copy-loader',
60
+ options: {
61
+ entryPath,
62
+ },
71
63
  },
72
- },
73
- {
74
- test: /\.(ts|js)$/,
75
- loader: 'babel-loader',
76
- options: {
77
- cacheDirectory: true, // 开启 babel 缓存
78
- cacheCompression: false, // 关闭缓存文件压缩
64
+ {
65
+ test: /\.json$/,
66
+ type: 'javascript/auto',
67
+ loader: '@codelet/copy-loader',
68
+ options: {
69
+ entryPath,
70
+ },
79
71
  },
80
- },
81
- ],
82
- },
83
- ],
84
- },
85
- plugins: [
86
- new mini_css_extract_plugin_1.default({
87
- filename: '[name].wxss',
88
- }),
89
- new inject_chunk_webpack_plugin_1.default(),
90
- new app_json_webpack_plugin_1.default(),
91
- new webpackbar_1.default(),
92
- ],
93
- optimization: {
94
- minimize: true,
95
- minimizer: [
96
- new terser_webpack_plugin_1.default({
97
- extractComments: false, // 不生成 license 文件
72
+ {
73
+ test: /\.(png|jpe?g|gif|svg)$/,
74
+ type: 'asset/resource',
75
+ generator: {
76
+ filename: 'assets/images/[name][ext]',
77
+ },
78
+ },
79
+ {
80
+ test: /\.(ts|js)$/,
81
+ loader: 'babel-loader',
82
+ options: {
83
+ cacheDirectory: true, // 开启 babel 缓存
84
+ cacheCompression: false, // 关闭缓存文件压缩
85
+ },
86
+ },
87
+ ],
88
+ },
89
+ ],
90
+ },
91
+ plugins: [
92
+ new mini_css_extract_plugin_1.default({
93
+ filename: '[name].wxss',
98
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(),
99
100
  ],
100
- splitChunks: {
101
- chunks: 'all',
102
- minChunks: 2,
103
- minSize: 0,
104
- cacheGroups: {
105
- main: {
106
- name: 'bundle',
107
- minChunks: 2,
108
- chunks: 'all',
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
+ },
109
118
  },
110
119
  },
111
120
  },
package/dist/utils.d.ts CHANGED
@@ -11,8 +11,10 @@ export declare function getOptionValue(argv: string[], option: string): string |
11
11
  export declare function parseArgv(argv: string[]): {
12
12
  configPath: string;
13
13
  isWatch: boolean;
14
+ pageIndex: string;
14
15
  };
15
16
  export declare function getConfig(options: {
16
17
  configPath: string;
17
18
  isWatch: boolean;
19
+ pageIndex: string;
18
20
  }): Configuration;
package/dist/utils.js CHANGED
@@ -36,34 +36,44 @@ function getOptionValue(argv, option) {
36
36
  exports.getOptionValue = getOptionValue;
37
37
  function parseArgv(argv) {
38
38
  const isWatch = argv.includes('--watch');
39
+ const pageIndex = getOptionValue(argv, '--pageIndex') || '';
39
40
  const configRelativePath = getOptionValue(argv, '--config') || 'codelet.config.js';
40
41
  const configPath = (0, exports.resolve)(configRelativePath);
41
- return { configPath, isWatch };
42
+ return { configPath, isWatch, pageIndex };
42
43
  }
43
44
  exports.parseArgv = parseArgv;
44
45
  function getConfig(options) {
45
46
  const { configPath, isWatch } = options;
46
- let config = (0, config_1.getDefaultConfig)();
47
+ let config;
47
48
  if (fs_1.default.existsSync(configPath)) {
48
- const options = require(configPath);
49
- if (typeof options === 'function') {
50
- config = options(config);
49
+ const cfg = require(configPath);
50
+ if (typeof cfg === 'function') {
51
+ config = (0, config_1.getDefaultConfig)(options);
52
+ config = cfg(config);
51
53
  }
52
54
  else {
53
- if (options.source) {
54
- delete config.source;
55
+ if (options.pageIndex) {
56
+ cfg.pageIndex = options.pageIndex;
55
57
  }
56
- config = (0, webpack_merge_1.default)(config, options);
58
+ config = (0, config_1.getDefaultConfig)(cfg);
59
+ config = {
60
+ ...config,
61
+ ...cfg,
62
+ ...(0, webpack_merge_1.default)(config.webpack ?? {}, cfg.webpack ?? {}),
63
+ };
57
64
  }
58
65
  }
59
- const { entryPath, source, ...rest } = config;
60
- if (!rest.entry) {
66
+ else {
67
+ config = (0, config_1.getDefaultConfig)(options);
68
+ }
69
+ const { entryPath, source, webpack } = config;
70
+ if (!webpack.entry) {
61
71
  const { entry } = (0, exports.parseDir)(entryPath, source);
62
- rest.entry = entry;
72
+ webpack.entry = entry;
63
73
  }
64
74
  if (isWatch) {
65
- rest.watch = true;
75
+ webpack.watch = true;
66
76
  }
67
- return rest;
77
+ return webpack;
68
78
  }
69
79
  exports.getConfig = getConfig;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codelet/cli-service",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "cli-service",
5
5
  "bin": {
6
6
  "codelet-cli-service": "./bin/codelet-cli-service.js"
@@ -35,13 +35,14 @@
35
35
  "mini-css-extract-plugin": "^2.7.7",
36
36
  "sass": "^1.69.7",
37
37
  "sass-loader": "^13.3.3",
38
+ "terser-webpack-plugin": "^5.3.10",
38
39
  "webpack": "^5.89.0",
39
40
  "webpack-merge": "^5.10.0",
40
41
  "webpackbar": "^6.0.0",
41
- "@codelet/inject-chunk-webpack-plugin": "^0.0.2",
42
- "@codelet/app-json-webpack-plugin": "^0.0.2",
43
- "@codelet/wxml-loader": "^0.0.2",
44
- "@codelet/copy-loader": "^0.0.2"
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"
45
46
  },
46
47
  "devDependencies": {
47
48
  "rimraf": "^5.0.5"
@@ -49,6 +50,7 @@
49
50
  "scripts": {
50
51
  "build": "npm run clean && tsc -p ./tsconfig.lib.json",
51
52
  "clean": "rimraf ./dist",
53
+ "sync": "dsc sync",
52
54
  "release": "npm run build && dsc publish --pnpm"
53
55
  }
54
56
  }