@@ -12,6 +12,12 @@ let Config = require('./Config.js'),
12
12
13
13
let UtilFs = require ( '../utils/fs.js' ) ;
14
14
15
+ const ENVS = {
16
+ LOCAL : 'local' ,
17
+ DEV : 'dev' ,
18
+ PRD : 'prd' ,
19
+ }
20
+
15
21
class Project {
16
22
constructor ( cwd ) {
17
23
this . cwd = cwd ;
@@ -50,25 +56,26 @@ class Project {
50
56
readConfig ( options ) {
51
57
if ( this . check ( ) ) {
52
58
let userConfig = {
53
- cwd : this . cwd ,
54
- _manager : Manager ,
55
- setConfig : this . config . setCompiler . bind ( this . config ) , // 兼容旧api
56
- setCompile : this . config . setCompiler . bind ( this . config ) , // 兼容旧api
57
- setCompiler : this . config . setCompiler . bind ( this . config ) ,
58
- setExports : this . config . setExports . bind ( this . config ) ,
59
- setGroupExports : this . config . setGroupExports . bind ( this . config ) ,
60
- setSync : this . config . setSync . bind ( this . config ) ,
61
- setCommands : this . setCommands . bind ( this ) ,
62
- setEslintConfig : this . setEslintConfig . bind ( this ) ,
63
- setStylelintConfig : this . setStylelintConfig . bind ( this ) ,
64
- config : this . config . getConfig ( ) ,
65
- commands : this . commands ,
66
- middlewares : this . middlewares ,
67
- packCallbacks : this . packCallbacks ,
68
- eslintConfig : this . eslintConfig ,
69
- stylelintConfig : this . stylelintConfig
70
- } ,
71
- globalConfigs = Manager . readRC ( ) . configs || [ ] ;
59
+ cwd : this . cwd ,
60
+ _manager : Manager ,
61
+ setConfig : this . config . setCompiler . bind ( this . config ) , // 兼容旧api
62
+ setCompile : this . config . setCompiler . bind ( this . config ) , // 兼容旧api
63
+ setCompiler : this . config . setCompiler . bind ( this . config ) ,
64
+ setExports : this . config . setExports . bind ( this . config ) ,
65
+ setGroupExports : this . config . setGroupExports . bind ( this . config ) ,
66
+ setSync : this . config . setSync . bind ( this . config ) ,
67
+ setCommands : this . setCommands . bind ( this ) ,
68
+ setEslintConfig : this . setEslintConfig . bind ( this ) ,
69
+ setStylelintConfig : this . setStylelintConfig . bind ( this ) ,
70
+ config : this . config . getConfig ( ) ,
71
+ commands : this . commands ,
72
+ middlewares : this . middlewares ,
73
+ packCallbacks : this . packCallbacks ,
74
+ eslintConfig : this . eslintConfig ,
75
+ stylelintConfig : this . stylelintConfig ,
76
+ env : this . _getCurrentEnv ( ) , // 默认为本地环境
77
+ } ,
78
+ globalConfigs = Manager . readRC ( ) . configs || [ ] ;
72
79
73
80
this . options = options = options || { } ;
74
81
options . ExtractTextPlugin = ExtractTextPlugin ;
@@ -479,6 +486,18 @@ class Project {
479
486
return false ;
480
487
}
481
488
}
489
+
490
+ _getCurrentEnv ( ) {
491
+ if ( process . argv [ 2 ] === 'pack' ) {
492
+ if ( process . argv . indexOf ( '-m' ) > - 1 ) {
493
+ return ENVS . PRD
494
+ } else {
495
+ return ENVS . DEV
496
+ }
497
+ }
498
+
499
+ return ENVS . LOCAL
500
+ }
482
501
}
483
502
484
503
module . exports = Project ;
0 commit comments