mirror of
https://gitee.com/vuejs/vue.git
synced 2024-11-30 02:57:43 +08:00
improve build script
This commit is contained in:
parent
ae881f514b
commit
82bbbcfb83
187
build/build.js
187
build/build.js
@ -14,119 +14,104 @@ var banner =
|
|||||||
' * Released under the MIT License.\n' +
|
' * Released under the MIT License.\n' +
|
||||||
' */'
|
' */'
|
||||||
|
|
||||||
// update main file
|
// Update main file
|
||||||
var main = fs
|
var main = fs
|
||||||
.readFileSync('src/runtime/index.js', 'utf-8')
|
.readFileSync('src/runtime/index.js', 'utf-8')
|
||||||
.replace(/Vue\.version = '[\d\.]+'/, "Vue.version = '" + version + "'")
|
.replace(/Vue\.version = '[\d\.]+'/, "Vue.version = '" + version + "'")
|
||||||
fs.writeFileSync('src/runtime/index.js', main)
|
fs.writeFileSync('src/runtime/index.js', main)
|
||||||
|
|
||||||
// CommonJS build.
|
build([
|
||||||
// this is used as the "main" field in package.json
|
// Runtime only, CommonJS build. Used by bundlers e.g. Webpack & Browserify
|
||||||
// and used by bundlers like Webpack and Browserify.
|
{
|
||||||
// runtime only, because it's meant to be
|
entry: 'src/entries/web-runtime.js',
|
||||||
// used with vue-loader which pre-compiles the template.
|
|
||||||
rollup.rollup({
|
|
||||||
entry: 'src/entries/web-runtime.js',
|
|
||||||
plugins: [babel()]
|
|
||||||
})
|
|
||||||
.then(function (bundle) {
|
|
||||||
var code = bundle.generate({
|
|
||||||
format: 'cjs',
|
format: 'cjs',
|
||||||
banner: banner
|
out: 'dist/vue.common.js'
|
||||||
}).code
|
},
|
||||||
return write('dist/vue.common.js', code)
|
// Minified runtime, only for filze size monitoring
|
||||||
})
|
{
|
||||||
// production CommonJS build, just for file size monitoring.
|
entry: 'src/entries/web-runtime.js',
|
||||||
.then(function () {
|
|
||||||
return rollup.rollup({
|
|
||||||
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',
|
format: 'umd',
|
||||||
moduleName: 'Vue'
|
env: 'production',
|
||||||
}).code
|
out: 'dist/vue.common.min.js'
|
||||||
return write('dist/vue.common.min.js', uglify.minify(code, {
|
},
|
||||||
fromString: true,
|
// Runtime+compiler standalone developement build.
|
||||||
output: {
|
{
|
||||||
ascii_only: true
|
entry: 'src/entries/web-runtime-with-compiler.js',
|
||||||
|
format: 'umd',
|
||||||
|
env: 'development',
|
||||||
|
out: 'dist/vue.js',
|
||||||
|
banner: true,
|
||||||
|
alias: {
|
||||||
|
entities: './entity-decoder'
|
||||||
}
|
}
|
||||||
}).code)
|
},
|
||||||
})
|
// Runtime+compiler standalone production build.
|
||||||
.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)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
// Standalone Dev Build
|
|
||||||
.then(function () {
|
|
||||||
return rollup.rollup({
|
|
||||||
entry: 'src/entries/web-runtime-with-compiler.js',
|
entry: 'src/entries/web-runtime-with-compiler.js',
|
||||||
plugins: [
|
format: 'umd',
|
||||||
alias({
|
env: 'production',
|
||||||
entities: './entity-decoder'
|
out: 'dist/vue.min.js',
|
||||||
}),
|
banner: true,
|
||||||
replace({
|
alias: {
|
||||||
'process.env.NODE_ENV': "'development'"
|
entities: './entity-decoder'
|
||||||
}),
|
}
|
||||||
babel()
|
},
|
||||||
]
|
// Compiler standalone build, for npm distribution.
|
||||||
})
|
{
|
||||||
.then(function (bundle) {
|
entry: 'src/compiler/index',
|
||||||
return write('dist/vue.js', bundle.generate({
|
format: 'cjs',
|
||||||
format: 'umd',
|
external: ['entities'],
|
||||||
banner: banner,
|
out: 'dist/compiler/compiler.js'
|
||||||
moduleName: 'Vue'
|
}
|
||||||
}).code)
|
])
|
||||||
})
|
|
||||||
})
|
function build (builds) {
|
||||||
.then(function () {
|
var built = 0
|
||||||
// Standalone Production Build
|
var total = builds.length
|
||||||
return rollup.rollup({
|
next()
|
||||||
entry: 'src/entries/web-runtime-with-compiler.js',
|
function next () {
|
||||||
plugins: [
|
buildEntry(builds[built]).then(function () {
|
||||||
alias({
|
built++
|
||||||
entities: './entity-decoder'
|
if (built < total) {
|
||||||
}),
|
next()
|
||||||
replace({
|
|
||||||
'process.env.NODE_ENV': "'production'"
|
|
||||||
}),
|
|
||||||
babel()
|
|
||||||
]
|
|
||||||
})
|
|
||||||
.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
|
|
||||||
}
|
}
|
||||||
|
}).catch(logError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildEntry (opts) {
|
||||||
|
var plugins = [babel()]
|
||||||
|
if (opts.env) {
|
||||||
|
plugins.push(replace({
|
||||||
|
'process.env.NODE_ENV': JSON.stringify(opts.env)
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
if (opts.alias) {
|
||||||
|
plugins.push(alias(opts.alias))
|
||||||
|
}
|
||||||
|
return rollup.rollup({
|
||||||
|
entry: opts.entry,
|
||||||
|
plugins: plugins,
|
||||||
|
external: opts.external
|
||||||
|
}).then(function (bundle) {
|
||||||
|
var code = bundle.generate({
|
||||||
|
format: opts.format,
|
||||||
|
moduleName: 'Vue',
|
||||||
|
banner: opts.banner ? banner : null
|
||||||
}).code
|
}).code
|
||||||
return write('dist/vue.min.js', minified)
|
if (opts.env === 'production') {
|
||||||
|
var minified = (opts.banner ? banner + '\n' : '') + uglify.minify(code, {
|
||||||
|
fromString: true,
|
||||||
|
output: {
|
||||||
|
ascii_only: true
|
||||||
|
}
|
||||||
|
}).code
|
||||||
|
return write(opts.out, minified).then(zip(opts.out))
|
||||||
|
} else {
|
||||||
|
return write(opts.out, code)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.then(zip('dist/vue.min.js'))
|
}
|
||||||
})
|
|
||||||
.catch(logError)
|
|
||||||
|
|
||||||
function write (dest, code) {
|
function write (dest, code) {
|
||||||
return new Promise(function (resolve, reject) {
|
return new Promise(function (resolve, reject) {
|
||||||
|
Loading…
Reference in New Issue
Block a user