Add support for passing in additional assetExts to packager

fbshipit-source-id: 42e508e37d960fbeb905a2ea8cb4741dba5c67fc
This commit is contained in:
androidtrunkagent 2016-08-02 10:13:13 -07:00 committed by Facebook Github Bot 6
parent 47d6d289d4
commit 1ab4b2a792
7 changed files with 55 additions and 25 deletions

View File

@ -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;
}

View File

@ -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.

View File

@ -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,
});

View File

@ -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'

View File

@ -0,0 +1,16 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
'use strict';
module.exports = [
'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
];

View File

@ -17,9 +17,10 @@ const Promise = require('promise');
const SourceMapConsumer = require('source-map').SourceMapConsumer;
const declareOpts = require('../lib/declareOpts');
const defaultAssetExts = require('../../../defaultAssetExts');
const mime = require('mime-types');
const path = require('path');
const url = require('url');
const mime = require('mime-types');
function debounce(fn, delay) {
var timeout;
@ -71,12 +72,7 @@ const validateOpts = declareOpts({
},
assetExts: {
type: 'array',
default: [
'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
],
default: defaultAssetExts,
},
transformTimeoutInterval: {
type: 'number',

View File

@ -5,7 +5,7 @@
*/
'use strict';
const blacklist = require('./blacklist.js');
const blacklist = require('./blacklist');
const path = require('path');
module.exports = {
@ -17,6 +17,10 @@ module.exports = {
return this._getRoots();
},
getAssetExts() {
return [];
},
getBlacklistRE(platform) {
return blacklist(platform);
},