Skip to content
This repository was archived by the owner on May 17, 2019. It is now read-only.

Commit 338bb68

Browse files
committed
Add option in fusionConfig to configure jsExtPattern
1 parent 19546eb commit 338bb68

3 files changed

Lines changed: 22 additions & 3 deletions

File tree

build/get-webpack-config.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ const EXCLUDE_TRANSPILATION_PATTERNS = [
6060
/node_modules\/react\//,
6161
/node_modules\/core-js\//,
6262
];
63+
6364
const JS_EXT_PATTERN = /\.jsx?$/;
6465

6566
/*::
@@ -99,6 +100,8 @@ function getWebpackConfig(opts /*: WebpackConfigOpts */) {
99100
const {id, dev, dir, watch, state, fusionConfig, legacyPkgConfig = {}} = opts;
100101
const main = 'src/main.js';
101102

103+
const jsExtPattern = fusionConfig.jsExtPattern || JS_EXT_PATTERN;
104+
102105
if (!fs.existsSync(path.join(dir, main))) {
103106
throw new Error(`Project directory must contain a ${main} file`);
104107
}
@@ -269,7 +272,7 @@ function getWebpackConfig(opts /*: WebpackConfigOpts */) {
269272
*/
270273
runtime === 'server' && {
271274
compiler: id => id === 'server',
272-
test: JS_EXT_PATTERN,
275+
test: jsExtPattern,
273276
exclude: EXCLUDE_TRANSPILATION_PATTERNS,
274277
use: [
275278
{
@@ -299,7 +302,7 @@ function getWebpackConfig(opts /*: WebpackConfigOpts */) {
299302
*/
300303
(runtime === 'client' || runtime === 'sw') && {
301304
compiler: id => id === 'client' || id === 'sw',
302-
test: JS_EXT_PATTERN,
305+
test: jsExtPattern,
303306
exclude: EXCLUDE_TRANSPILATION_PATTERNS,
304307
use: [
305308
{
@@ -329,7 +332,7 @@ function getWebpackConfig(opts /*: WebpackConfigOpts */) {
329332
*/
330333
runtime === 'client' && {
331334
compiler: id => id === 'client-legacy',
332-
test: JS_EXT_PATTERN,
335+
test: jsExtPattern,
333336
exclude: EXCLUDE_TRANSPILATION_PATTERNS,
334337
use: [
335338
{

build/load-fusionrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ let loggedNotice = false;
1818
/*::
1919
export type FusionRC = {
2020
babel?: {plugins?: Array<any>, presets?: Array<any>},
21+
jsExtPattern?: RegExp,
2122
assumeNoImportSideEffects?: boolean,
2223
experimentalCompile?: boolean,
2324
nodeBuiltins?: {[string]: any},

docs/fusionrc.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,21 @@ Fusion supports a `.fusionrc.js` in the root directory of your application. This
44

55
This configuration object supports the following fields:
66

7+
## `jsExtPattern`
8+
9+
By default this is `/\.jsx?$/`
10+
11+
For example, this enables to handle typescript files with addition to Babel plugins/preset:
12+
13+
```js
14+
module.exports = {
15+
jsExtPattern: \[jt]sx?$\,
16+
babel: {
17+
presets: ["@babel/preset-typescript"],
18+
}
19+
};
20+
```
21+
722
## `babel`
823

924
### Adding plugins/presets

0 commit comments

Comments
 (0)