Browse Source

build: update rollup config

Evan You 7 years ago
parent
commit
91b7998550
4 changed files with 32 additions and 24 deletions
  1. 7 7
      build/build.main.js
  2. 16 12
      build/configs.js
  3. 3 1
      build/rollup.dev.config.js
  4. 6 4
      build/rollup.logger.config.js

+ 7 - 7
build/build.main.js

@@ -26,22 +26,22 @@ function build (builds) {
   next()
 }
 
-function buildEntry (config) {
-  const isProd = /min\.js$/.test(config.file)
-  return rollup.rollup(config)
-    .then(bundle => bundle.generate(config))
+function buildEntry ({ input, output }) {
+  const isProd = /min\.js$/.test(output.file)
+  return rollup.rollup(input)
+    .then(bundle => bundle.generate(output))
     .then(({ code }) => {
       if (isProd) {
-        var minified = (config.banner ? config.banner + '\n' : '') + uglify.minify(code, {
+        var minified = (output.banner ? output.banner + '\n' : '') + uglify.minify(code, {
           output: {
             /* eslint-disable camelcase */
             ascii_only: true
             /* eslint-enable camelcase */
           }
         }).code
-        return write(config.file, minified, true)
+        return write(output.file, minified, true)
       } else {
-        return write(config.file, code)
+        return write(output.file, code)
       }
     })
 }

+ 16 - 12
build/configs.js

@@ -38,21 +38,25 @@ const configs = {
 
 function genConfig (opts) {
   const config = {
-    input: opts.input,
-    file: opts.file,
-    format: opts.format,
-    banner,
-    name: 'Vuex',
-    plugins: [
-      replace({
-        __VERSION__: version
-      }),
-      buble()
-    ]
+    input: {
+      input: opts.input,
+      plugins: [
+        replace({
+          __VERSION__: version
+        }),
+        buble()
+      ]
+    },
+    output: {
+      banner,
+      file: opts.file,
+      format: opts.format,
+      name: 'Vuex'
+    }
   }
 
   if (opts.env) {
-    config.plugins.unshift(replace({
+    config.input.plugins.unshift(replace({
       'process.env.NODE_ENV': JSON.stringify(opts.env)
     }))
   }

+ 3 - 1
build/rollup.dev.config.js

@@ -1 +1,3 @@
-module.exports = require('./configs').commonjs
+const { input, output } = require('./configs').commonjs
+
+module.exports = Object.assign({}, input, { output })

+ 6 - 4
build/rollup.logger.config.js

@@ -1,9 +1,11 @@
 const buble = require('rollup-plugin-buble')
 
 module.exports = {
-  entry: 'src/plugins/logger.js',
-  dest: 'dist/logger.js',
-  format: 'umd',
-  moduleName: 'createVuexLogger',
+  input: 'src/plugins/logger.js',
+  output: {
+    file: 'dist/logger.js',
+    format: 'umd',
+    name: 'createVuexLogger',
+  },
   plugins: [buble()]
 }