mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-04 20:57:17 +02:00
refactor(v2): move unused generated files out from build folder (#2033)
This commit is contained in:
parent
d1f84709e0
commit
cea224b03d
5 changed files with 12 additions and 9 deletions
|
@ -45,12 +45,12 @@ export default async function render(locals) {
|
|||
];
|
||||
const metaAttributes = metaStrings.filter(Boolean);
|
||||
|
||||
const {outDir} = locals;
|
||||
const manifestPath = path.join(outDir, 'client-manifest.json');
|
||||
const {generatedFilesDir} = locals;
|
||||
const manifestPath = path.join(generatedFilesDir, 'client-manifest.json');
|
||||
const manifest = JSON.parse(await fs.readFile(manifestPath, 'utf8'));
|
||||
|
||||
// chunkName -> chunkAssets mapping.
|
||||
const chunkManifestPath = path.join(outDir, 'chunk-map.json');
|
||||
const chunkManifestPath = path.join(generatedFilesDir, 'chunk-map.json');
|
||||
const chunkManifest = JSON.parse(
|
||||
await fs.readFile(chunkManifestPath, 'utf8'),
|
||||
);
|
||||
|
|
|
@ -55,7 +55,7 @@ export async function build(
|
|||
const props: Props = await load(siteDir);
|
||||
|
||||
// Apply user webpack config.
|
||||
const {outDir, plugins} = props;
|
||||
const {outDir, generatedFilesDir, plugins} = props;
|
||||
|
||||
let clientConfig: Configuration = merge(createClientConfig(props), {
|
||||
plugins: [
|
||||
|
@ -65,7 +65,7 @@ export async function build(
|
|||
cliOptions.bundleAnalyzer && new BundleAnalyzerPlugin(),
|
||||
// Generate client manifests file that will be used for server bundle
|
||||
new ReactLoadableSSRAddon({
|
||||
filename: 'client-manifest.json',
|
||||
filename: path.join(generatedFilesDir, 'client-manifest.json'),
|
||||
}),
|
||||
].filter(Boolean) as Plugin[],
|
||||
});
|
||||
|
|
|
@ -30,6 +30,7 @@ export function createClientConfig(props: Props): Configuration {
|
|||
// Generate chunk-map.json (mapping of chunk names to their corresponding chunk assets)
|
||||
new ChunkManifestPlugin({
|
||||
filename: 'chunk-map.json',
|
||||
outputPath: props.generatedFilesDir,
|
||||
manifestVariable: '__chunkMapping',
|
||||
inlineManifest: !isProd,
|
||||
}),
|
||||
|
|
|
@ -15,6 +15,7 @@ class ChunkManifestPlugin {
|
|||
constructor(options) {
|
||||
this.options = {
|
||||
filename: 'manifest.json',
|
||||
outputPath: null,
|
||||
manifestVariable: 'webpackManifest',
|
||||
inlineManifest: false,
|
||||
...options,
|
||||
|
@ -23,7 +24,7 @@ class ChunkManifestPlugin {
|
|||
|
||||
apply(compiler) {
|
||||
let chunkManifest;
|
||||
const {path: outputPath, publicPath} = compiler.options.output;
|
||||
const {path: defaultOutputPath, publicPath} = compiler.options.output;
|
||||
|
||||
// Build the chunk mapping
|
||||
compiler.hooks.afterCompile.tapAsync(pluginName, (compilation, done) => {
|
||||
|
@ -49,6 +50,7 @@ class ChunkManifestPlugin {
|
|||
}
|
||||
chunkManifest = assetsMap;
|
||||
if (!this.options.inlineManifest) {
|
||||
const outputPath = this.options.outputPath || defaultOutputPath;
|
||||
const finalPath = path.resolve(outputPath, this.options.filename);
|
||||
fs.ensureDir(path.dirname(finalPath), () => {
|
||||
fs.writeFile(finalPath, JSON.stringify(chunkManifest, null, 2), done);
|
||||
|
|
|
@ -16,7 +16,7 @@ import WaitPlugin from './plugins/WaitPlugin';
|
|||
import LogPlugin from './plugins/LogPlugin';
|
||||
|
||||
export function createServerConfig(props: Props): Configuration {
|
||||
const {baseUrl, routesPaths, outDir} = props;
|
||||
const {baseUrl, routesPaths, generatedFilesDir} = props;
|
||||
const config = createBaseConfig(props, true);
|
||||
|
||||
const routesLocation = {};
|
||||
|
@ -41,7 +41,7 @@ export function createServerConfig(props: Props): Configuration {
|
|||
plugins: [
|
||||
// Wait until manifest from client bundle is generated
|
||||
new WaitPlugin({
|
||||
filepath: path.join(outDir, 'client-manifest.json'),
|
||||
filepath: path.join(generatedFilesDir, 'client-manifest.json'),
|
||||
}),
|
||||
|
||||
// Static site generator webpack plugin.
|
||||
|
@ -49,7 +49,7 @@ export function createServerConfig(props: Props): Configuration {
|
|||
entry: 'main',
|
||||
locals: {
|
||||
baseUrl,
|
||||
outDir,
|
||||
generatedFilesDir,
|
||||
routesLocation,
|
||||
},
|
||||
paths: ssgPaths,
|
||||
|
|
Loading…
Add table
Reference in a new issue