-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(webpack): remove support for legacy browsers (nrwl#14190)
- Loading branch information
Showing
30 changed files
with
1,063 additions
and
1,570 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
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,58 +1,77 @@ | ||
import type { Configuration } from 'webpack'; | ||
import ReactRefreshPlugin = require('@pmmmwh/react-refresh-webpack-plugin'); | ||
import { NormalizedWebpackExecutorOptions } from '@nrwl/webpack'; | ||
import { ExecutorContext } from 'nx/src/config/misc-interfaces'; | ||
|
||
// Add React-specific configuration | ||
export function getWebpackConfig(config: Configuration) { | ||
config.module.rules.push({ | ||
test: /\.svg$/, | ||
issuer: /\.(js|ts|md)x?$/, | ||
use: [ | ||
{ | ||
loader: require.resolve('@svgr/webpack'), | ||
options: { | ||
svgo: false, | ||
titleProp: true, | ||
ref: true, | ||
export function withReact() { | ||
return function configure( | ||
config: Configuration, | ||
_ctx?: { | ||
options: NormalizedWebpackExecutorOptions; | ||
context: ExecutorContext; | ||
} | ||
): Configuration { | ||
config.module.rules.push({ | ||
test: /\.svg$/, | ||
issuer: /\.(js|ts|md)x?$/, | ||
use: [ | ||
{ | ||
loader: require.resolve('@svgr/webpack'), | ||
options: { | ||
svgo: false, | ||
titleProp: true, | ||
ref: true, | ||
}, | ||
}, | ||
}, | ||
{ | ||
loader: require.resolve('file-loader'), | ||
options: { | ||
name: '[name].[hash].[ext]', | ||
{ | ||
loader: require.resolve('file-loader'), | ||
options: { | ||
name: '[name].[hash].[ext]', | ||
}, | ||
}, | ||
}, | ||
], | ||
}); | ||
], | ||
}); | ||
|
||
if (config.mode === 'development' && config['devServer']?.hot) { | ||
// add `react-refresh/babel` to babel loader plugin | ||
const babelLoader = config.module.rules.find( | ||
(rule) => | ||
typeof rule !== 'string' && | ||
rule.loader?.toString().includes('babel-loader') | ||
); | ||
if (babelLoader && typeof babelLoader !== 'string') { | ||
babelLoader.options['plugins'] = [ | ||
...(babelLoader.options['plugins'] || []), | ||
[ | ||
require.resolve('react-refresh/babel'), | ||
{ | ||
skipEnvCheck: true, | ||
}, | ||
], | ||
]; | ||
if (config.mode === 'development' && config['devServer']?.hot) { | ||
// add `react-refresh/babel` to babel loader plugin | ||
const babelLoader = config.module.rules.find( | ||
(rule) => | ||
typeof rule !== 'string' && | ||
rule.loader?.toString().includes('babel-loader') | ||
); | ||
if (babelLoader && typeof babelLoader !== 'string') { | ||
babelLoader.options['plugins'] = [ | ||
...(babelLoader.options['plugins'] || []), | ||
[ | ||
require.resolve('react-refresh/babel'), | ||
{ | ||
skipEnvCheck: true, | ||
}, | ||
], | ||
]; | ||
} | ||
// add https://github.com/pmmmwh/react-refresh-webpack-plugin to webpack plugin | ||
config.plugins.push(new ReactRefreshPlugin()); | ||
} | ||
// add https://github.com/pmmmwh/react-refresh-webpack-plugin to webpack plugin | ||
config.plugins.push(new ReactRefreshPlugin()); | ||
} | ||
|
||
// enable webpack node api | ||
config.node = { | ||
__dirname: true, | ||
__filename: true, | ||
}; | ||
// enable webpack node api | ||
config.node = { | ||
__dirname: true, | ||
__filename: true, | ||
}; | ||
|
||
return config; | ||
return config; | ||
}; | ||
} | ||
|
||
module.exports = getWebpackConfig; | ||
// Support existing default exports as well as new named export. | ||
const legacyExport: any = withReact(); | ||
legacyExport.withReact = withReact; | ||
|
||
/** @deprecated use `import { withReact } from '@nrwl/react'` */ | ||
// This is here for backward compatibility if anyone imports {getWebpackConfig} directly. | ||
// TODO(jack): Remove in Nx 16 | ||
legacyExport.getWebpackConfig = withReact(); | ||
|
||
export default legacyExport; |
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
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
Oops, something went wrong.