-
-
Save fkorotkov/a694e5deee7c3b037e4a4b5952dd9033 to your computer and use it in GitHub Desktop.
Buck RN JS bundle generation
This file contains hidden or 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
# workaround to make rule key to depend on node and npm versions | |
NODE_NPM_VERSIONS = 'cat $(location //:node_version) && cat $(location //:npm_version) && ' | |
# prepopulated modules | |
# for example CI fails to clone react-native-permissions fork due to ssh permissions | |
export_file( | |
name = 'locale_node_modules', | |
src = 'node_modules', | |
out = 'node_modules', | |
) | |
genrule( | |
name = 'node_modules', | |
visibility = ['PUBLIC'], | |
srcs = [ | |
'.babelrc', | |
'.npmrc', | |
'.nvmrc', | |
'npm-shrinkwrap.json', | |
'package.json', | |
], | |
bash = NODE_NPM_VERSIONS + '' \ | |
'rsync $SRCDIR/ $TMP/ -a --copy-links -v && ' \ | |
'mkdir -p $TMP/node_modules/ && ' \ | |
'rsync $(location :locale_node_modules)/ $TMP/node_modules/ -a --copy-links -v && ' \ | |
'cd $TMP && npm install && ' \ | |
'mv $TMP/node_modules $OUT && ' \ | |
'rm -rf $TMP', | |
out = 'node_modules', | |
) | |
PLATFORMS = [ | |
'ios', | |
# TODO(fedor): add android | |
] | |
for platform in PLATFORMS: | |
genrule( | |
name = 'bundle-' + platform, | |
visibility = ['PUBLIC'], | |
srcs = [ | |
'.babelrc', | |
'.flowconfig', | |
] + glob([ | |
'**/*.ejs', | |
'**/*.gif', | |
'**/*.js', | |
'**/*.json', | |
'**/*.jpg', | |
'**/*.png', | |
'**/*.sh', | |
], excludes = [ | |
'node_modules/**' | |
]), | |
bash = NODE_NPM_VERSIONS + '' \ | |
'mkdir -p $OUT && ' \ | |
'rsync $SRCDIR/ $TMP/ -a --copy-links -v && ' \ | |
'cp -r $(location :node_modules) $TMP && ' \ | |
'cd $TMP && ' \ | |
'node ./node_modules/react-native/local-cli/cli.js bundle ' \ | |
'--platform ' + platform + ' ' \ | |
'--dev false ' \ | |
'--entry-file index.js ' \ | |
'--bundle-output $OUT/main.jsbundle ' \ | |
'--assets-dest $OUT && ' \ | |
'rm -rf $TMP', | |
out = 'Assets', | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here are some root rules for NPM and Node