Skip to content

Commit

Permalink
refactor(v2): move unused generated files out from build folder
Browse files Browse the repository at this point in the history
  • Loading branch information
endiliey committed Nov 23, 2019
1 parent 2d15fad commit e032222
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
6 changes: 3 additions & 3 deletions packages/docusaurus/src/client/serverEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
);
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand All @@ -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[],
});
Expand Down
1 change: 1 addition & 0 deletions packages/docusaurus/src/webpack/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class ChunkManifestPlugin {
constructor(options) {
this.options = {
filename: 'manifest.json',
outputPath: null,
manifestVariable: 'webpackManifest',
inlineManifest: false,
...options,
Expand All @@ -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) => {
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions packages/docusaurus/src/webpack/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand All @@ -41,15 +41,15 @@ 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.
new StaticSiteGeneratorPlugin({
entry: 'main',
locals: {
baseUrl,
outDir,
generatedFilesDir,
routesLocation,
},
paths: ssgPaths,
Expand Down

0 comments on commit e032222

Please sign in to comment.