1
- var fs = require ( 'fs' )
2
- var zlib = require ( 'zlib' )
3
- var rollup = require ( 'rollup' )
4
- var uglify = require ( 'uglify-js' )
5
- var babel = require ( 'rollup-plugin-babel' )
6
- var replace = require ( 'rollup-plugin-replace' )
7
- var aliasPlugin = require ( 'rollup-plugin-alias' )
8
- var baseAlias = require ( './alias' )
9
- var version = process . env . VERSION || require ( '../package.json' ) . version
1
+ const fs = require ( 'fs' )
2
+ const path = require ( 'path' )
3
+ const zlib = require ( 'zlib' )
4
+ const rollup = require ( 'rollup' )
5
+ const uglify = require ( 'uglify-js' )
10
6
11
7
if ( ! fs . existsSync ( 'dist' ) ) {
12
8
fs . mkdirSync ( 'dist' )
13
9
}
14
10
15
- var banner =
16
- '/*!\n' +
17
- ' * Vue.js v' + version + '\n' +
18
- ' * (c) 2014-' + new Date ( ) . getFullYear ( ) + ' Evan You\n' +
19
- ' * Released under the MIT License.\n' +
20
- ' */'
21
-
22
11
// Update main file
23
- var main = fs
12
+ const version = process . env . VERSION || require ( '../package.json' ) . version
13
+ const main = fs
24
14
. readFileSync ( 'src/core/index.js' , 'utf-8' )
25
15
. replace ( / V u e \. v e r s i o n = ' [ ^ ' ] + ' / , "Vue.version = '" + version + "'" )
26
16
fs . writeFileSync ( 'src/core/index.js' , main )
27
17
28
- var builds = [
29
- // Runtime only (CommonJS). Used by bundlers e.g. Webpack & Browserify
30
- {
31
- entry : 'src/entries/web-runtime.js' ,
32
- format : 'cjs' ,
33
- out : 'dist/vue.common.js'
34
- } ,
35
- // Minified runtime, only for filze size monitoring
36
- {
37
- entry : 'src/entries/web-runtime.js' ,
38
- format : 'umd' ,
39
- env : 'production' ,
40
- out : 'dist/vue.common.min.js'
41
- } ,
42
- // Runtime+compiler standalone developement build.
43
- {
44
- entry : 'src/entries/web-runtime-with-compiler.js' ,
45
- format : 'umd' ,
46
- env : 'development' ,
47
- out : 'dist/vue.js' ,
48
- banner : true ,
49
- alias : {
50
- entities : './entity-decoder'
51
- }
52
- } ,
53
- // Runtime+compiler standalone production build.
54
- {
55
- entry : 'src/entries/web-runtime-with-compiler.js' ,
56
- format : 'umd' ,
57
- env : 'production' ,
58
- out : 'dist/vue.min.js' ,
59
- banner : true ,
60
- alias : {
61
- entities : './entity-decoder'
62
- }
63
- } ,
64
- // Web compiler (CommonJS).
65
- {
66
- entry : 'src/entries/web-compiler.js' ,
67
- format : 'cjs' ,
68
- external : [ 'entities' , 'de-indent' ] ,
69
- out : 'packages/vue-template-compiler/build.js'
70
- } ,
71
- // Web server renderer (CommonJS).
72
- {
73
- entry : 'src/entries/web-server-renderer.js' ,
74
- format : 'cjs' ,
75
- external : [ 'stream' , 'module' , 'vm' , 'entities' , 'de-indent' ] ,
76
- out : 'packages/vue-server-renderer/build.js'
77
- }
78
- ]
18
+ let builds = require ( './config' ) . getAllBuilds ( )
79
19
80
20
// filter builds via command line arg
81
21
if ( process . argv [ 2 ] ) {
82
- var filters = process . argv [ 2 ] . split ( ',' )
22
+ const filters = process . argv [ 2 ] . split ( ',' )
83
23
builds = builds . filter ( b => {
84
- return filters . some ( f => b . out . indexOf ( f ) > - 1 )
24
+ return filters . some ( f => b . dest . indexOf ( f ) > - 1 )
85
25
} )
86
26
}
87
27
88
28
build ( builds )
89
29
90
30
function build ( builds ) {
91
- var built = 0
92
- var total = builds . length
93
- next ( )
94
- function next ( ) {
95
- buildEntry ( builds [ built ] ) . then ( function ( ) {
31
+ let built = 0
32
+ const total = builds . length
33
+ const next = ( ) => {
34
+ buildEntry ( builds [ built ] ) . then ( ( ) => {
96
35
built ++
97
36
if ( built < total ) {
98
37
next ( )
99
38
}
100
39
} ) . catch ( logError )
101
40
}
41
+
42
+ next ( )
102
43
}
103
44
104
- function buildEntry ( opts ) {
105
- var plugins = [ babel ( ) ]
106
- if ( opts . env ) {
107
- plugins . push ( replace ( {
108
- 'process.env.NODE_ENV' : JSON . stringify ( opts . env ) ,
109
- 'process.env.VUE_ENV' : JSON . stringify ( 'client' )
110
- } ) )
111
- }
112
- var alias = baseAlias
113
- if ( opts . alias ) {
114
- alias = Object . assign ( { } , baseAlias , opts . alias )
115
- }
116
- plugins . push ( aliasPlugin ( alias ) )
117
- return rollup . rollup ( {
118
- entry : opts . entry ,
119
- plugins : plugins ,
120
- external : opts . external
121
- } ) . then ( function ( bundle ) {
122
- var code = bundle . generate ( {
123
- format : opts . format ,
124
- moduleName : 'Vue' ,
125
- banner : opts . banner ? banner : null
126
- } ) . code
127
- if ( opts . env === 'production' ) {
128
- var minified = ( opts . banner ? banner + '\n' : '' ) + uglify . minify ( code , {
45
+ function buildEntry ( config ) {
46
+ const isProd = / m i n \. j s $ / . test ( config . dest )
47
+ return rollup . rollup ( config ) . then ( bundle => {
48
+ const code = bundle . generate ( config ) . code
49
+ if ( isProd ) {
50
+ var minified = ( config . banner ? config . banner + '\n' : '' ) + uglify . minify ( code , {
129
51
fromString : true ,
130
52
output : {
131
53
screw_ie8 : true ,
@@ -135,9 +57,9 @@ function buildEntry (opts) {
135
57
pure_funcs : [ 'makeMap' ]
136
58
}
137
59
} ) . code
138
- return write ( opts . out , minified ) . then ( zip ( opts . out ) )
60
+ return write ( config . dest , minified ) . then ( zip ( config . dest ) )
139
61
} else {
140
- return write ( opts . out , code )
62
+ return write ( config . dest , code )
141
63
}
142
64
} )
143
65
}
@@ -146,7 +68,7 @@ function write (dest, code) {
146
68
return new Promise ( function ( resolve , reject ) {
147
69
fs . writeFile ( dest , code , function ( err ) {
148
70
if ( err ) return reject ( err )
149
- console . log ( blue ( dest ) + ' ' + getSize ( code ) )
71
+ console . log ( blue ( path . relative ( process . cwd ( ) , dest ) ) + ' ' + getSize ( code ) )
150
72
resolve ( )
151
73
} )
152
74
} )
0 commit comments