Skip to content

Commit 2017704

Browse files
committed
switch to webpack build
1 parent f15dc32 commit 2017704

File tree

6 files changed

+52
-77
lines changed

6 files changed

+52
-77
lines changed

grunt/shared-build.js

Lines changed: 14 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2,67 +2,27 @@
22
* Shared build function
33
*/
44

5-
var resolve = require('component-resolver')
6-
var build = require('component-builder')
7-
85
module.exports = function (grunt, cb) {
96

10-
var license =
7+
var webpack = require('webpack')
8+
var banner =
119
'/**\n' +
1210
' * Vue.js v' + grunt.config.get('version') + '\n' +
1311
' * (c) ' + new Date().getFullYear() + ' Evan You\n' +
1412
' * Released under the MIT License.\n' +
1513
' */\n'
1614

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)
5727

58-
function shortenPaths (js) {
59-
var seen = {}
60-
var count = 0
61-
return js.replace(/'vue\/src\/(.+?)'|"vue\/src\/(.+?)"/g, function (path) {
62-
path = path.slice(1, -1)
63-
if (!seen[path]) {
64-
seen[path] = ++count
65-
}
66-
return seen[path]
67-
})
6828
}

grunt/tasks/build-test.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
1+
/**
2+
* Build `test/unit/specs.js` which is used in
3+
* `test/unit/runner.html`
4+
*/
5+
16
module.exports = function (grunt) {
27
grunt.registerTask('build-test', function () {
3-
var done = this.async()
4-
var fs = require('fs')
5-
var browserify = require('browserify')
8+
var webpack = require('webpack')
69
var files = grunt.file.expand(['test/unit/specs/**/*.js'])
710
.map(function (file) {
811
return './' + file
912
})
10-
browserify(files)
11-
.bundle()
12-
.pipe(fs.createWriteStream('test/unit/specs.js'))
13-
.on('close', done)
13+
webpack({
14+
entry: files,
15+
output: {
16+
path: './test/unit',
17+
filename: 'specs.js'
18+
}
19+
}, this.async())
1420
})
1521
}

grunt/tasks/build.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* Build, update component.json, uglify, and report size.
3+
*/
4+
15
module.exports = function (grunt) {
26
grunt.registerTask('build', function () {
37

@@ -19,8 +23,10 @@ module.exports = function (grunt) {
1923
grunt.file.write('component.json', JSON.stringify(component, null, 2))
2024

2125
// then build
22-
build(grunt, function (js) {
23-
write('dist/vue.js', js)
26+
build(grunt, function (err) {
27+
if (err) return done(err)
28+
var js = fs.readFileSync('dist/vue.js', 'utf-8')
29+
report('dist/vue.js', js)
2430
// uglify
2531
var result = uglifyjs.minify(js, {
2632
fromString: true,
@@ -42,12 +48,16 @@ module.exports = function (grunt) {
4248
// report gzip size
4349
zlib.gzip(result.code, function (err, buf) {
4450
write('dist/vue.min.js.gz', buf)
45-
done()
51+
done(err)
4652
})
4753
})
4854

49-
function write (path, file, report) {
55+
function write (path, file) {
5056
fs.writeFileSync(path, file)
57+
report(path, file)
58+
}
59+
60+
function report (path, file) {
5161
console.log(
5262
blue(path + ': ') +
5363
(file.length / 1024).toFixed(2) + 'kb'

grunt/tasks/casper.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
var path = require('path')
1+
/**
2+
* Run e2e tests with CasperJS.
3+
*/
24

35
module.exports = function (grunt) {
46
grunt.registerTask( 'casper', function (id) {
7+
var path = require('path')
58
var done = this.async()
69
var file = id ? id + '.js' : ''
710
grunt.util.spawn({

grunt/tasks/dev.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1+
/**
2+
* Simple development build to be run with grunt watch.
3+
*/
4+
15
module.exports = function (grunt) {
26
grunt.registerTask('dev', function () {
3-
var done = this.async()
4-
var fs = require('fs')
5-
var build = require('../shared-build')
6-
build(grunt, function (js) {
7-
fs.writeFileSync('dist/vue.js', js)
8-
done()
9-
})
7+
require('../shared-build')(grunt, this.async())
108
})
119
}

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
"test": "grunt ci"
2121
},
2222
"devDependencies": {
23-
"browserify": "^5.11.0",
24-
"component-builder": "^1.1.10",
25-
"component-resolver": "^1.1.8",
2623
"grunt": "^0.4.5",
2724
"grunt-contrib-jshint": "^0.10.0",
2825
"grunt-contrib-watch": "^0.6.1",
@@ -37,6 +34,7 @@
3734
"karma-jasmine": "^0.2.2",
3835
"karma-phantomjs-launcher": "^0.1.4",
3936
"karma-sauce-launcher": "^0.2.10",
40-
"uglify-js": "^2.4.15"
37+
"uglify-js": "^2.4.15",
38+
"webpack": "^1.4.4"
4139
}
4240
}

0 commit comments

Comments
 (0)