fix(next): fix withNx with nx property doesn't exist (#11900)

This commit is contained in:
Jason Jean 2022-09-06 14:33:15 -07:00 committed by GitHub
parent f9ef42e8c2
commit c64dbdec24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 53 additions and 2 deletions

View File

@ -0,0 +1,51 @@
import { withNx } from './with-nx';
describe('withNx', () => {
describe('svgr', () => {
it('should be used by default', () => {
const config = withNx({});
const result = config.webpack(
{
module: { rules: [{ oneOf: [] }] },
},
{
defaultLoaders: {
babel: {
options: {},
},
},
}
);
expect(
result.module.rules.some((rule) => rule.test?.test('cat.svg'))
).toBe(true);
});
it('should not be used when disabled', () => {
const config = withNx({
nx: {
svgr: false,
},
});
const result = config.webpack(
{
module: { rules: [{ oneOf: [] }] },
},
{
defaultLoaders: {
babel: {
options: {},
},
},
}
);
expect(
result.module.rules.some((rule) => rule.test?.test('cat.svg'))
).toBe(false);
});
});
});

View File

@ -128,7 +128,7 @@ export function withNx(nextConfig = {} as WithNxOptions) {
*/
// Default SVGR support to be on for projects.
if (nx.svgr !== false) {
if (nx?.svgr !== false) {
config.module.rules.push({
test: /\.svg$/,
oneOf: [
@ -180,7 +180,7 @@ function getNxEnvironmentVariables() {
}
function addNxEnvVariables(config: any) {
const maybeDefinePlugin = config.plugins.find((plugin) => {
const maybeDefinePlugin = config.plugins?.find((plugin) => {
return plugin.definitions?.['process.env.NODE_ENV'];
});