From e9f2828551c6d22a642dd020502a22e2038c8dcf Mon Sep 17 00:00:00 2001 From: Piotr Monarski Date: Tue, 19 Feb 2019 10:31:06 +0100 Subject: [PATCH 1/2] Add option in fusionConfig to configure jsExtPattern --- build/get-webpack-config.js | 9 ++++++--- build/load-fusionrc.js | 2 ++ docs/fusionrc.md | 15 +++++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/build/get-webpack-config.js b/build/get-webpack-config.js index 4b8fd589..c5d2e4c9 100644 --- a/build/get-webpack-config.js +++ b/build/get-webpack-config.js @@ -60,6 +60,7 @@ const EXCLUDE_TRANSPILATION_PATTERNS = [ /node_modules\/react\//, /node_modules\/core-js\//, ]; + const JS_EXT_PATTERN = /\.jsx?$/; /*:: @@ -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`); } @@ -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: [ { @@ -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: [ { @@ -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: [ { diff --git a/build/load-fusionrc.js b/build/load-fusionrc.js index 5d20f9d0..9ce230b0 100644 --- a/build/load-fusionrc.js +++ b/build/load-fusionrc.js @@ -18,6 +18,7 @@ let loggedNotice = false; /*:: export type FusionRC = { babel?: {plugins?: Array, presets?: Array}, + jsExtPattern?: RegExp, assumeNoImportSideEffects?: boolean, experimentalCompile?: boolean, nodeBuiltins?: {[string]: any}, @@ -59,6 +60,7 @@ function isValid(config) { !Object.keys(config).every(key => [ 'babel', + 'jsExtPattern', 'assumeNoImportSideEffects', 'experimentalCompile', 'nodeBuiltins', diff --git a/docs/fusionrc.md b/docs/fusionrc.md index e0137d09..e3575232 100644 --- a/docs/fusionrc.md +++ b/docs/fusionrc.md @@ -4,6 +4,21 @@ 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"], + } +}; +``` + ## `babel` ### Adding plugins/presets From c3bdd9ebf169c3a79e8e17528dd2288f9d627c14 Mon Sep 17 00:00:00 2001 From: Piotr Monarski Date: Fri, 22 Feb 2019 10:00:38 +0100 Subject: [PATCH 2/2] Add resolveExtensions in fusionrc.js option --- build/get-webpack-config.js | 1 + build/load-fusionrc.js | 2 ++ docs/fusionrc.md | 10 ++++++++++ 3 files changed, 13 insertions(+) diff --git a/build/get-webpack-config.js b/build/get-webpack-config.js index c5d2e4c9..f72677ef 100644 --- a/build/get-webpack-config.js +++ b/build/get-webpack-config.js @@ -404,6 +404,7 @@ function getWebpackConfig(opts /*: WebpackConfigOpts */) { __FUSION_ENTRY_PATH__: path.join(dir, main), __ENV__: env, }, + extensions: fusionConfig.resolveExtensions, }, resolveLoader: { alias: { diff --git a/build/load-fusionrc.js b/build/load-fusionrc.js index 9ce230b0..efa4c959 100644 --- a/build/load-fusionrc.js +++ b/build/load-fusionrc.js @@ -19,6 +19,7 @@ let loggedNotice = false; export type FusionRC = { babel?: {plugins?: Array, presets?: Array}, jsExtPattern?: RegExp, + resolveExtensions?: Array, assumeNoImportSideEffects?: boolean, experimentalCompile?: boolean, nodeBuiltins?: {[string]: any}, @@ -61,6 +62,7 @@ function isValid(config) { [ 'babel', 'jsExtPattern', + 'resolveExtensions', 'assumeNoImportSideEffects', 'experimentalCompile', 'nodeBuiltins', diff --git a/docs/fusionrc.md b/docs/fusionrc.md index e3575232..a5948c76 100644 --- a/docs/fusionrc.md +++ b/docs/fusionrc.md @@ -19,6 +19,16 @@ module.exports = { }; ``` +## `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