-
Notifications
You must be signed in to change notification settings - Fork 835
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add build script * fix * finalize script * fix the script * add minifier * revert changes in yarn.lock
- Loading branch information
Showing
2 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/bin/bash | ||
# Browserify doesn't seem to support defining custom entry point for modules in node_modules | ||
# This build script replaces the entry point (the main field of package.json) of d3 libraries to the files | ||
# defined in the unpkg field when building browser bundles. | ||
# The replacement are reverted after the build finishes. | ||
D3_LIB_PATHS=$(ls -d ../../node_modules/d3-*) | ||
|
||
get_key_from_d3_path() { | ||
local KEY=$(echo $1 | sed 's/..\/..\/node_modules\/d3-//') | ||
local KEY=$(echo $KEY | sed 's/-/_/') | ||
echo $KEY | ||
} | ||
|
||
for D3_LIB_PATH in $D3_LIB_PATHS | ||
do | ||
PACKAGE_JSON=$D3_LIB_PATH/package.json | ||
UNPKG=$(jq -r '.unpkg' $PACKAGE_JSON) | ||
if ! [ -z $UNPKG ] && [ $UNPKG != null ] | ||
then | ||
# save the main field | ||
MAIN=$(jq -r '.main' $PACKAGE_JSON) | ||
KEY=$(get_key_from_d3_path $D3_LIB_PATH) | ||
declare var_$KEY=$MAIN | ||
|
||
# modify the main field | ||
MOD=$(jq --arg unpkg $UNPKG '.main = $unpkg' $PACKAGE_JSON) | ||
cat <<< $MOD | jq . > $PACKAGE_JSON | ||
fi | ||
done | ||
|
||
browserify src/index.js -t [ babelify --rootMode upward --global ] --standalone reactVis | uglifyjs > dist/dist.min.js | ||
|
||
# set the main fields of package.json back to original | ||
for D3_LIB_PATH in $D3_LIB_PATHS | ||
do | ||
PACKAGE_JSON=$D3_LIB_PATH/package.json | ||
KEY=$(get_key_from_d3_path $D3_LIB_PATH) | ||
MAIN="var_$KEY" | ||
if ! [ -z "${!MAIN}" ] | ||
then | ||
MOD=$(jq --arg var "${!MAIN}" '.main = $var' $PACKAGE_JSON) | ||
cat <<< $MOD | jq . > $PACKAGE_JSON | ||
fi | ||
done | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters