kn-cli 1.0.22 → 1.0.24

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/build/build.sh CHANGED
@@ -3,6 +3,7 @@ then
3
3
  echo "没有发现build_env,默认设置为prod"
4
4
  build_env="prod"
5
5
  fi
6
+ echo "cli build模式强制设定 noSkipNpmInstall=1"
6
7
  export noSkipNpmInstall=1
7
8
  export mock=0
8
9
  export build_type=build
@@ -1,9 +1,11 @@
1
1
 
2
2
  module.exports = {
3
+ name:'projectName',
3
4
  registryType:'npm',//npm镜像源,taobao|npm
4
5
  less:{
5
6
  javascriptEnabled:false,//是否开启less js
6
7
  },
8
+ // pxtorem:false,//默认:true,开启px转rem模式
7
9
  // site_root_path:'/dist/',// 默认:'',站点根目录
8
10
  // 自定义多入口
9
11
  // entry:{
@@ -1,6 +1,23 @@
1
+ const fs = require('fs');
2
+ const writeLog = require('./writeLog.js')()
3
+ writeLog('读取 postcss.config.js');
4
+
5
+
6
+ let CLI_CONFIG = {};
7
+ let existsCli= fs.existsSync('./cli.config.js');
8
+ if(existsCli){
9
+ CLI_CONFIG = require('./cli.config.js');
10
+ }
11
+ const pxtorem = CLI_CONFIG?.pxtorem??true;
12
+ const plugins = [
13
+ require('postcss-preset-env'),
14
+ ];
15
+ if(pxtorem){
16
+ writeLog('启用pxtorem');
17
+ plugins.push( require("postcss-pxtorem")({rootValue:100,propList:['*']}) )
18
+ }else{
19
+ writeLog('关闭pxtorem');
20
+ }
1
21
  module.exports = {
2
- plugins:[
3
- require('postcss-preset-env'),
4
- require("postcss-pxtorem")({rootValue:100,propList:['*']})
5
- ]
22
+ plugins
6
23
  }
@@ -1,5 +1,7 @@
1
1
  const path = require('path');
2
2
  const fs = require('fs');
3
+ const log = require('./writeLog.js')()
4
+ log('==========读取webpack.config.js===========');
3
5
  const webpack = require('webpack');
4
6
  const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
5
7
  const MiniCssExtractPlugin = require('mini-css-extract-plugin');
@@ -204,11 +206,19 @@ const rules= [
204
206
  }
205
207
  },
206
208
  },
207
- 'postcss-loader',
209
+ {
210
+ loader:'postcss-loader',
211
+ options:{
212
+ postcssOptions: {
213
+ config: path.resolve(webpackPath, "postcss.config.js"),
214
+ },
215
+ }
216
+ },
208
217
  {
209
218
  loader: 'less-loader',
210
219
  options:{
211
- javascriptEnabled: CLI_CONFIG?.less?.javascriptEnabled??false
220
+ javascriptEnabled: CLI_CONFIG?.less?.javascriptEnabled??false,
221
+ modifyVars:CLI_CONFIG?.less?.modifyVars??false,
212
222
  }
213
223
  }
214
224
  ],
@@ -220,7 +230,14 @@ const rules= [
220
230
  loader: cssSplitMode?MiniCssExtractPlugin.loader:'style-loader',
221
231
  },
222
232
  'css-loader',
223
- 'postcss-loader'
233
+ {
234
+ loader:'postcss-loader',
235
+ options:{
236
+ postcssOptions: {
237
+ config: path.resolve(webpackPath, "postcss.config.js"),
238
+ },
239
+ }
240
+ },
224
241
  ],
225
242
  },
226
243
  ];
@@ -242,7 +259,14 @@ if(support_sass){
242
259
  }
243
260
  },
244
261
  },
245
- 'postcss-loader',
262
+ {
263
+ loader:'postcss-loader',
264
+ options:{
265
+ postcssOptions: {
266
+ config: path.resolve(webpackPath, "postcss.config.js"),
267
+ },
268
+ }
269
+ },
246
270
  {
247
271
  loader: 'sass-loader',
248
272
  }
@@ -0,0 +1,10 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+
4
+
5
+ module.exports = function(dir='./'){
6
+ const logFile = path.resolve(dir,'cli.log');
7
+ return function(text){
8
+ fs.appendFileSync(logFile,`${text}\n`);
9
+ }
10
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kn-cli",
3
- "version": "1.0.22",
3
+ "version": "1.0.24",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/readme.md CHANGED
@@ -20,6 +20,7 @@
20
20
  # cli.config.js - 构建配置文件
21
21
  ```js
22
22
  module.exports = {
23
+ projectName:'项目名称',
23
24
  registryType:'npm',//默认:npm npm镜像源,taobao|npm
24
25
  less:{
25
26
  javascriptEnabled:false,//默认:false, 是否开启less中对js支持
@@ -57,10 +58,20 @@ module.exports = {
57
58
  // base:'',
58
59
  // js:'',//js输出的目录
59
60
  // }
61
+ // pxtorem:false,//默认:true,开启px转rem模式
60
62
  };
61
63
  ```
62
64
 
63
65
  # 更新日志
66
+ * 1.0.24
67
+ 1. 删除了无用的console.log
68
+
69
+ * 1.0.23
70
+ 1. 修正postcss.config无法正确读取的bug
71
+ 2. 增加对pxtorem插件的开关配置
72
+ 3. 增加构建日志文件
73
+ 4. 增加 cli.config.js内增加name名称配置
74
+
64
75
  * 1.0.22
65
76
  1. cli.config.js 扩展indexHtml的配置项,详细参考注释
66
77
 
package/src/build.js CHANGED
@@ -26,7 +26,14 @@ const ROOT=path.resolve(__dirname,"../");
26
26
  module.exports= async (options={})=> {
27
27
  const {type='dev'} = options;
28
28
  const projectPath = process.cwd();
29
- const projectName = path.parse(projectPath).base;
29
+
30
+ const cliConfigJs = path.resolve(projectPath,'cli.config.js');
31
+ let existsCli= fs.existsSync(cliConfigJs);
32
+ let cliConfig;
33
+ if(existsCli){
34
+ cliConfig= require(cliConfigJs);
35
+ }
36
+ const projectName = cliConfig?.name??path.parse(projectPath).base;
30
37
 
31
38
  // 用户项目文件夹下的public目录
32
39
  const sourceDir = path.resolve(projectPath,'public');
@@ -39,12 +46,7 @@ module.exports= async (options={})=> {
39
46
  const tempWebpackPackagePath = path.resolve(tempWebpackDir,'package.json');
40
47
  const tempWebpackConfigPath = path.resolve(tempWebpackDir,'webpack.config.js');
41
48
  const tempStartShell = path.resolve(tempWebpackDir,'start.sh');
42
- const cliConfigJs = path.resolve(projectPath,'cli.config.js');
43
- let existsCli= fs.existsSync(cliConfigJs);
44
- let cliConfig;
45
- if(existsCli){
46
- cliConfig= require(cliConfigJs);
47
- }
49
+
48
50
 
49
51
  let projectPackage,webpackPackage;
50
52