-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rspack): Update configuration generator to support NxWebpackAppP…
…lugin
- Loading branch information
1 parent
1c2ae37
commit 1944ac9
Showing
6 changed files
with
340 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
packages/react/src/generators/application/files/base-rspack/rspack.config.js__tmpl__
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<%_ if (rspackPluginOptions) { _%> | ||
const { NxAppRspackPlugin } = require('@nx/rspack/app-plugin'); | ||
const { NxReactRspackPlugin } = require('@nx/rspack/react-plugin'); | ||
const { join } = require('path'); | ||
|
||
module.exports = { | ||
output: { | ||
path: join(__dirname, '<%= offsetFromRoot %><%= rspackPluginOptions.outputPath %>'), | ||
}, | ||
devServer: { | ||
port: 4200, | ||
historyApiFallback: { | ||
index: '/index.html', | ||
disableDotRule: true, | ||
htmlAcceptHeaders: ['text/html', 'application/xhtml+xml'], | ||
}, | ||
}, | ||
plugins: [ | ||
new NxAppRspackPlugin({ | ||
tsConfig: '<%= rspackPluginOptions.tsConfig %>', | ||
main: '<%= rspackPluginOptions.main %>', | ||
index: '<%= rspackPluginOptions.index %>', | ||
baseHref: '<%= rspackPluginOptions.baseHref %>', | ||
assets: <%- JSON.stringify(rspackPluginOptions.assets) %>, | ||
styles: <%- JSON.stringify(rspackPluginOptions.styles) %>, | ||
outputHashing: process.env['NODE_ENV'] === 'production' ? 'all' : 'none', | ||
optimization: process.env['NODE_ENV'] === 'production', | ||
}), | ||
new NxReactRspackPlugin({ | ||
// Uncomment this line if you don't want to use SVGR | ||
// See: https://react-svgr.com/ | ||
// svgr: false | ||
}), | ||
], | ||
}; | ||
<%_ } else { _%> | ||
const { composePlugins, withNx, withReact } = require('@nx/rspack'); | ||
|
||
// Nx plugins for rspack. | ||
module.exports = composePlugins( | ||
withNx(), | ||
withReact({ | ||
// Uncomment this line if you don't want to use SVGR | ||
// See: https://react-svgr.com/ | ||
// svgr: false | ||
}), | ||
(config) => { | ||
// Update the rspack config as needed here. | ||
// e.g. `config.plugins.push(new MyPlugin())` | ||
return config; | ||
} | ||
); | ||
<%_ } _%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { readNxJson, Tree } from '@nx/devkit'; | ||
|
||
export function hasRspackPlugin(tree: Tree) { | ||
const nxJson = readNxJson(tree); | ||
return !!nxJson.plugins?.some((p) => | ||
typeof p === 'string' | ||
? p === '@nx/rspack/plugin' | ||
: p.plugin === '@nx/rspack/plugin' | ||
); | ||
} |
Oops, something went wrong.