mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-20 03:32:29 +02:00
v2: nits
This commit is contained in:
parent
48f273e68f
commit
dcb733a63a
2 changed files with 134 additions and 134 deletions
|
@ -2,7 +2,7 @@ import React from 'react';
|
||||||
|
|
||||||
export default props => {
|
export default props => {
|
||||||
if (props.error) {
|
if (props.error) {
|
||||||
return <div align="center">Error 🔥🔥🔥</div>;
|
return <div align="center">Error</div>;
|
||||||
}
|
}
|
||||||
if (props.pastDelay) {
|
if (props.pastDelay) {
|
||||||
return <div align="center">Loading...</div>;
|
return <div align="center">Loading...</div>;
|
||||||
|
|
|
@ -1,133 +1,133 @@
|
||||||
const Config = require('webpack-chain');
|
const Config = require('webpack-chain');
|
||||||
const CSSExtractPlugin = require('mini-css-extract-plugin');
|
const CSSExtractPlugin = require('mini-css-extract-plugin');
|
||||||
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
|
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
const mdLoader = require.resolve('./loader/markdown');
|
const mdLoader = require.resolve('./loader/markdown');
|
||||||
|
|
||||||
module.exports = function createBaseConfig(props, isServer) {
|
module.exports = function createBaseConfig(props, isServer) {
|
||||||
const {
|
const {
|
||||||
siteConfig,
|
siteConfig,
|
||||||
outDir,
|
outDir,
|
||||||
themePath,
|
themePath,
|
||||||
docsDir,
|
docsDir,
|
||||||
pagesDir,
|
pagesDir,
|
||||||
siteDir,
|
siteDir,
|
||||||
sourceToMetadata,
|
sourceToMetadata,
|
||||||
versionedDir,
|
versionedDir,
|
||||||
translatedDir,
|
translatedDir,
|
||||||
baseUrl
|
baseUrl
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
const config = new Config();
|
const config = new Config();
|
||||||
const isProd = process.env.NODE_ENV === 'production';
|
const isProd = process.env.NODE_ENV === 'production';
|
||||||
|
|
||||||
config
|
config
|
||||||
.mode(isProd ? 'production' : 'development')
|
.mode(isProd ? 'production' : 'development')
|
||||||
.output.path(outDir)
|
.output.path(outDir)
|
||||||
.filename(isProd ? '[name].[chunkhash].js' : '[name].js')
|
.filename(isProd ? '[name].[chunkhash].js' : '[name].js')
|
||||||
.publicPath(isProd ? baseUrl : '/');
|
.publicPath(isProd ? baseUrl : '/');
|
||||||
|
|
||||||
if (!isProd) {
|
if (!isProd) {
|
||||||
config.devtool('cheap-module-eval-source-map');
|
config.devtool('cheap-module-eval-source-map');
|
||||||
}
|
}
|
||||||
|
|
||||||
config.resolve
|
config.resolve
|
||||||
.set('symlinks', true)
|
.set('symlinks', true)
|
||||||
.alias.set('@theme', themePath)
|
.alias.set('@theme', themePath)
|
||||||
.set('@site', siteDir)
|
.set('@site', siteDir)
|
||||||
.set('@versioned_docs', versionedDir)
|
.set('@versioned_docs', versionedDir)
|
||||||
.set('@translated_docs', translatedDir)
|
.set('@translated_docs', translatedDir)
|
||||||
.set('@docs', docsDir)
|
.set('@docs', docsDir)
|
||||||
.set('@pages', pagesDir)
|
.set('@pages', pagesDir)
|
||||||
.set('@build', outDir)
|
.set('@build', outDir)
|
||||||
.set('@generated', path.resolve(__dirname, '../core/generated'))
|
.set('@generated', path.resolve(__dirname, '../core/generated'))
|
||||||
.set('@core', path.resolve(__dirname, '../core'))
|
.set('@core', path.resolve(__dirname, '../core'))
|
||||||
.end();
|
.end();
|
||||||
|
|
||||||
function applyBabel(rule) {
|
function applyBabel(rule) {
|
||||||
rule
|
rule
|
||||||
.use('babel')
|
.use('babel')
|
||||||
.loader('babel-loader')
|
.loader('babel-loader')
|
||||||
.options({
|
.options({
|
||||||
babelrc: false,
|
babelrc: false,
|
||||||
presets: ['env', 'react'],
|
presets: ['env', 'react'],
|
||||||
plugins: [isServer ? 'dynamic-import-node' : 'syntax-dynamic-import']
|
plugins: [isServer ? 'dynamic-import-node' : 'syntax-dynamic-import']
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const jsRule = config.module
|
const jsRule = config.module
|
||||||
.rule('js')
|
.rule('js')
|
||||||
.test(/\.js$/)
|
.test(/\.js$/)
|
||||||
.exclude.add(filepath => {
|
.exclude.add(filepath => {
|
||||||
// Always transpile lib directory
|
// Always transpile lib directory
|
||||||
if (filepath.startsWith(path.join(__dirname, '..'))) {
|
if (filepath.startsWith(path.join(__dirname, '..'))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Don't transpile node_modules
|
// Don't transpile node_modules
|
||||||
return /node_modules/.test(filepath);
|
return /node_modules/.test(filepath);
|
||||||
})
|
})
|
||||||
.end();
|
.end();
|
||||||
|
|
||||||
applyBabel(jsRule);
|
applyBabel(jsRule);
|
||||||
|
|
||||||
const mdRule = config.module.rule('markdown').test(/\.md$/);
|
const mdRule = config.module.rule('markdown').test(/\.md$/);
|
||||||
|
|
||||||
applyBabel(mdRule);
|
applyBabel(mdRule);
|
||||||
|
|
||||||
mdRule
|
mdRule
|
||||||
.use('markdown-loader')
|
.use('markdown-loader')
|
||||||
.loader(mdLoader)
|
.loader(mdLoader)
|
||||||
.options({
|
.options({
|
||||||
siteConfig,
|
siteConfig,
|
||||||
versionedDir,
|
versionedDir,
|
||||||
translatedDir,
|
translatedDir,
|
||||||
docsDir,
|
docsDir,
|
||||||
sourceToMetadata
|
sourceToMetadata
|
||||||
});
|
});
|
||||||
|
|
||||||
const cssRule = config.module.rule('css').test(/\.css$/);
|
const cssRule = config.module.rule('css').test(/\.css$/);
|
||||||
if (!isServer) {
|
if (!isServer) {
|
||||||
if (isProd) {
|
if (isProd) {
|
||||||
cssRule.use('extract-css-loader').loader(CSSExtractPlugin.loader);
|
cssRule.use('extract-css-loader').loader(CSSExtractPlugin.loader);
|
||||||
} else {
|
} else {
|
||||||
cssRule.use('style-loader').loader('style-loader');
|
cssRule.use('style-loader').loader('style-loader');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cssRule
|
cssRule
|
||||||
.use('css-loader')
|
.use('css-loader')
|
||||||
.loader(isServer ? 'css-loader/locals' : 'css-loader')
|
.loader(isServer ? 'css-loader/locals' : 'css-loader')
|
||||||
.options({
|
.options({
|
||||||
modules: true,
|
modules: true,
|
||||||
importLoaders: 1,
|
importLoaders: 1,
|
||||||
localIdentName: `[local]_[hash:base64:8]`,
|
localIdentName: `[local]_[hash:base64:8]`,
|
||||||
sourceMap: !isProd,
|
sourceMap: !isProd,
|
||||||
minimize: true
|
minimize: true
|
||||||
});
|
});
|
||||||
|
|
||||||
// mini-css-extract plugin
|
// mini-css-extract plugin
|
||||||
config.plugin('extract-css').use(CSSExtractPlugin, [
|
config.plugin('extract-css').use(CSSExtractPlugin, [
|
||||||
{
|
{
|
||||||
filename: isProd ? '[name].[chunkhash].css' : '[name].css',
|
filename: isProd ? '[name].[chunkhash].css' : '[name].css',
|
||||||
chunkFilename: isProd ? '[id].[chunkhash].css' : '[id].css'
|
chunkFilename: isProd ? '[id].[chunkhash].css' : '[id].css'
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (isProd) {
|
if (isProd) {
|
||||||
config.optimization.minimizer([
|
config.optimization.minimizer([
|
||||||
new UglifyJsPlugin({
|
new UglifyJsPlugin({
|
||||||
cache: true,
|
cache: true,
|
||||||
uglifyOptions: {
|
uglifyOptions: {
|
||||||
warnings: false,
|
warnings: false,
|
||||||
compress: false,
|
compress: false,
|
||||||
ecma: 6,
|
ecma: 6,
|
||||||
mangle: true
|
mangle: true
|
||||||
},
|
},
|
||||||
sourceMap: true
|
sourceMap: true
|
||||||
})
|
})
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue