mirror of
https://github.com/facebook/docusaurus.git
synced 2025-08-06 10:20:09 +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 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 path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
const mdLoader = require.resolve('./loader/markdown');
|
const mdLoader = require.resolve('./loader/markdown');
|
||||||
|
@ -74,7 +75,7 @@ module.exports = function createBaseConfig(props, isServer) {
|
||||||
mdRule
|
mdRule
|
||||||
.use('markdown-loader')
|
.use('markdown-loader')
|
||||||
.loader(mdLoader)
|
.loader(mdLoader)
|
||||||
.options({siteConfig});
|
.options({siteConfig, siteDir, docsDir});
|
||||||
|
|
||||||
const cssRule = config.module.rule('css').test(/\.css$/);
|
const cssRule = config.module.rule('css').test(/\.css$/);
|
||||||
if (isProd) {
|
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;
|
return config;
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,21 +3,19 @@ const fm = require('front-matter');
|
||||||
|
|
||||||
module.exports = function(fileString) {
|
module.exports = function(fileString) {
|
||||||
const options = getOptions(this);
|
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
|
Process the markdown file content, including replacing all relative markdown links
|
||||||
e.g: [test](test.md) become [test](/docs/test)
|
|
||||||
*/
|
*/
|
||||||
const siteConfig = JSON.stringify(options.siteConfig);
|
const {body: content = ''} = fm(fileString);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
`import React from 'react';\n` +
|
`import React from 'react';\n` +
|
||||||
`import Markdown from '@theme/Markdown'\n` +
|
`import Markdown from '@theme/Markdown'\n` +
|
||||||
`export default () => (
|
`export default () => (
|
||||||
<Markdown siteConfig={${siteConfig}}>
|
<Markdown siteConfig={${JSON.stringify(siteConfig)}}>
|
||||||
{${content}}
|
{${JSON.stringify(content)}}
|
||||||
</Markdown>
|
</Markdown>
|
||||||
);`
|
);`
|
||||||
);
|
);
|
||||||
|
|
|
@ -80,6 +80,7 @@
|
||||||
"semver": "^5.5.0",
|
"semver": "^5.5.0",
|
||||||
"static-site-generator-webpack-plugin": "endiliey/static-site-generator-webpack-plugin#master",
|
"static-site-generator-webpack-plugin": "endiliey/static-site-generator-webpack-plugin#master",
|
||||||
"style-loader": "^0.22.1",
|
"style-loader": "^0.22.1",
|
||||||
|
"uglifyjs-webpack-plugin": "^1.3.0",
|
||||||
"webpack": "^4.16.3",
|
"webpack": "^4.16.3",
|
||||||
"webpack-chain": "^4.8.0",
|
"webpack-chain": "^4.8.0",
|
||||||
"webpack-merge": "^4.1.4",
|
"webpack-merge": "^4.1.4",
|
||||||
|
|
13
yarn.lock
13
yarn.lock
|
@ -6712,6 +6712,19 @@ uglifyjs-webpack-plugin@^1.2.4:
|
||||||
webpack-sources "^1.1.0"
|
webpack-sources "^1.1.0"
|
||||||
worker-farm "^1.5.2"
|
worker-farm "^1.5.2"
|
||||||
|
|
||||||
|
uglifyjs-webpack-plugin@^1.3.0:
|
||||||
|
version "1.3.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/uglifyjs-webpack-plugin/-/uglifyjs-webpack-plugin-1.3.0.tgz#75f548160858163a08643e086d5fefe18a5d67de"
|
||||||
|
dependencies:
|
||||||
|
cacache "^10.0.4"
|
||||||
|
find-cache-dir "^1.0.0"
|
||||||
|
schema-utils "^0.4.5"
|
||||||
|
serialize-javascript "^1.4.0"
|
||||||
|
source-map "^0.6.1"
|
||||||
|
uglify-es "^3.3.4"
|
||||||
|
webpack-sources "^1.1.0"
|
||||||
|
worker-farm "^1.5.2"
|
||||||
|
|
||||||
underscore.string@~2.4.0:
|
underscore.string@~2.4.0:
|
||||||
version "2.4.0"
|
version "2.4.0"
|
||||||
resolved "https://registry.yarnpkg.com/underscore.string/-/underscore.string-2.4.0.tgz#8cdd8fbac4e2d2ea1e7e2e8097c42f442280f85b"
|
resolved "https://registry.yarnpkg.com/underscore.string/-/underscore.string-2.4.0.tgz#8cdd8fbac4e2d2ea1e7e2e8097c42f442280f85b"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue