]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
build: improve build script to support multiple targets
authorEvan You <yyx990803@gmail.com>
Wed, 2 Oct 2019 15:19:30 +0000 (11:19 -0400)
committerEvan You <yyx990803@gmail.com>
Wed, 2 Oct 2019 15:19:30 +0000 (11:19 -0400)
scripts/build.js
scripts/utils.js

index 0ade7371b83912d94d5897510a65ce780013b443..b4d63ab21d8aa32b6c85e1b4a4cb36b4ba330a9c 100644 (file)
@@ -20,19 +20,21 @@ const zlib = require('zlib')
 const chalk = require('chalk')
 const execa = require('execa')
 const { compress } = require('brotli')
-const { targets, fuzzyMatchTarget } = require('./utils')
+const { targets: allTargets, fuzzyMatchTarget } = require('./utils')
 
 const args = require('minimist')(process.argv.slice(2))
-const target = args._[0]
+const targets = args._
 const formats = args.formats || args.f
+const devOnly = args.devOnly || args.d
+const prodOnly = !devOnly && (args.prodOnly || args.p)
 const buildAllMatching = args.all || args.a
 ;(async () => {
-  if (!target) {
-    await buildAll(targets)
-    checkAllSizes(targets)
+  if (!targets.length) {
+    await buildAll(allTargets)
+    checkAllSizes(allTargets)
   } else {
-    await buildAll(fuzzyMatchTarget(target, buildAllMatching))
-    checkAllSizes(fuzzyMatchTarget(target, buildAllMatching))
+    await buildAll(fuzzyMatchTarget(targets, buildAllMatching))
+    checkAllSizes(fuzzyMatchTarget(targets, buildAllMatching))
   }
 })()
 
@@ -53,11 +55,11 @@ async function build(target) {
     [
       '-c',
       '--environment',
-      `NODE_ENV:production,` +
+      `NODE_ENV:${devOnly ? 'development' : 'production'},` +
         `TARGET:${target}` +
         (formats ? `,FORMATS:${formats}` : ``) +
         (args.types ? `,TYPES:true` : ``) +
-        (args.p ? `,PROD_ONLY:true` : ``)
+        (prodOnly ? `,PROD_ONLY:true` : ``)
     ],
     { stdio: 'inherit' }
   )
index 9816d795d7bd28a68d8ad0a103145558b62ad835..d703474c7f92fabe66ae9d35f0e8d0da87296390 100644 (file)
@@ -11,16 +11,18 @@ const targets = (exports.targets = fs.readdirSync('packages').filter(f => {
   return true
 }))
 
-exports.fuzzyMatchTarget = (partialTarget, includeAllMatching) => {
+exports.fuzzyMatchTarget = (partialTargets, includeAllMatching) => {
   const matched = []
-  for (const target of targets) {
-    if (target.match(partialTarget)) {
-      matched.push(target)
-      if (!includeAllMatching) {
-        return matched
+  partialTargets.some(partialTarget => {
+    for (const target of targets) {
+      if (target.match(partialTarget)) {
+        matched.push(target)
+        if (!includeAllMatching) {
+          break
+        }
       }
     }
-  }
+  })
   if (matched.length) {
     return matched
   } else {