From dcb733a63a7037a063b7d29af820b4d8e94f9af8 Mon Sep 17 00:00:00 2001 From: endiliey Date: Mon, 17 Sep 2018 12:09:14 +0800 Subject: [PATCH] v2: nits --- v2/lib/theme/Loading.js | 2 +- v2/lib/webpack/base.js | 266 ++++++++++++++++++++-------------------- 2 files changed, 134 insertions(+), 134 deletions(-) diff --git a/v2/lib/theme/Loading.js b/v2/lib/theme/Loading.js index 44443ff411..910e0032f4 100644 --- a/v2/lib/theme/Loading.js +++ b/v2/lib/theme/Loading.js @@ -2,7 +2,7 @@ import React from 'react'; export default props => { if (props.error) { - return
Error 🔥🔥🔥
; + return
Error
; } if (props.pastDelay) { return
Loading...
; diff --git a/v2/lib/webpack/base.js b/v2/lib/webpack/base.js index df1363ca41..61e4220a7e 100644 --- a/v2/lib/webpack/base.js +++ b/v2/lib/webpack/base.js @@ -1,133 +1,133 @@ -const Config = require('webpack-chain'); -const CSSExtractPlugin = require('mini-css-extract-plugin'); -const UglifyJsPlugin = require('uglifyjs-webpack-plugin'); -const path = require('path'); - -const mdLoader = require.resolve('./loader/markdown'); - -module.exports = function createBaseConfig(props, isServer) { - const { - siteConfig, - outDir, - themePath, - docsDir, - pagesDir, - siteDir, - sourceToMetadata, - versionedDir, - translatedDir, - baseUrl - } = props; - - const config = new Config(); - const isProd = process.env.NODE_ENV === 'production'; - - config - .mode(isProd ? 'production' : 'development') - .output.path(outDir) - .filename(isProd ? '[name].[chunkhash].js' : '[name].js') - .publicPath(isProd ? baseUrl : '/'); - - if (!isProd) { - config.devtool('cheap-module-eval-source-map'); - } - - config.resolve - .set('symlinks', true) - .alias.set('@theme', themePath) - .set('@site', siteDir) - .set('@versioned_docs', versionedDir) - .set('@translated_docs', translatedDir) - .set('@docs', docsDir) - .set('@pages', pagesDir) - .set('@build', outDir) - .set('@generated', path.resolve(__dirname, '../core/generated')) - .set('@core', path.resolve(__dirname, '../core')) - .end(); - - function applyBabel(rule) { - rule - .use('babel') - .loader('babel-loader') - .options({ - babelrc: false, - presets: ['env', 'react'], - plugins: [isServer ? 'dynamic-import-node' : 'syntax-dynamic-import'] - }); - } - - const jsRule = config.module - .rule('js') - .test(/\.js$/) - .exclude.add(filepath => { - // Always transpile lib directory - if (filepath.startsWith(path.join(__dirname, '..'))) { - return false; - } - // Don't transpile node_modules - return /node_modules/.test(filepath); - }) - .end(); - - applyBabel(jsRule); - - const mdRule = config.module.rule('markdown').test(/\.md$/); - - applyBabel(mdRule); - - mdRule - .use('markdown-loader') - .loader(mdLoader) - .options({ - siteConfig, - versionedDir, - translatedDir, - docsDir, - sourceToMetadata - }); - - const cssRule = config.module.rule('css').test(/\.css$/); - if (!isServer) { - if (isProd) { - cssRule.use('extract-css-loader').loader(CSSExtractPlugin.loader); - } else { - cssRule.use('style-loader').loader('style-loader'); - } - } - - cssRule - .use('css-loader') - .loader(isServer ? 'css-loader/locals' : 'css-loader') - .options({ - modules: true, - importLoaders: 1, - localIdentName: `[local]_[hash:base64:8]`, - sourceMap: !isProd, - minimize: true - }); - - // mini-css-extract plugin - config.plugin('extract-css').use(CSSExtractPlugin, [ - { - filename: isProd ? '[name].[chunkhash].css' : '[name].css', - chunkFilename: isProd ? '[id].[chunkhash].css' : '[id].css' - } - ]); - - if (isProd) { - config.optimization.minimizer([ - new UglifyJsPlugin({ - cache: true, - uglifyOptions: { - warnings: false, - compress: false, - ecma: 6, - mangle: true - }, - sourceMap: true - }) - ]); - } - - return config; -}; +const Config = require('webpack-chain'); +const CSSExtractPlugin = require('mini-css-extract-plugin'); +const UglifyJsPlugin = require('uglifyjs-webpack-plugin'); +const path = require('path'); + +const mdLoader = require.resolve('./loader/markdown'); + +module.exports = function createBaseConfig(props, isServer) { + const { + siteConfig, + outDir, + themePath, + docsDir, + pagesDir, + siteDir, + sourceToMetadata, + versionedDir, + translatedDir, + baseUrl + } = props; + + const config = new Config(); + const isProd = process.env.NODE_ENV === 'production'; + + config + .mode(isProd ? 'production' : 'development') + .output.path(outDir) + .filename(isProd ? '[name].[chunkhash].js' : '[name].js') + .publicPath(isProd ? baseUrl : '/'); + + if (!isProd) { + config.devtool('cheap-module-eval-source-map'); + } + + config.resolve + .set('symlinks', true) + .alias.set('@theme', themePath) + .set('@site', siteDir) + .set('@versioned_docs', versionedDir) + .set('@translated_docs', translatedDir) + .set('@docs', docsDir) + .set('@pages', pagesDir) + .set('@build', outDir) + .set('@generated', path.resolve(__dirname, '../core/generated')) + .set('@core', path.resolve(__dirname, '../core')) + .end(); + + function applyBabel(rule) { + rule + .use('babel') + .loader('babel-loader') + .options({ + babelrc: false, + presets: ['env', 'react'], + plugins: [isServer ? 'dynamic-import-node' : 'syntax-dynamic-import'] + }); + } + + const jsRule = config.module + .rule('js') + .test(/\.js$/) + .exclude.add(filepath => { + // Always transpile lib directory + if (filepath.startsWith(path.join(__dirname, '..'))) { + return false; + } + // Don't transpile node_modules + return /node_modules/.test(filepath); + }) + .end(); + + applyBabel(jsRule); + + const mdRule = config.module.rule('markdown').test(/\.md$/); + + applyBabel(mdRule); + + mdRule + .use('markdown-loader') + .loader(mdLoader) + .options({ + siteConfig, + versionedDir, + translatedDir, + docsDir, + sourceToMetadata + }); + + const cssRule = config.module.rule('css').test(/\.css$/); + if (!isServer) { + if (isProd) { + cssRule.use('extract-css-loader').loader(CSSExtractPlugin.loader); + } else { + cssRule.use('style-loader').loader('style-loader'); + } + } + + cssRule + .use('css-loader') + .loader(isServer ? 'css-loader/locals' : 'css-loader') + .options({ + modules: true, + importLoaders: 1, + localIdentName: `[local]_[hash:base64:8]`, + sourceMap: !isProd, + minimize: true + }); + + // mini-css-extract plugin + config.plugin('extract-css').use(CSSExtractPlugin, [ + { + filename: isProd ? '[name].[chunkhash].css' : '[name].css', + chunkFilename: isProd ? '[id].[chunkhash].css' : '[id].css' + } + ]); + + if (isProd) { + config.optimization.minimizer([ + new UglifyJsPlugin({ + cache: true, + uglifyOptions: { + warnings: false, + compress: false, + ecma: 6, + mangle: true + }, + sourceMap: true + }) + ]); + } + + return config; +};