mirror of
https://github.com/facebook/docusaurus.git
synced 2025-08-02 00:09:48 +02:00
feat: add uglifyjs webpack plugin
This commit is contained in:
parent
ca623d7d38
commit
0365403a75
4 changed files with 37 additions and 9 deletions
|
@ -1,5 +1,6 @@
|
|||
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');
|
||||
|
@ -74,7 +75,7 @@ module.exports = function createBaseConfig(props, isServer) {
|
|||
mdRule
|
||||
.use('markdown-loader')
|
||||
.loader(mdLoader)
|
||||
.options({siteConfig});
|
||||
.options({siteConfig, siteDir, docsDir});
|
||||
|
||||
const cssRule = config.module.rule('css').test(/\.css$/);
|
||||
if (isProd) {
|
||||
|
@ -101,5 +102,20 @@ module.exports = function createBaseConfig(props, isServer) {
|
|||
}
|
||||
]);
|
||||
|
||||
if (isProd) {
|
||||
config.optimization.minimizer([
|
||||
new UglifyJsPlugin({
|
||||
cache: true,
|
||||
uglifyOptions: {
|
||||
warnings: false,
|
||||
compress: false,
|
||||
ecma: 6,
|
||||
mangle: true,
|
||||
},
|
||||
sourceMap: true
|
||||
})
|
||||
]);
|
||||
}
|
||||
|
||||
return config;
|
||||
};
|
||||
|
|
|
@ -3,21 +3,19 @@ const fm = require('front-matter');
|
|||
|
||||
module.exports = function(fileString) {
|
||||
const options = getOptions(this);
|
||||
const {siteConfig, siteDir, docsDir } = options;
|
||||
|
||||
const {body} = fm(fileString);
|
||||
const content = JSON.stringify(body);
|
||||
/*
|
||||
TODO replace all the markdown linking to correct url depends on whether it's versioned/translated/normal docs
|
||||
e.g: [test](test.md) become [test](/docs/test)
|
||||
Process the markdown file content, including replacing all relative markdown links
|
||||
*/
|
||||
const siteConfig = JSON.stringify(options.siteConfig);
|
||||
|
||||
const {body: content = ''} = fm(fileString);
|
||||
|
||||
return (
|
||||
`import React from 'react';\n` +
|
||||
`import Markdown from '@theme/Markdown'\n` +
|
||||
`export default () => (
|
||||
<Markdown siteConfig={${siteConfig}}>
|
||||
{${content}}
|
||||
<Markdown siteConfig={${JSON.stringify(siteConfig)}}>
|
||||
{${JSON.stringify(content)}}
|
||||
</Markdown>
|
||||
);`
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue