Przeglądaj źródła

build adjustments

Evan You 9 lat temu
rodzic
commit
961d109148

+ 0 - 12
build/alias.js

@@ -1,12 +0,0 @@
-var path = require('path')
-
-module.exports = {
-  vue: path.resolve(__dirname, '../src/entries/web-runtime-with-compiler'),
-  compiler: path.resolve(__dirname, '../src/compiler'),
-  core: path.resolve(__dirname, '../src/core'),
-  shared: path.resolve(__dirname, '../src/shared'),
-  web: path.resolve(__dirname, '../src/platforms/web'),
-  server: path.resolve(__dirname, '../src/server'),
-  entries: path.resolve(__dirname, '../src/entries'),
-  sfc: path.resolve(__dirname, '../src/sfc')
-}

+ 25 - 103
build/build.js

@@ -1,131 +1,53 @@
-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 aliasPlugin = require('rollup-plugin-alias')
-var baseAlias = require('./alias')
-var version = process.env.VERSION || require('../package.json').version
+const fs = require('fs')
+const path = require('path')
+const zlib = require('zlib')
+const rollup = require('rollup')
+const uglify = require('uglify-js')
 
 if (!fs.existsSync('dist')) {
   fs.mkdirSync('dist')
 }
 
-var banner =
-  '/*!\n' +
-  ' * Vue.js v' + version + '\n' +
-  ' * (c) 2014-' + new Date().getFullYear() + ' Evan You\n' +
-  ' * Released under the MIT License.\n' +
-  ' */'
-
 // Update main file
-var main = fs
+const version = process.env.VERSION || require('../package.json').version
+const main = fs
   .readFileSync('src/core/index.js', 'utf-8')
   .replace(/Vue\.version = '[^']+'/, "Vue.version = '" + version + "'")
 fs.writeFileSync('src/core/index.js', main)
 
