Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support file extensions in Babel build #335

Merged
merged 3 commits into from
Oct 27, 2020
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions modules/dev-tools/scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ set -e
DEV_TOOLS_DIR=`node -e "require('ocular-dev-tools/node/module-dir')()"`
CONFIG=`node $DEV_TOOLS_DIR/node/get-config.js ".babel.configPath"`
MODULES=`node $DEV_TOOLS_DIR/node/get-config.js ".modules" | sed -E "s/,/ /g"`
EXTENSIONS=".es6,.js,.es,.jsx,.mjs"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the current @babel/cli default - it was easier to specify here than leave out.


check_target() {
if [[ ! "$1" =~ ^es5|es6|esm ]]; then
Expand All @@ -13,6 +14,13 @@ check_target() {
fi
}

build_src() {
OUT_DIR=$1
TARGET=$2
check_target $TARGET
BABEL_ENV=$TARGET npx babel src --config-file $CONFIG --out-dir $OUT_DIR --copy-files --source-maps --extensions $EXTENSIONS
}

build_module() {
if [ -z "$1" ]; then
TARGETS="es6 esm es5"
Expand All @@ -21,12 +29,10 @@ build_module() {
fi
N=`echo "$TARGETS" | wc -w`
if [ $N -eq 1 ]; then
check_target $TARGETS
BABEL_ENV=$TARGETS npx babel src --config-file $CONFIG --out-dir dist --copy-files --source-maps
build_src dist $TARGETS
else
for T in ${TARGETS}; do(
check_target $T
BABEL_ENV=$T npx babel src --config-file $CONFIG --out-dir dist/$T --copy-files --source-maps
build_src dist/$T $T
); done
fi
}
Expand All @@ -42,6 +48,9 @@ build_monorepo() {
--dist)
TARGET=$2
shift ;;
--extensions)
EXTENSIONS=$2
shift ;;
*)
echo -e "\033[91mUnknown option $1. ocular-build [--dist es5|es6|esm,...] [module1,...]\033[0m"
exit 1 ;;
Expand Down