improved the build tool

This commit is contained in:
Dominic Gannaway
2017-03-10 17:05:03 +00:00
parent 1f66be3be1
commit bd4d7ecb3e
2 changed files with 16 additions and 3 deletions
+1
View File
@@ -70,6 +70,7 @@
"jest-runtime": "^19.0.1",
"loose-envify": "^1.1.0",
"merge-stream": "^1.0.0",
"minimist": "^1.2.0",
"object-assign": "^4.1.1",
"platform": "^1.1.0",
"rollup": "^0.41.4",
+15 -3
View File
@@ -11,6 +11,7 @@ const chalk = require('chalk');
const boxen = require('boxen');
const { resolve } = require('path');
const fixHasteImports = require('./fixHasteImports');
const argv = require('minimist')(process.argv.slice(2));
const {
createModuleMap,
getExternalModules,
@@ -76,6 +77,13 @@ function updateBabelConfig(babelOpts, bundleType) {
}
}
function handleRollupWarnings(warning) {
if (warning.code === 'UNRESOLVED_IMPORT') {
return;
}
console.warn(warning.message || warning);
}
function updateBundleConfig(config, filename, format, bundleType, hastName) {
return Object.assign({}, config, {
banner: getBanner(bundleType, hastName),
@@ -200,16 +208,19 @@ function getPlugins(entry, babelOpts, paths, filename, bundleType) {
return plugins;
}
const inputBundleType = argv.type;
function createBundle({babelOpts, entry, fbEntry, config, paths, name, hasteName}, bundleType) {
if (inputBundleType && inputBundleType !== bundleType) {
return Promise.resolve();
}
const filename = getFilename(name, hasteName, bundleType);
const format = getFormat(bundleType);
return rollup({
entry: bundleType === bundleTypes.FB ? fbEntry : entry,
plugins: getPlugins(entry, babelOpts, paths, filename, bundleType),
external: [
'react',
],
onwarn: handleRollupWarnings,
}).then(({write}) => write(
updateBundleConfig(config, filename, format, bundleType, hasteName)
)).catch(console.error);
@@ -230,3 +241,4 @@ bundles.forEach(bundle => {
);
}
});