-var builds = [
-  // Runtime only (CommonJS). Used by bundlers e.g. Webpack & Browserify
-  {
-    entry: 'src/entries/web-runtime.js',
-    format: 'cjs',
-    out: 'dist/vue.common.js'
-  },
-  // Minified runtime, only for filze size monitoring
-  {
-    entry: 'src/entries/web-runtime.js',
-    format: 'umd',
-    env: 'production',
-    out: 'dist/vue.common.min.js'
-  },
-  // Runtime+compiler standalone developement build.
-  {
-    entry: 'src/entries/web-runtime-with-compiler.js',
-    format: 'umd',
-    env: 'development',
-    out: 'dist/vue.js',
-    banner: true,
-    alias: {
-      entities: './entity-decoder'
-    }
-  },
-  // Runtime+compiler standalone production build.
-  {
-    entry: 'src/entries/web-runtime-with-compiler.js',
-    format: 'umd',
-    env: 'production',
-    out: 'dist/vue.min.js',
-    banner: true,
-    alias: {
-      entities: './entity-decoder'
-    }
-  },
-  // Web compiler (CommonJS).
-  {
-    entry: 'src/entries/web-compiler.js',
-    format: 'cjs',
-    external: ['entities', 'de-indent'],
-    out: 'packages/vue-template-compiler/build.js'
-  },
-  // Web server renderer (CommonJS).
-  {
-    entry: 'src/entries/web-server-renderer.js',
-    format: 'cjs',
-    external: ['stream', 'module', 'vm', 'entities', 'de-indent'],
-    out: 'packages/vue-server-renderer/build.js'
-  }
-]
+let builds = require('./config').getAllBuilds()
 
 // filter builds via command line arg
 if (process.argv[2]) {
-  var filters = process.argv[2].split(',')
+  const filters = process.argv[2].split(',')
   builds = builds.filter(b => {
-    return filters.some(f => b.out.indexOf(f) > -1)
+    return filters.some(f => b.dest.indexOf(f) > -1)
   })
 }
 
 build(builds)
 
 function build (builds) {
-  var built = 0
-  var total = builds.length
-  next()
-  function next () {
-    buildEntry(builds[built]).then(function () {
+  let built = 0
+  const total = builds.length
+  const next = () => {
+    buildEntry(builds[built]).then(() => {
       built++
       if (built < total) {
         next()
       }
     }).catch(logError)
   }
+
+  next()
 }
 
-function buildEntry (opts) {
-  var plugins = [babel()]
-  if (opts.env) {
-    plugins.push(replace({
-      'process.env.NODE_ENV': JSON.stringify(opts.env),
-      'process.env.VUE_ENV': JSON.stringify('client')
-    }))
-  }
-  var alias = baseAlias
-  if (opts.alias) {
-    alias = Object.assign({}, baseAlias, opts.alias)
-  }
-  plugins.push(aliasPlugin(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
-    if (opts.env === 'production') {
-      var minified = (opts.banner ? banner + '\n' : '') + uglify.minify(code, {
+function buildEntry (config) {
+  const isProd = /min\.js$/.test(config.dest)
+  return rollup.rollup(config).then(bundle => {
+    const code = bundle.generate(config).code
+    if (isProd) {
+      var minified = (config.banner ? config.banner + '\n' : '') + uglify.minify(code, {
         fromString: true,
         output: {
           screw_ie8: true,
@@ -135,9 +57,9 @@ function buildEntry (opts) {
           pure_funcs: ['makeMap']
         }
       }).code
-      return write(opts.out, minified).then(zip(opts.out))
+      return write(config.dest, minified).then(zip(config.dest))
     } else {
-      return write(opts.out, code)
+      return write(config.dest, code)
     }
   })
 }
@@ -146,7 +68,7 @@ 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))
+      console.log(blue(path.relative(process.cwd(), dest)) + ' ' + getSize(code))
       resolve()
     })
   })

+ 108 - 0
build/config.js

@@ -0,0 +1,108 @@
+const path = require('path')
+const flow = require('./rollup-plugin-flow')
+const buble = require('rollup-plugin-buble')
+const replace = require('rollup-plugin-replace')
+const alias = require('rollup-plugin-alias')
+const version = process.env.VERSION || require('../package.json').version
+
+const banner =
+  '/*!\n' +
+  ' * Vue.js v' + version + '\n' +
+  ' * (c) 2014-' + new Date().getFullYear() + ' Evan You\n' +
+  ' * Released under the MIT License.\n' +
+  ' */'
+
+const baseAlias = {
+  vue: path.resolve(__dirname, '../src/entries/web-runtime-with-compiler'),
+  compiler: path.resolve(__dirname, '../src/compiler'),
+  core: path.resolve(__dirname, '../src/core'),
+  shared: path.resolve(__dirname, '../src/shared'),
+  web: path.resolve(__dirname, '../src/platforms/web'),
+  server: path.resolve(__dirname, '../src/server'),
+  entries: path.resolve(__dirname, '../src/entries'),
+  sfc: path.resolve(__dirname, '../src/sfc')
+}
+
+const builds = {
+  // Runtime only (CommonJS). Used by bundlers e.g. Webpack & Browserify
+  'web-runtime-dev': {
+    entry: path.resolve(__dirname, '../src/entries/web-runtime.js'),
+    dest: path.resolve(__dirname, '../dist/vue.common.js'),
+    format: 'cjs'
+  },
+  // Minified runtime, only for filze size monitoring
+  'web-runtime-prod': {
+    entry: path.resolve(__dirname, '../src/entries/web-runtime.js'),
+    dest: path.resolve(__dirname, '../dist/vue.common.min.js'),
+    format: 'umd',
+    env: 'production'
+  },
+  // Runtime+compiler standalone developement build.
+  'web-standalone-dev': {
+    entry: path.resolve(__dirname, '../src/entries/web-runtime-with-compiler.js'),
+    dest: path.resolve(__dirname, '../dist/vue.js'),
+    format: 'umd',
+    env: 'development',
+    banner,
+    alias: {
+      entities: './entity-decoder'
+    }
+  },
+  // Runtime+compiler standalone production build.
+  'web-standalone-prod': {
+    entry: path.resolve(__dirname, '../src/entries/web-runtime-with-compiler.js'),
+    dest: path.resolve(__dirname, '../dist/vue.min.js'),
+    format: 'umd',
+    env: 'production',
+    banner,
+    alias: {
+      entities: './entity-decoder'
+    }
+  },
+  // Web compiler (CommonJS).
+  'web-compiler': {
+    entry: path.resolve(__dirname, '../src/entries/web-compiler.js'),
+    dest: path.resolve(__dirname, '../packages/vue-template-compiler/build.js'),
+    format: 'cjs',
+    external: ['entities', 'de-indent']
+  },
+  // Web server renderer (CommonJS).
+  'web-server-renderer': {
+    entry: path.resolve(__dirname, '../src/entries/web-server-renderer.js'),
+    dest: path.resolve(__dirname, '../packages/vue-server-renderer/build.js'),
+    format: 'cjs',
+    external: ['stream', 'module', 'vm', 'entities', 'de-indent']
+  }
+}
+
+function genConfig (opts) {
+  const config = {
+    entry: opts.entry,
+    dest: opts.dest,
+    external: opts.external,
+    format: opts.format,
+    banner: opts.banner,
+    moduleName: 'Vue',
+    plugins: [
+      flow(),
+      buble(),
+      alias(Object.assign({}, baseAlias, opts.alias))
+    ]
+  }
+
+  if (opts.env) {
+    config.plugins.push(replace({
+      'process.env.NODE_ENV': JSON.stringify(opts.env),
+      'process.env.VUE_ENV': JSON.stringify('client')
+    }))
+  }
+
+  return config
+}
+
+if (process.env.TARGET) {
+  module.exports = genConfig(builds[process.env.TARGET])
+} else {
+  exports.getBuild = name => genConfig(builds[name])
+  exports.getAllBuilds = () => Object.keys(builds).map(name => genConfig(builds[name]))
+}

+ 16 - 0
build/rollup-plugin-flow.js

@@ -0,0 +1,16 @@
+var flowRemoveTypes = require('flow-remove-types')
+var createFilter = require('rollup-pluginutils').createFilter
+
+module.exports = function(options) {
+  options = options || {};
+  var filter = createFilter(options.include, options.exclude)
+
+  return {
+    name: 'flow-remove-types',
+    transform: function(code, id) {
+      if (filter(id)) {
+        return flowRemoveTypes(code)
+      }
+    }
+  }
+}

+ 0 - 29
build/webpack.compiler.dev.config.js

@@ -1,29 +0,0 @@
-var path = require('path')
-var alias = require('./alias')
-
-module.exports = {
-  entry: path.resolve(__dirname, '../src/entries/web-compiler.js'),
-  target: 'node',
-  output: {
-    path: path.resolve(__dirname, '../packages/vue-template-compiler'),
-    filename: 'index.js',
-    libraryTarget: 'commonjs2'
-  },
-  resolve: {
-    alias: alias
-  },
-  externals: {
-    'entities': true,
-    'de-indent': true,
-    'source-map': true
-  },
-  module: {
-    loaders: [
-      {
-        test: /\.js/,
-        loader: 'babel!eslint',
-        exclude: /node_modules/
-      }
-    ]
-  }
-}

+ 0 - 35
build/webpack.dist.dev.config.js

@@ -1,35 +0,0 @@
-var path = require('path')
-var alias = require('./alias')
-var webpack = require('webpack')
-
-module.exports = {
-  entry: path.resolve(__dirname, 'webpack.dist.dev.entry.js'),
-  output: {
-    path: path.resolve(__dirname, '../dist'),
-    filename: 'vue.js',
-    library: 'Vue',
-    libraryTarget: 'umd'
-  },
-  resolve: {
-    alias: Object.assign({}, alias, {
-      entities: './entity-decoder'
-    })
-  },
-  module: {
-    loaders: [
-      {
-        test: /\.js/,
-        loader: 'babel!eslint',
-        exclude: /node_modules/
-      }
-    ]
-  },
-  plugins: [
-    new webpack.DefinePlugin({
-      'process.env': {
-        NODE_ENV: '"development"'
-      }
-    })
-  ],
-  devtool: '#source-map'
-}

+ 0 - 1
build/webpack.dist.dev.entry.js

@@ -1 +0,0 @@
-module.exports = require('../src/entries/web-runtime-with-compiler')['default']

+ 0 - 29
build/webpack.ssr.dev.config.js

@@ -1,29 +0,0 @@
-var path = require('path')
-var alias = require('./alias')
-
-module.exports = {
-  target: 'node',
-  entry: path.resolve(__dirname, '../src/entries/web-server-renderer'),
-  output: {
-    path: path.resolve(__dirname, '../packages/vue-server-renderer'),
-    filename: 'index.js',
-    libraryTarget: 'commonjs2'
-  },
-  resolve: {
-    alias: alias
-  },
-  externals: {
-    'entities': true,
-    'de-indent': true
-  },
-  module: {
-    noParse: /run-in-vm/,
-    loaders: [
-      {
-        test: /\.js/,
-        loader: 'babel!eslint',
-        exclude: /node_modules/
-      }
-    ]
-  }
-}

+ 8 - 4
package.json

@@ -10,11 +10,11 @@
     "src"
   ],
   "scripts": {
-    "dev": "webpack --watch --config build/webpack.dist.dev.config.js",
+    "dev": "TARGET=web-standalone-dev rollup --w --c build/config.js",
     "dev:test": "karma start build/karma.dev.config.js",
-    "dev:ssr": "webpack --watch --config build/webpack.ssr.dev.config.js",
-    "dev:compiler": "webpack --watch --config build/webpack.compiler.dev.config.js",
-    "build": "NODE_ENV=production node build/build.js",
+    "dev:ssr": "TARGET=web-server-renderer rollup --w --c build/config.js",
+    "dev:compiler": "TARGET=web-compiler rollup --w --c build/config.js",
+    "build": "node build/build.js",
     "build:ssr": "npm run build -- vue.common.js,vue-server-renderer",
     "test": "npm run lint && flow check && npm run test:cover && npm run test:e2e -- --env phantomjs && npm run test:ssr",
     "test:unit": "NODE_ENV=development karma start build/karma.unit.config.js",
@@ -49,6 +49,7 @@
     "babel-preset-es2015": "^6.9.0",
     "babel-preset-es2015-rollup-vue": "^1.1.0",
     "babel-preset-flow-vue": "^1.0.0",
+    "buble": "^0.13.1",
     "chromedriver": "^2.21.2",
     "codecov.io": "^0.1.6",
     "cross-spawn": "^4.0.0",
@@ -59,6 +60,7 @@
     "eslint-loader": "^1.3.0",
     "eslint-plugin-flow-vars": "^0.4.0",
     "flow-bin": "^0.27.0",
+    "flow-remove-types": "github:yyx990803/flow-remove-types",
     "http-server": "^0.9.0",
     "jasmine": "^2.4.1",
     "jasmine-core": "^2.4.1",
@@ -80,7 +82,9 @@
     "rollup": "^0.33.0",
     "rollup-plugin-alias": "^1.2.0",
     "rollup-plugin-babel": "^2.4.0",
+    "rollup-plugin-buble": "^0.13.0",
     "rollup-plugin-replace": "^1.1.0",
+    "rollup-watch": "^2.5.0",
     "selenium-server": "2.53.0",
     "uglify-js": "^2.6.2",
     "webpack": "^1.13.1"