Created
September 15, 2015 22:50
-
-
Save johnbintz/5ed3d65b1427aa0981be to your computer and use it in GitHub Desktop.
Webpack + Babel with React Native Android, using react-native-webpack-server's internals
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
// this is a hack until react-native-webpack-server gets updated (and I'm | |
// sure it will soon. :) ) | |
// | |
// you'll need 0.4.0-rc or better of react-native-webpack-server | |
// don't run react-native-webpack-server's server for now, use react-native's | |
// | |
// also, run me in pure node and not babel-node, or react-native will try and | |
// load polyfills that are already loaded. :/ | |
var webpack = require('webpack'); | |
var webpackConfig = require('./webpack.config.js'); | |
var getReactNativeExternals = require('react-native-webpack-server/lib/getReactNativeExternals'); | |
var outputOptions = { | |
cached: false, | |
cachedAssets: false, | |
colors: true, | |
exclude: ['node_modules'] | |
}; | |
getReactNativeExternals().then(function(reactNativeExternals) { | |
webpackConfig.externals = Array.isArray(webpackConfig.externals) | |
? webpackConfig.externals | |
: [(webpackConfig.externals || {})]; | |
// Inject react native externals | |
webpackConfig.externals.push(reactNativeExternals); | |
webpack(webpackConfig).watch(300, function (err, stats) { | |
if (err) { | |
console.error(err.stack || err); | |
if (err.details) console.error(err.details); | |
} else { | |
process.stdout.write(stats.toString(outputOptions) + '\n'); | |
} | |
}); | |
}); |
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
var webpack = require('webpack'), | |
path = require('path'); | |
module.exports = { | |
debug: true, | |
entry: './index.android', | |
context: __dirname + '/src', | |
module: { | |
loaders: [ | |
{ test: /\.jsx$/, exclude: /node_modules/, loaders: ['babel?stage=0'] } | |
] | |
}, | |
output: { | |
path: __dirname, | |
filename: 'index.android.js' | |
}, | |
resolve: { | |
root: [path.join(__dirname, 'src')], | |
extensions: ['', '.js', '.jsx'] | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment