nx/packages/react/plugins/webpack.ts
Victor Savkin 7679df22f5 Revert "feat(react): refactored babel support so options are more easily customized (#3058)"
This reverts commit 0e036272cbe156fe9750a2f2bc6498a08cf7f457.
2020-05-28 13:11:56 -04:00

58 lines
1.4 KiB
TypeScript

import { Configuration } from 'webpack';
import { updateBabelOptions } from '../src/utils/babel-utils';
// Add React-specific configuration
function getWebpackConfig(config: Configuration) {
const idx = config.module.rules.findIndex((r) => r.loader === 'babel-loader');
const babelRuleOptions = config.module.rules[idx].options as any;
updateBabelOptions(babelRuleOptions);
config.module.rules.push(
{
test: /\.(png|jpe?g|gif|webp)$/,
loader: 'url-loader',
options: {
limit: 10000, // 10kB
name: '[name].[hash:7].[ext]',
},
},
{
test: /\.svg$/,
oneOf: [
// If coming from JS/TS file, then transform into React component using SVGR.
{
issuer: {
test: /\.[jt]sx?$/,
},
use: [
'@svgr/webpack?-svgo,+titleProp,+ref![path]',
{
loader: 'url-loader',
options: {
limit: 10000, // 10kB
name: '[name].[hash:7].[ext]',
},
},
],
},
// Fallback to plain URL loader.
{
use: [
{
loader: 'url-loader',
options: {
limit: 10000, // 10kB
name: '[name].[hash:7].[ext]',
},
},
],
},
],
}
);
return config;
}
module.exports = getWebpackConfig;