Skip to content

Commit

Permalink
feat(build): support --watch and --environment flags
Browse files Browse the repository at this point in the history
  • Loading branch information
Kent C. Dodds committed Sep 8, 2017
1 parent 1956e5e commit 0dce5bc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
"rollup-plugin-json": "^2.3.0",
"rollup-plugin-node-resolve": "^3.0.0",
"rollup-plugin-uglify": "^2.0.1",
"rollup-watch": "^4.3.1"
"rollup-watch": "^4.3.1",
"yargs-parser": "^7.0.0"
},
"repository": {
"type": "git",
Expand Down
13 changes: 12 additions & 1 deletion src/scripts/build/rollup.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const path = require('path')
const spawn = require('cross-spawn')
const rimraf = require('rimraf')
const yargsParser = require('yargs-parser')
const {
hasFile,
resolveBin,
Expand All @@ -12,15 +13,25 @@ const crossEnv = resolveBin('cross-env')
const rollup = resolveBin('rollup')
const args = process.argv.slice(2)
const here = p => path.join(__dirname, p)
const parsedArgs = yargsParser(args)

const useBuiltinConfig =
!args.includes('--config') && !hasFile('rollup.config.js')
const config = useBuiltinConfig
? `--config ${here('../../config/rollup.config.js')}`
: args.includes('--config') ? '' : '--config' // --config will pick up the rollup.config.js file

const environment = parsedArgs.environment
? `--environment ${parsedArgs.environment}`
: ''
const watch = parsedArgs.watch ? '--watch' : ''

const defaultEnv = 'BUILD_ROLLUP=true'

const getCommand = env =>
`${crossEnv} BUILD_ROLLUP=true ${env} ${rollup} ${config}`
[crossEnv, defaultEnv, env, rollup, config, environment, watch]
.filter(Boolean)
.join(' ')

const scripts = args.includes('--p-react')
? getPReactScripts()
Expand Down

0 comments on commit 0dce5bc

Please sign in to comment.