Skip to content

Commit 61923a2

Browse files
committed
feat: add 'enableReact' flag
1 parent cf8ad9a commit 61923a2

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/index.cjs

+9-6
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@ const toPath = path => {
2626
class ScratchWebpackConfigBuilder {
2727
/**
2828
* @param {object} options Options for the webpack configuration.
29-
* @param {string} [options.libraryName] The name of the library to build. Shorthand for `output.library.name`.
3029
* @param {string|URL} options.rootPath The absolute path to the project root.
31-
* @param {string|URL} [options.srcPath] The absolute path to the source files. Defaults to `src` under `rootPath`.
3230
* @param {string|URL} [options.distPath] The absolute path to build output. Defaults to `dist` under `rootPath`.
31+
* @param {boolean} [options.enableReact] Whether to enable React and JSX support.
32+
* @param {string} [options.libraryName] The name of the library to build. Shorthand for `output.library.name`.
33+
* @param {string|URL} [options.srcPath] The absolute path to the source files. Defaults to `src` under `rootPath`.
3334
*/
34-
constructor ({libraryName, rootPath, srcPath, distPath}) {
35+
constructor ({distPath, enableReact, libraryName, rootPath, srcPath}) {
3536
const isProduction = process.env.NODE_ENV === 'production';
3637
const mode = isProduction ? 'production' : 'development';
3738

@@ -64,12 +65,14 @@ class ScratchWebpackConfigBuilder {
6465
module: {
6566
rules: [{
6667
include: this._srcPath,
67-
test: /\.jsx?$/,
68+
test: enableReact ? /\.jsx?$/ : /\.js$/,
6869
loader: 'babel-loader',
6970
options: {
7071
presets: [
71-
// Use the browserslist setting from package.json
72-
'@babel/preset-env'
72+
'@babel/preset-env',
73+
...(
74+
enableReact ? ['@babel/preset-react'] : []
75+
)
7376
]
7477
}
7578
}]

0 commit comments

Comments
 (0)