mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-02 11:47:23 +02:00
43 lines
1.3 KiB
JavaScript
43 lines
1.3 KiB
JavaScript
const path = require('path');
|
|
const staticSiteGenerator = require('static-site-generator-webpack-plugin');
|
|
const webpackNiceLog = require('webpack-nicelog');
|
|
const createBaseConfig = require('./base');
|
|
const {applyChainWebpack} = require('./utils');
|
|
|
|
module.exports = function createServerConfig(props) {
|
|
const config = createBaseConfig(props, true);
|
|
|
|
config.entry('main').add(path.resolve(__dirname, '../core/serverEntry.js'));
|
|
config.target('node');
|
|
config.output.filename('server.bundle.js').libraryTarget('commonjs2');
|
|
|
|
// Workaround for Webpack 4 Bug (https://github.com/webpack/webpack/issues/6522)
|
|
config.output.globalObject('this');
|
|
|
|
const {siteConfig, docsMetadatas, pagesMetadatas} = props;
|
|
|
|
// static site generator webpack plugin
|
|
const docsLinks = Object.values(docsMetadatas).map(data => ({
|
|
path: `${data.permalink}`
|
|
}));
|
|
const paths = [...docsLinks, ...pagesMetadatas].map(data => data.path);
|
|
config.plugin('siteGenerator').use(staticSiteGenerator, [
|
|
{
|
|
entry: 'main',
|
|
locals: {
|
|
baseUrl: siteConfig.baseUrl
|
|
},
|
|
paths
|
|
}
|
|
]);
|
|
|
|
// show compilation progress bar and build time
|
|
config
|
|
.plugin('niceLog')
|
|
.use(webpackNiceLog, [{name: 'Server', color: 'yellow'}]);
|
|
|
|
// user extended webpack-chain config
|
|
applyChainWebpack(props.siteConfig.chainWebpack, config, true);
|
|
|
|
return config;
|
|
};
|