kn-cli 1.0.21 → 1.0.23
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 +1 -0
- package/build/cli.config.js +6 -0
- package/build/postcss.config.js +22 -4
- package/build/webpack.config.js +40 -6
- package/build/writeLog.js +10 -0
- package/package.json +1 -1
- package/readme.md +15 -0
- package/src/build.js +9 -7
package/build/build.sh
CHANGED
package/build/cli.config.js
CHANGED
|
@@ -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:{
|
|
@@ -24,5 +26,9 @@ module.exports = {
|
|
|
24
26
|
// cssSplitMode:false,//false=关闭css文件分隔,将css内置到js内
|
|
25
27
|
// sass:true,//true=开启sass支持,默认仅支持less
|
|
26
28
|
// indexHtml:false,//false=关闭index.html的注入
|
|
29
|
+
// indexHtml:{
|
|
30
|
+
// template:'index_template.html',
|
|
31
|
+
// output:'../index.html',//将index.html输出到 dist目录外的index.html
|
|
32
|
+
// },
|
|
27
33
|
// projectSourceFolder:'./',//项目源代码文件夹所在位置,默认是'src'
|
|
28
34
|
};
|
package/build/postcss.config.js
CHANGED
|
@@ -1,6 +1,24 @@
|
|
|
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
|
+
console.log('关闭pxtorem')
|
|
21
|
+
}
|
|
1
22
|
module.exports = {
|
|
2
|
-
|
|
3
|
-
require('postcss-preset-env'),
|
|
4
|
-
require("postcss-pxtorem")({rootValue:100,propList:['*']})
|
|
5
|
-
]
|
|
23
|
+
plugins
|
|
6
24
|
}
|
package/build/webpack.config.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
}
|
|
@@ -341,11 +365,21 @@ if(indexHtml){
|
|
|
341
365
|
if(jsSplitMode===true || jsSplitMode?.runtime !== false){
|
|
342
366
|
shareJs.splice(0,0,'runtime');
|
|
343
367
|
}
|
|
368
|
+
let index_template = path.join(dirname, 'index.html');
|
|
369
|
+
let index_template_output= 'index.html';
|
|
370
|
+
if(typeof indexHtml ==='object'){
|
|
371
|
+
if(indexHtml.template){
|
|
372
|
+
index_template = path.join(dirname, indexHtml.template);
|
|
373
|
+
}
|
|
374
|
+
if(indexHtml.output){
|
|
375
|
+
index_template_output = indexHtml.output;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
344
378
|
plugins.push(
|
|
345
379
|
new HtmlWebpackPlugin({
|
|
346
380
|
chunks: ['index',...shareJs],
|
|
347
|
-
template:
|
|
348
|
-
filename:
|
|
381
|
+
template: index_template,
|
|
382
|
+
filename: index_template_output,
|
|
349
383
|
inject: true,
|
|
350
384
|
isProd: process.env.build_env == 'prod',
|
|
351
385
|
}),
|
package/package.json
CHANGED
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支持
|
|
@@ -46,6 +47,10 @@ module.exports = {
|
|
|
46
47
|
cssSplitMode:false,//默认:true,false=关闭css文件分隔,将css内置到js内
|
|
47
48
|
sass:true,//默认:false,true=开启sass支持,默认仅支持less
|
|
48
49
|
indexHtml:false,//默认:true,false=关闭index.html的注入
|
|
50
|
+
// indexHtml:{
|
|
51
|
+
// template:'index_template.html',
|
|
52
|
+
// output:'../index.html',//将index.html输出到 dist目录外的index.html
|
|
53
|
+
// },
|
|
49
54
|
projectSourceFolder:'./',//默认:'./public',项目源代码文件夹所在位置,默认是'src'
|
|
50
55
|
site_root_path:'',//默认:'',站点根目录,
|
|
51
56
|
// dist:'dist',// 默认:'dist',编译后文件输出目录
|
|
@@ -53,10 +58,20 @@ module.exports = {
|
|
|
53
58
|
// base:'',
|
|
54
59
|
// js:'',//js输出的目录
|
|
55
60
|
// }
|
|
61
|
+
// pxtorem:false,//默认:true,开启px转rem模式
|
|
56
62
|
};
|
|
57
63
|
```
|
|
58
64
|
|
|
59
65
|
# 更新日志
|
|
66
|
+
* 1.0.23
|
|
67
|
+
1. 修正postcss.config无法正确读取的bug
|
|
68
|
+
2. 增加对pxtorem插件的开关配置
|
|
69
|
+
3. 增加构建日志文件
|
|
70
|
+
4. 增加 cli.config.js内增加name名称配置
|
|
71
|
+
|
|
72
|
+
* 1.0.22
|
|
73
|
+
1. cli.config.js 扩展indexHtml的配置项,详细参考注释
|
|
74
|
+
|
|
60
75
|
* 1.0.21
|
|
61
76
|
1. cli.config.js内扩展了copyFolder配置项目的功能,现在支持更多配置,详细参考注释
|
|
62
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
|
-
|
|
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
|
-
|
|
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
|
|