Skip to content

Instantly share code, notes, and snippets.

@kmrk
Last active January 16, 2020 23:58
Show Gist options
  • Save kmrk/bbc52a4d54b407398aff1695e5b710b7 to your computer and use it in GitHub Desktop.
Save kmrk/bbc52a4d54b407398aff1695e5b710b7 to your computer and use it in GitHub Desktop.
babel --copy-files with --ignore
#!/usr/bin/env node
// babel's cli option --copy-files will override the --ignore setting
// so copy resources like this
require('fs-extra').copy(
process.argv.slice(-2).shift(),
process.argv.slice(-2).pop(),
{ filter: (src,dist)=>{ return (src.match(/\.js|\.jsx|stories|test/)===null)} },
err => { if (err) return console.error (err); console.log ('Copy success!');
});
// package.json
...
"scripts": {
"build-commonjs": "BABEL_ENV=commonjs babel src --out-dir dist/commonjs --ignore '**/test','**/stories' --source-maps inline && ./scripts/--copy-files src dist/commonjs",
"build-esm": "BABEL_ENV=esm babel src --out-dir dist/esm --ignore '**/test','**/stories' --source-maps inline && ./scripts/--copy-files src dist/esm",
"build": "rimraf dist && 'npm run build-commonjs' 'npm run build-esm'"
},
"devDependencies": {
"fs-extra": "^8.1.0"
},
...
@kmrk
Copy link
Author

kmrk commented Aug 7, 2019

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment