From ec06f04566ef5e182d72f4aed48026f5da2cc302 Mon Sep 17 00:00:00 2001 From: Matt Parrish and Dennis Johnson Date: Fri, 17 Apr 2015 12:57:02 -0600 Subject: [PATCH] Allowing all React Tools command-line options to be passed in webpack loader config --- README.md | 3 ++- index.js | 13 +++---------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 0a40e6e..598e174 100644 --- a/README.md +++ b/README.md @@ -8,5 +8,6 @@ To enable ES6 features, use `?harmony` in your loader config. To auto insert the pragma required to process the file use the insertPragma parameter e.g. `?insertPragma=React.DOM`. [Flow]-style type annotations can be stripped using `?stripTypes`. +Additionally, any valid [React Tools command-line options](https://github.com/facebook/react/blob/master/npm-react-tools/README.md#command-line) can be specified as loader config options. -[Flow]: http://flowtype.org/ +Flow: http://flowtype.org/ diff --git a/index.js b/index.js index 021047b..39e1d9a 100644 --- a/index.js +++ b/index.js @@ -6,18 +6,11 @@ module.exports = function(source) { var sourceFilename = loaderUtils.getRemainingRequest(this); var current = loaderUtils.getCurrentRequest(this); + var transformOptions = loaderUtils.parseQuery(this.query); + transformOptions.sourceMap = this.sourceMap; - var query = loaderUtils.parseQuery(this.query); - if (query.insertPragma) { - source = '/** @jsx ' + query.insertPragma + ' */' + source; - } + var transform = reactTools.transformWithDetails(source, transformOptions); - var transform = reactTools.transformWithDetails(source, { - harmony: query.harmony, - stripTypes: query.stripTypes, - es5: query.es5, - sourceMap: this.sourceMap - }); if (transform.sourceMap) { transform.sourceMap.sources = [sourceFilename]; transform.sourceMap.file = current;