You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

166 lines
3.9 KiB

9 years ago
var fs = require('fs')
var zlib = require('zlib')
var rollup = require('rollup')
var uglify = require('uglify-js')
var babel = require('rollup-plugin-babel')
var replace = require('rollup-plugin-replace')
var alias = require('rollup-plugin-alias')
9 years ago
var version = process.env.VERSION || require('../package.json').version
var banner =
'/*!\n' +
' * Vue.js v' + version + '\n' +
9 years ago
' * (c) 2014-' + new Date().getFullYear() + ' Evan You\n' +
9 years ago
' * Released under the MIT License.\n' +
' */'
// update main file
var main = fs
9 years ago
.readFileSync('src/runtime/index.js', 'utf-8')
9 years ago
.replace(/Vue\.version = '[\d\.]+'/, "Vue.version = '" + version + "'")
9 years ago
fs.writeFileSync('src/runtime/index.js', main)
9 years ago
// CommonJS build.
// this is used as the "main" field in package.json
// and used by bundlers like Webpack and Browserify.
9 years ago
// runtime only, because it's meant to be
// used with vue-loader which pre-compiles the template.
9 years ago
rollup.rollup({
9 years ago
entry: 'src/entries/web-runtime.js',
plugins: [babel()]
9 years ago
})
.then(function (bundle) {
9 years ago
var code = bundle.generate({
9 years ago
format: 'cjs',
banner: banner
9 years ago
}).code
return write('dist/vue.common.js', code)
})
// production CommonJS build, just for file size monitoring.
.then(function () {
return rollup.rollup({
9 years ago
entry: 'src/entries/web-runtime',
plugins: [
replace({
'process.env.NODE_ENV': "'production'"
}),
babel()
]
})
}).then(function (bundle) {
// use UMD to wrap the code so that variable names are mangled
// for proper minification size.
var code = bundle.generate({
format: 'umd',
moduleName: 'Vue'
}).code
return write('dist/vue.common.min.js', uglify.minify(code, {
9 years ago
fromString: true,
output: {
ascii_only: true
}
}).code)
9 years ago
})
9 years ago
.then(zip('dist/vue.common.min.js'))
// Compiler CommonJS build.
// Used in Node loaders/transforms.
.then(function () {
return rollup.rollup({
entry: 'src/compiler/index.js',
plugins: [babel()]
})
.then(function (bundle) {
write('dist/compiler/compiler.js', bundle.generate({
format: 'cjs'
}).code)
})
})
9 years ago
// Standalone Dev Build
.then(function () {
return rollup.rollup({
9 years ago
entry: 'src/entries/web-runtime-with-compiler.js',
9 years ago
plugins: [
alias({
entities: './entity-decoder'
}),
9 years ago
replace({
'process.env.NODE_ENV': "'development'"
}),
babel()
]
9 years ago
})
.then(function (bundle) {
return write('dist/vue.js', bundle.generate({
format: 'umd',
banner: banner,
moduleName: 'Vue'
}).code)
})
})
.then(function () {
// Standalone Production Build
return rollup.rollup({
9 years ago
entry: 'src/entries/web-runtime-with-compiler.js',
9 years ago
plugins: [
alias({
entities: './entity-decoder'
}),
9 years ago
replace({
'process.env.NODE_ENV': "'production'"
}),
babel()
]
9 years ago
})
.then(function (bundle) {
var code = bundle.generate({
format: 'umd',
moduleName: 'Vue'
}).code
var minified = banner + '\n' + uglify.minify(code, {
fromString: true,
output: {
ascii_only: true
}
}).code
return write('dist/vue.min.js', minified)
})
9 years ago
.then(zip('dist/vue.min.js'))
9 years ago
})
.catch(logError)
function write (dest, code) {
return new Promise(function (resolve, reject) {
fs.writeFile(dest, code, function (err) {
if (err) return reject(err)
console.log(blue(dest) + ' ' + getSize(code))
resolve()
})
})
}
9 years ago
function zip (file) {
return function () {
return new Promise(function (resolve, reject) {
fs.readFile(file, function (err, buf) {
9 years ago
if (err) return reject(err)
9 years ago
zlib.gzip(buf, function (err, buf) {
if (err) return reject(err)
write(file + '.gz', buf).then(resolve)
})
9 years ago
})
})
9 years ago
}
9 years ago
}
function getSize (code) {
return (code.length / 1024).toFixed(2) + 'kb'
}
function logError (e) {
console.log(e)
}
function blue (str) {
return '\x1b[1m\x1b[34m' + str + '\x1b[39m\x1b[22m'
}