mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-24 04:16:00 +08:00
Add support for passing in additional assetExts to packager
fbshipit-source-id: 42e508e37d960fbeb905a2ea8cb4741dba5c67fc
This commit is contained in:
committed by
Facebook Github Bot 6
parent
47d6d289d4
commit
1ab4b2a792
@@ -13,6 +13,7 @@ const path = require('path');
|
||||
const Promise = require('promise');
|
||||
const saveAssets = require('./saveAssets');
|
||||
const Server = require('../../packager/react-packager/src/Server');
|
||||
const defaultAssetExts = require('../../packager/defaultAssetExts');
|
||||
|
||||
function saveBundle(output, bundle, args) {
|
||||
return Promise.resolve(
|
||||
@@ -25,17 +26,6 @@ function buildBundle(args, config, output = outputBundle, packagerInstance) {
|
||||
// have other choice than defining it as an env variable here.
|
||||
process.env.NODE_ENV = args.dev ? 'development' : 'production';
|
||||
|
||||
const options = {
|
||||
projectRoots: config.getProjectRoots(),
|
||||
assetRoots: config.getAssetRoots(),
|
||||
blacklistRE: config.getBlacklistRE(args.platform),
|
||||
getTransformOptionsModulePath: config.getTransformOptionsModulePath,
|
||||
transformModulePath: args.transformer,
|
||||
extraNodeModules: config.extraNodeModules,
|
||||
nonPersistent: true,
|
||||
resetCache: args.resetCache,
|
||||
};
|
||||
|
||||
const requestOpts = {
|
||||
entryFile: args.entryFile,
|
||||
sourceMapUrl: args.sourcemapOutput,
|
||||
@@ -48,6 +38,20 @@ function buildBundle(args, config, output = outputBundle, packagerInstance) {
|
||||
// bundle command and close it down afterwards.
|
||||
var shouldClosePackager = false;
|
||||
if (!packagerInstance) {
|
||||
let assetExts = (config.getAssetExts && config.getAssetExts()) || [];
|
||||
|
||||
const options = {
|
||||
projectRoots: config.getProjectRoots(),
|
||||
assetExts: defaultAssetExts.concat(assetExts),
|
||||
assetRoots: config.getAssetRoots(),
|
||||
blacklistRE: config.getBlacklistRE(args.platform),
|
||||
getTransformOptionsModulePath: config.getTransformOptionsModulePath,
|
||||
transformModulePath: args.transformer,
|
||||
extraNodeModules: config.extraNodeModules,
|
||||
nonPersistent: true,
|
||||
resetCache: args.resetCache,
|
||||
};
|
||||
|
||||
packagerInstance = new Server(options);
|
||||
shouldClosePackager = true;
|
||||
}
|
||||
|
||||
@@ -28,6 +28,15 @@ var config = {
|
||||
return getRoots();
|
||||
},
|
||||
|
||||
/**
|
||||
* Specify any additional asset extentions to be used by the packager.
|
||||
* For example, if you want to include a .ttf file, you would return ['ttf']
|
||||
* from here and use `require('./fonts/example.ttf')` inside your app.
|
||||
*/
|
||||
getAssetExts() {
|
||||
return [];
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns a regular expression for modules that should be ignored by the
|
||||
* packager on a given platform.
|
||||
|
||||
@@ -24,6 +24,7 @@ const indexPageMiddleware = require('./middleware/indexPage');
|
||||
const systraceProfileMiddleware = require('./middleware/systraceProfileMiddleware.js');
|
||||
const heapCaptureMiddleware = require('./middleware/heapCaptureMiddleware.js');
|
||||
const webSocketProxy = require('./util/webSocketProxy.js');
|
||||
const defaultAssetExts = require('../../packager/defaultAssetExts');
|
||||
|
||||
function runServer(args, config, readyCallback) {
|
||||
var wsProxy = null;
|
||||
@@ -85,12 +86,7 @@ function getPackagerServer(args, config) {
|
||||
transformModulePath: transformModulePath,
|
||||
extraNodeModules: config.extraNodeModules,
|
||||
assetRoots: args.assetRoots,
|
||||
assetExts: [
|
||||
'bmp', 'gif', 'jpg', 'jpeg', 'png', 'psd', 'svg', 'webp', // Image formats
|
||||
'm4v', 'mov', 'mp4', 'mpeg', 'mpg', 'webm', // Video formats
|
||||
'aac', 'aiff', 'caf', 'm4a', 'mp3', 'wav', // Audio formats
|
||||
'html', 'pdf', // Document formats
|
||||
],
|
||||
assetExts: defaultAssetExts.concat(args.assetExts),
|
||||
resetCache: args.resetCache,
|
||||
verbose: args.verbose,
|
||||
});
|
||||
|
||||
@@ -96,6 +96,11 @@ module.exports = {
|
||||
description: 'specify the root directories of app assets',
|
||||
parse: (val) => val.split(',').map(dir => path.resolve(process.cwd(), dir)),
|
||||
default: (config) => config.getAssetRoots(),
|
||||
}, {
|
||||
command: '--assetExts [list]',
|
||||
description: 'Specify any additional asset extentions to be used by the packager',
|
||||
parse: (val) => val.split(','),
|
||||
default: (config) => config.getAssetExts(),
|
||||
}, {
|
||||
command: '--skipflow',
|
||||
description: 'Disable flow checks'
|
||||
|
||||
Reference in New Issue
Block a user