mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-12 16:47:26 +02:00
misc(v2): misc fixes
This commit is contained in:
parent
95b0cb942f
commit
d64581f2b4
9 changed files with 27 additions and 34 deletions
|
@ -30,6 +30,7 @@ module.exports = {
|
|||
'react/jsx-closing-bracket-location': OFF, // Conflicts with Prettier.
|
||||
'react/jsx-filename-extension': OFF,
|
||||
'react/jsx-one-expression-per-line': OFF,
|
||||
'react/no-array-index-key': OFF, // Sometimes its ok, e.g. non-changing data.
|
||||
'react/prop-types': OFF,
|
||||
'react/destructuring-assignment': OFF, // Too many lines.
|
||||
'import/no-unresolved': WARNING, // Because it couldn't resolve webpack alias.
|
||||
|
|
|
@ -47,7 +47,7 @@ module.exports = async function build(siteDir) {
|
|||
let serverConfig = createServerConfig(props).toConfig();
|
||||
let clientConfig = createClientConfig(props).toConfig();
|
||||
|
||||
// apply user webpack config
|
||||
// Apply user webpack config.
|
||||
const {
|
||||
siteConfig: {configureWebpack},
|
||||
} = props;
|
||||
|
@ -61,7 +61,7 @@ module.exports = async function build(siteDir) {
|
|||
// Build the server bundles (render the static HTML and pick client bundle)
|
||||
await compile(serverConfig);
|
||||
|
||||
// copy static files
|
||||
// Copy static files.
|
||||
const {outDir} = props;
|
||||
const staticDir = path.resolve(siteDir, 'static');
|
||||
const staticFiles = await globby(['**'], {
|
||||
|
@ -75,7 +75,7 @@ module.exports = async function build(siteDir) {
|
|||
}),
|
||||
);
|
||||
|
||||
// generate sitemap
|
||||
// Generate sitemap.
|
||||
const sitemap = await createSitemap(props);
|
||||
const sitemapPath = path.join(outDir, 'sitemap.xml');
|
||||
await fs.writeFile(sitemapPath, sitemap);
|
||||
|
|
|
@ -49,8 +49,8 @@ module.exports = async function start(siteDir, cliOptions = {}) {
|
|||
const docsRelativeDir = props.siteConfig.customDocsPath;
|
||||
const fsWatcher = chokidar.watch(
|
||||
[
|
||||
// TODO: Watch plugin paths (e.g. blog)
|
||||
`../${docsRelativeDir}/**/*.md`,
|
||||
'blog/**/*.md',
|
||||
loadConfig.configFileName,
|
||||
'sidebars.json',
|
||||
],
|
||||
|
@ -59,11 +59,9 @@ module.exports = async function start(siteDir, cliOptions = {}) {
|
|||
ignoreInitial: true,
|
||||
},
|
||||
);
|
||||
fsWatcher.on('add', reload);
|
||||
fsWatcher.on('change', reload);
|
||||
fsWatcher.on('unlink', reload);
|
||||
fsWatcher.on('addDir', reload);
|
||||
fsWatcher.on('unlinkDir', reload);
|
||||
['add', 'change', 'unlink', 'addDir', 'unlinkDir'].forEach(event =>
|
||||
fsWatcher.on(event, reload),
|
||||
);
|
||||
}
|
||||
|
||||
const port = await getPort(cliOptions.port);
|
||||
|
|
|
@ -13,7 +13,7 @@ import App from './App';
|
|||
import preload from './preload';
|
||||
import routes from '@generated/routes'; // eslint-disable-line
|
||||
|
||||
// Client side render (e.g: running in browser) to become single-page application (SPA)
|
||||
// Client-side render (e.g: running in browser) to become single-page application (SPA).
|
||||
if (typeof window !== 'undefined' && typeof document !== 'undefined') {
|
||||
preload(routes, window.location.pathname).then(() => {
|
||||
ReactDOM.render(
|
||||
|
|
|
@ -50,8 +50,7 @@ export default function render(locals) {
|
|||
const cssFiles = assets.filter(value => value.match(/\.css$/));
|
||||
const {baseUrl} = locals;
|
||||
|
||||
const html = `
|
||||
<!DOCTYPE html>
|
||||
return `<!DOCTYPE html>
|
||||
<html${htmlAttributes ? ` ${htmlAttributes}` : ''}>
|
||||
<head>
|
||||
${metaHtml}
|
||||
|
@ -75,6 +74,5 @@ export default function render(locals) {
|
|||
</body>
|
||||
</html>
|
||||
`;
|
||||
return html;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -29,21 +29,17 @@ module.exports = async function createSitemap({
|
|||
);
|
||||
}
|
||||
|
||||
const urls = [];
|
||||
const urls = allMetadatas.map(metadata => ({
|
||||
url: metadata.permalink,
|
||||
changefreq: 'weekly',
|
||||
priority: 0.5,
|
||||
}));
|
||||
|
||||
allMetadatas.forEach(metadata => {
|
||||
urls.push({
|
||||
url: metadata.permalink,
|
||||
changefreq: 'weekly',
|
||||
priority: 0.5,
|
||||
});
|
||||
});
|
||||
|
||||
const sm = sitemap.createSitemap({
|
||||
const generatedSitemap = sitemap.createSitemap({
|
||||
hostname: siteUrl,
|
||||
cacheTime: 600 * 1000, // 600 sec - cache purge period
|
||||
urls,
|
||||
});
|
||||
|
||||
return sm.toString();
|
||||
return generatedSitemap.toString();
|
||||
};
|
||||
|
|
|
@ -34,8 +34,8 @@ function BlogPage(props) {
|
|||
</li>
|
||||
))}
|
||||
</ul>
|
||||
{BlogPosts.map(BlogPost => (
|
||||
<BlogPost />
|
||||
{BlogPosts.map((BlogPost, index) => (
|
||||
<BlogPost key={index} />
|
||||
))}
|
||||
</div>
|
||||
</Layout>
|
||||
|
|
|
@ -146,7 +146,7 @@ module.exports = function createBaseConfig(props, isServer) {
|
|||
}).test(CSS_MODULE_REGEX);
|
||||
|
||||
// mini-css-extract plugin
|
||||
config.plugin('extract-css').use(CSSExtractPlugin, [
|
||||
config.plugin('extractCSS').use(CSSExtractPlugin, [
|
||||
{
|
||||
filename: isProd ? '[name].[chunkhash].css' : '[name].css',
|
||||
chunkFilename: isProd ? '[id].[chunkhash].css' : '[id].css',
|
||||
|
|
|
@ -5,11 +5,12 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
const cleanWebpackPlugin = require('clean-webpack-plugin');
|
||||
const path = require('path');
|
||||
const webpackNiceLog = require('webpack-nicelog');
|
||||
const {StatsWriterPlugin} = require('webpack-stats-plugin');
|
||||
const {ReactLoadablePlugin} = require('react-loadable/webpack');
|
||||
const cleanWebpackPlugin = require('clean-webpack-plugin');
|
||||
|
||||
const createBaseConfig = require('./base');
|
||||
const {applyChainWebpack} = require('./utils');
|
||||
|
||||
|
@ -17,18 +18,17 @@ module.exports = function createClientConfig(props) {
|
|||
const config = createBaseConfig(props);
|
||||
config.entry('main').add(path.resolve(__dirname, '../core/clientEntry.js'));
|
||||
|
||||
// Remove/clean build folders before building bundles.
|
||||
const {outDir} = props;
|
||||
// Remove/clean build folders before building bundles.
|
||||
config
|
||||
.plugin('clean')
|
||||
.use(cleanWebpackPlugin, [outDir, {verbose: false, allowExternal: true}]);
|
||||
|
||||
// write webpack stats object so we can pickup correct client bundle path in server.
|
||||
// Write webpack stats object so we can pickup correct client bundle path in server.
|
||||
config
|
||||
.plugin('client-stats')
|
||||
.plugin('clientStats')
|
||||
.use(StatsWriterPlugin, [{filename: 'client.stats.json'}]);
|
||||
config
|
||||
.plugin('react-loadable-stats')
|
||||
.plugin('reactLoadableStats')
|
||||
.use(ReactLoadablePlugin, [
|
||||
{filename: path.join(outDir, 'react-loadable.json')},
|
||||
]);
|
||||
|
@ -39,7 +39,7 @@ module.exports = function createClientConfig(props) {
|
|||
.plugin('niceLog')
|
||||
.use(webpackNiceLog, [{name: 'Client', skipBuildTime: isProd}]);
|
||||
|
||||
// user extended webpack-chain config
|
||||
// User-extended webpack-chain config.
|
||||
applyChainWebpack(props.siteConfig.chainWebpack, config, false);
|
||||
|
||||
return config;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue