diff --git a/v2/.eslintrc.js b/v2/.eslintrc.js index 9e7e5e8016..19c4eec318 100644 --- a/v2/.eslintrc.js +++ b/v2/.eslintrc.js @@ -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. diff --git a/v2/lib/commands/build.js b/v2/lib/commands/build.js index 6a02b37f07..69f47c73a2 100644 --- a/v2/lib/commands/build.js +++ b/v2/lib/commands/build.js @@ -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); diff --git a/v2/lib/commands/start.js b/v2/lib/commands/start.js index 2e62b28aee..e4ff49f617 100644 --- a/v2/lib/commands/start.js +++ b/v2/lib/commands/start.js @@ -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); diff --git a/v2/lib/core/clientEntry.js b/v2/lib/core/clientEntry.js index 8e32531fde..4957db3f74 100644 --- a/v2/lib/core/clientEntry.js +++ b/v2/lib/core/clientEntry.js @@ -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( diff --git a/v2/lib/core/serverEntry.js b/v2/lib/core/serverEntry.js index fd742fea86..b749e89bdf 100644 --- a/v2/lib/core/serverEntry.js +++ b/v2/lib/core/serverEntry.js @@ -50,8 +50,7 @@ export default function render(locals) { const cssFiles = assets.filter(value => value.match(/\.css$/)); const {baseUrl} = locals; - const html = ` - + return ` ${metaHtml} @@ -75,6 +74,5 @@ export default function render(locals) { `; - return html; }); } diff --git a/v2/lib/core/sitemap.js b/v2/lib/core/sitemap.js index f1b3033194..af5226d8f2 100644 --- a/v2/lib/core/sitemap.js +++ b/v2/lib/core/sitemap.js @@ -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(); }; diff --git a/v2/lib/theme/BlogPage/index.js b/v2/lib/theme/BlogPage/index.js index 7ba7df383b..eb8d1e5e5a 100644 --- a/v2/lib/theme/BlogPage/index.js +++ b/v2/lib/theme/BlogPage/index.js @@ -34,8 +34,8 @@ function BlogPage(props) { ))} - {BlogPosts.map(BlogPost => ( - + {BlogPosts.map((BlogPost, index) => ( + ))} diff --git a/v2/lib/webpack/base.js b/v2/lib/webpack/base.js index 0ae90356ea..a83779172e 100644 --- a/v2/lib/webpack/base.js +++ b/v2/lib/webpack/base.js @@ -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', diff --git a/v2/lib/webpack/client.js b/v2/lib/webpack/client.js index 69d9638ea6..b0ccb8cde1 100644 --- a/v2/lib/webpack/client.js +++ b/v2/lib/webpack/client.js @@ -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;