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

Add option in fusionConfig to configure jsExtPattern (enable typescript) #705

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions build/get-webpack-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const EXCLUDE_TRANSPILATION_PATTERNS = [
/node_modules\/react\//,
/node_modules\/core-js\//,
];

const JS_EXT_PATTERN = /\.jsx?$/;

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

const jsExtPattern = fusionConfig.jsExtPattern || JS_EXT_PATTERN;

if (!fs.existsSync(path.join(dir, main))) {
throw new Error(`Project directory must contain a ${main} file`);
}
Expand Down Expand Up @@ -269,7 +272,7 @@ function getWebpackConfig(opts /*: WebpackConfigOpts */) {
*/
runtime === 'server' && {
compiler: id => id === 'server',
test: JS_EXT_PATTERN,
test: jsExtPattern,
exclude: EXCLUDE_TRANSPILATION_PATTERNS,
use: [
{
Expand Down Expand Up @@ -299,7 +302,7 @@ function getWebpackConfig(opts /*: WebpackConfigOpts */) {
*/
(runtime === 'client' || runtime === 'sw') && {
compiler: id => id === 'client' || id === 'sw',
test: JS_EXT_PATTERN,
test: jsExtPattern,
exclude: EXCLUDE_TRANSPILATION_PATTERNS,
use: [
{
Expand Down Expand Up @@ -329,7 +332,7 @@ function getWebpackConfig(opts /*: WebpackConfigOpts */) {
*/
runtime === 'client' && {
compiler: id => id === 'client-legacy',
test: JS_EXT_PATTERN,
test: jsExtPattern,
exclude: EXCLUDE_TRANSPILATION_PATTERNS,
use: [
{
Expand Down Expand Up @@ -401,6 +404,7 @@ function getWebpackConfig(opts /*: WebpackConfigOpts */) {
__FUSION_ENTRY_PATH__: path.join(dir, main),
__ENV__: env,
},
extensions: fusionConfig.resolveExtensions,
},
resolveLoader: {
alias: {
Expand Down
4 changes: 4 additions & 0 deletions build/load-fusionrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ let loggedNotice = false;
/*::
export type FusionRC = {
babel?: {plugins?: Array<any>, presets?: Array<any>},
jsExtPattern?: RegExp,
resolveExtensions?: Array<string>,
assumeNoImportSideEffects?: boolean,
experimentalCompile?: boolean,
nodeBuiltins?: {[string]: any},
Expand Down Expand Up @@ -59,6 +61,8 @@ function isValid(config) {
!Object.keys(config).every(key =>
[
'babel',
'jsExtPattern',
'resolveExtensions',
'assumeNoImportSideEffects',
'experimentalCompile',
'nodeBuiltins',
Expand Down
25 changes: 25 additions & 0 deletions docs/fusionrc.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,31 @@ Fusion supports a `.fusionrc.js` in the root directory of your application. This

This configuration object supports the following fields:

## `jsExtPattern`

By default this is `/\.jsx?$/`

For example, this enables to handle typescript files with addition to Babel plugins/preset:

```js
module.exports = {
jsExtPattern: \[jt]sx?$\,
babel: {
presets: ["@babel/preset-typescript"],
}
};
```

## `resolveExtensions`

By default this is webpack default witch is: `['.wasm', '.mjs', '.js', '.json']`

```js
module.exports = {
resolveExtensions: ['.wasm', '.mjs', '.js', '.json', '.ts', '.tsx'],
};
```

## `babel`

### Adding plugins/presets
Expand Down