fix(react): allow async functions to work with custom webpack config (#11467)
This commit is contained in:
parent
a829270344
commit
dec910274b
@ -1,20 +1,20 @@
|
|||||||
import {
|
import {
|
||||||
checkFilesDoNotExist,
|
checkFilesDoNotExist,
|
||||||
checkFilesExist,
|
checkFilesExist,
|
||||||
|
cleanupProject,
|
||||||
createFile,
|
createFile,
|
||||||
isNotWindows,
|
isNotWindows,
|
||||||
killPorts,
|
killPorts,
|
||||||
newProject,
|
newProject,
|
||||||
readFile,
|
readFile,
|
||||||
removeFile,
|
removeFile,
|
||||||
cleanupProject,
|
rmDist,
|
||||||
runCLI,
|
runCLI,
|
||||||
runCLIAsync,
|
runCLIAsync,
|
||||||
runCypressTests,
|
runCypressTests,
|
||||||
uniq,
|
uniq,
|
||||||
updateFile,
|
updateFile,
|
||||||
updateProjectConfig,
|
updateProjectConfig,
|
||||||
expectJestTestsToPass,
|
|
||||||
} from '@nrwl/e2e/utils';
|
} from '@nrwl/e2e/utils';
|
||||||
|
|
||||||
describe('Web Components Applications', () => {
|
describe('Web Components Applications', () => {
|
||||||
@ -38,7 +38,7 @@ describe('Web Components Applications', () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
expect(readFile(`dist/apps/${appName}/index.html`)).toContain(
|
expect(readFile(`dist/apps/${appName}/index.html`)).toContain(
|
||||||
`<link rel="stylesheet" href="styles.css">`
|
'<link rel="stylesheet" href="styles.css">'
|
||||||
);
|
);
|
||||||
|
|
||||||
const testResults = await runCLIAsync(`test ${appName}`);
|
const testResults = await runCLIAsync(`test ${appName}`);
|
||||||
@ -188,8 +188,54 @@ describe('Web Components Applications', () => {
|
|||||||
).not.toThrow();
|
).not.toThrow();
|
||||||
}, 1000000);
|
}, 1000000);
|
||||||
|
|
||||||
it('should run default jest tests', async () => {
|
it('should support custom webpackConfig option', async () => {
|
||||||
await expectJestTestsToPass('@nrwl/web:app');
|
const appName = uniq('app');
|
||||||
|
runCLI(`generate @nrwl/web:app ${appName} --no-interactive`);
|
||||||
|
|
||||||
|
updateProjectConfig(appName, (config) => {
|
||||||
|
config.targets.build.options.webpackConfig = `apps/${appName}/webpack.config.js`;
|
||||||
|
return config;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Return sync function
|
||||||
|
updateFile(
|
||||||
|
`apps/${appName}/webpack.config.js`,
|
||||||
|
`
|
||||||
|
module.exports = (config, context) => {
|
||||||
|
return config;
|
||||||
|
};
|
||||||
|
`
|
||||||
|
);
|
||||||
|
runCLI(`build ${appName} --outputHashing none`);
|
||||||
|
checkFilesExist(`dist/apps/${appName}/main.esm.js`);
|
||||||
|
|
||||||
|
rmDist();
|
||||||
|
|
||||||
|
// Return async function
|
||||||
|
updateFile(
|
||||||
|
`apps/${appName}/webpack.config.js`,
|
||||||
|
`
|
||||||
|
module.exports = async (config, context) => {
|
||||||
|
return config;
|
||||||
|
};
|
||||||
|
`
|
||||||
|
);
|
||||||
|
runCLI(`build ${appName} --outputHashing none`);
|
||||||
|
checkFilesExist(`dist/apps/${appName}/main.esm.js`);
|
||||||
|
|
||||||
|
rmDist();
|
||||||
|
|
||||||
|
// Return promise of function
|
||||||
|
updateFile(
|
||||||
|
`apps/${appName}/webpack.config.js`,
|
||||||
|
`
|
||||||
|
module.exports = Promise.resolve((config, context) => {
|
||||||
|
return config;
|
||||||
|
});
|
||||||
|
`
|
||||||
|
);
|
||||||
|
runCLI(`build ${appName} --outputHashing none`);
|
||||||
|
checkFilesExist(`dist/apps/${appName}/main.esm.js`);
|
||||||
}, 100000);
|
}, 100000);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -377,7 +423,6 @@ describe('index.html interpolation', () => {
|
|||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<title>BestReactApp</title>
|
<title>BestReactApp</title>
|
||||||
<base href="/" />
|
<base href="/" />
|
||||||
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
<link rel="icon" type="image/x-icon" href="favicon.ico" />
|
<link rel="icon" type="image/x-icon" href="favicon.ico" />
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
@ -85,7 +85,7 @@ export default async function* devServerExecutor(
|
|||||||
customWebpack = await customWebpack;
|
customWebpack = await customWebpack;
|
||||||
}
|
}
|
||||||
|
|
||||||
webpackConfig = customWebpack(webpackConfig, {
|
webpackConfig = await customWebpack(webpackConfig, {
|
||||||
buildOptions,
|
buildOptions,
|
||||||
configuration: serveOptions.buildTarget.split(':')[2],
|
configuration: serveOptions.buildTarget.split(':')[2],
|
||||||
});
|
});
|
||||||
|
|||||||
@ -101,7 +101,8 @@ async function getWebpackConfigs(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return await Promise.all(
|
||||||
|
[
|
||||||
// ESM build for modern browsers.
|
// ESM build for modern browsers.
|
||||||
getWebConfig(
|
getWebConfig(
|
||||||
context.root,
|
context.root,
|
||||||
@ -126,16 +127,17 @@ async function getWebpackConfigs(
|
|||||||
: undefined,
|
: undefined,
|
||||||
]
|
]
|
||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
.map((config) => {
|
.map(async (config) => {
|
||||||
if (customWebpack) {
|
if (customWebpack) {
|
||||||
return customWebpack(config, {
|
return await customWebpack(config, {
|
||||||
options,
|
options,
|
||||||
configuration: context.configurationName,
|
configuration: context.configurationName,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function* run(
|
export async function* run(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user