2
2
* Shared build function
3
3
*/
4
4
5
- var resolve = require ( 'component-resolver' )
6
- var build = require ( 'component-builder' )
7
-
8
5
module . exports = function ( grunt , cb ) {
9
6
10
- var license =
7
+ var webpack = require ( 'webpack' )
8
+ var banner =
11
9
'/**\n' +
12
10
' * Vue.js v' + grunt . config . get ( 'version' ) + '\n' +
13
11
' * (c) ' + new Date ( ) . getFullYear ( ) + ' Evan You\n' +
14
12
' * Released under the MIT License.\n' +
15
13
' */\n'
16
14
17
- // build with component-builder
18
- resolve ( process . cwd ( ) , { } , function ( err , tree ) {
19
- build . scripts ( tree )
20
- . use ( 'scripts' , build . plugins . js ( ) )
21
- . end ( function ( err , js ) {
22
- // wrap with umd
23
- js = umd ( js )
24
- // replace require paths with numbers for file size
25
- js = shortenPaths ( js )
26
- // add license
27
- js = license + js
28
- // done
29
- cb ( js )
30
- } )
31
- } )
32
- }
33
-
34
- /**
35
- * component's umd wrapper throws error in strict mode
36
- * so we have to roll our own
37
- */
38
-
39
- function umd ( js ) {
40
- return '\n;(function(){\n\n'
41
- + '"use strict"\n\n'
42
- + build . scripts . require
43
- + js
44
- + 'if (typeof exports == "object") {\n'
45
- + ' module.exports = require("vue");\n'
46
- + '} else if (typeof define == "function" && define.amd) {\n'
47
- + ' define([], function(){ return require("vue"); });\n'
48
- + '} else {\n'
49
- + ' window.Vue = require("vue");\n'
50
- + '}\n'
51
- + '})()\n' ;
52
- }
53
-
54
- /**
55
- * Shorten require() paths for smaller file size
56
- */
15
+ webpack ( {
16
+ entry : './src/vue' ,
17
+ output : {
18
+ path : './dist' ,
19
+ filename : 'vue.js' ,
20
+ library : 'Vue' ,
21
+ libraryTarget : 'umd'
22
+ } ,
23
+ plugins : [
24
+ new webpack . BannerPlugin ( banner , { raw : true } )
25
+ ]
26
+ } , cb )
57
27
58
- function shortenPaths ( js ) {
59
- var seen = { }
60
- var count = 0
61
- return js . replace ( / ' v u e \/ s r c \/ ( .+ ?) ' | " v u e \/ s r c \/ ( .+ ?) " / g, function ( path ) {
62
- path = path . slice ( 1 , - 1 )
63
- if ( ! seen [ path ] ) {
64
- seen [ path ] = ++ count
65
- }
66
- return seen [ path ]
67
- } )
68
28
}
0 commit comments