Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(v2): Webpack 5, PostCSS 8 #4089

Merged
merged 157 commits into from
Apr 30, 2021
Merged
Show file tree
Hide file tree
Changes from 153 commits
Commits
Show all changes
157 commits
Select commit Hold shift + click to select a range
849d9c0
Initial webpack 5 work
RDIL Jan 22, 2021
24c3817
It works on my machine (lol)
RDIL Feb 5, 2021
7b2f923
Committing a bit more work
RDIL Feb 9, 2021
9bfe9fb
It works - sorta
RDIL Feb 9, 2021
89e6cb3
Merge branch 'master' into webpack-5
RDIL Feb 9, 2021
82b7a4c
Update packages/docusaurus/package.json
RDIL Feb 9, 2021
09aaaeb
at least fix prettier /shrug
RDIL Feb 9, 2021
78dc506
making more progress. build should work now, css stuff is still a bit…
RDIL Feb 11, 2021
3ac46d3
Terser things
RDIL Feb 11, 2021
833fe54
Merge branch 'master' into webpack-5
RDIL Feb 11, 2021
31c6185
Working on things
RDIL Feb 11, 2021
5970897
Vendor webpack
RDIL Feb 11, 2021
8abd018
Repair chunks, and tests
RDIL Feb 11, 2021
41e4d87
Rerun prettier
RDIL Feb 11, 2021
97d4dad
Re-add client prefetching
RDIL Feb 11, 2021
90c9894
Update snapshots
RDIL Feb 11, 2021
90b1e22
Update snapshots
RDIL Feb 11, 2021
e82f654
I hope this works
RDIL Feb 11, 2021
0c73485
Remove redundant dev server code
RDIL Feb 12, 2021
5879eb7
relock
RDIL Feb 12, 2021
c38836b
Trying to reduce memory usage and fix things
RDIL Feb 12, 2021
f63cf76
Dead code elim
RDIL Feb 12, 2021
00a5147
Search bar works!!!
RDIL Feb 16, 2021
7d52dfc
Prefetching should work again
RDIL Feb 16, 2021
741d100
Merge branch 'master' into webpack-5
RDIL Feb 16, 2021
fc9138c
lock
RDIL Feb 16, 2021
67e4233
ts issue
RDIL Feb 16, 2021
d1907ac
Repair snapshot
RDIL Feb 16, 2021
51d9641
Run prettier
RDIL Feb 16, 2021
cfdac27
Fix the CI for now
RDIL Feb 17, 2021
a8e96ba
fix lint-prettier
RDIL Feb 17, 2021
127840b
clean-css works, now for the other one
RDIL Feb 18, 2021
f64b97d
Merge branch 'webpack-5' of https://github.com/RDIL/docusaurus into w…
RDIL Feb 19, 2021
de50f0e
Merge branch 'master' into webpack-5
RDIL Feb 19, 2021
78e18f4
Fix lockfile
RDIL Feb 19, 2021
7fc121a
Fixes prettier
RDIL Feb 19, 2021
d5b4309
Other css minification works!!!
RDIL Feb 19, 2021
c51c572
Add clean-css options, fix webpack versions
RDIL Feb 22, 2021
275c646
Merge branch 'master' into webpack-5
RDIL Feb 22, 2021
fab025e
Fix tests and several of the webpack loaders
RDIL Feb 22, 2021
66e7257
Re-add support for simple css minifier
RDIL Feb 22, 2021
c192a93
Merge branch 'master' into webpack-5
RDIL Feb 22, 2021
7ee130a
Update other related dependencies
RDIL Feb 22, 2021
fea4fbd
Merge branch 'master' into webpack-5
RDIL Feb 22, 2021
53cc534
Fix lockfile
RDIL Feb 22, 2021
b965ec2
Dev server fixups
RDIL Feb 24, 2021
c9caf4c
Simplify css things
RDIL Feb 24, 2021
ce04544
Update webpack, try with postcss 7
RDIL Mar 2, 2021
e46832c
Merge branch 'master' into webpack-5
RDIL Mar 4, 2021
d726233
Other cssnano repairs
RDIL Mar 4, 2021
9a9c69d
Merge branch 'master' into webpack-5
RDIL Mar 8, 2021
2f84c91
fix lockfile
RDIL Mar 8, 2021
7603a90
Clean up the babel preset
RDIL Mar 10, 2021
7844680
Merge branch 'master' into webpack-5
RDIL Mar 10, 2021
1281d67
Fix lockfile
RDIL Mar 10, 2021
d929c58
Bump RL SSR version
RDIL Mar 10, 2021
e3c9008
Merge branch 'master' into webpack-5
RDIL Mar 16, 2021
047aa97
Merge branch 'master' into webpack-5
RDIL Mar 17, 2021
0506b13
Fix the build errors
RDIL Mar 17, 2021
0bfd87e
Merge branch 'master' into webpack-5
RDIL Mar 22, 2021
1c8d6a2
Lockfile fix
RDIL Mar 22, 2021
e69486d
It works again
RDIL Mar 22, 2021
33b1f2d
webpack 5 should close compiler after run
slorber Mar 25, 2021
c481041
add proper webpack5 persistent caching config
slorber Mar 25, 2021
ba009d3
Merge branch 'master' into webpack-5
slorber Mar 25, 2021
bf142b2
upgrade webpack deps again
slorber Mar 25, 2021
be961ea
Merge branch 'master' into webpack-5
slorber Mar 25, 2021
907393e
reduce build perf timeouts to avoid build time regressions
slorber Mar 25, 2021
9392f0a
test if incremental build can run on netlify
slorber Mar 25, 2021
27e5f17
netlify test
slorber Mar 25, 2021
68d7cbf
netlify test
slorber Mar 25, 2021
483efe7
netlify test
slorber Mar 25, 2021
25c5b5c
netlify test
slorber Mar 25, 2021
1db5381
netlify test
slorber Mar 25, 2021
2c84f3e
netlify test
slorber Mar 25, 2021
8e2cc76
netlify test
slorber Mar 26, 2021
db47fca
netlify test
slorber Mar 26, 2021
ba4bc60
netlify test
slorber Mar 26, 2021
1d2810a
netlify test
slorber Mar 26, 2021
cb769a2
netlify test
slorber Mar 26, 2021
57139aa
netlify test
slorber Mar 26, 2021
eb00350
netlify test
slorber Mar 26, 2021
1c22b52
netlify test
slorber Mar 26, 2021
94ff214
netlify test
slorber Mar 26, 2021
d52c82f
test
slorber Mar 26, 2021
b6cb026
test
slorber Mar 26, 2021
f3445a3
test
slorber Mar 26, 2021
7f8e812
test
slorber Mar 26, 2021
eaa6a47
netlify test
slorber Mar 26, 2021
2747940
netlify test
slorber Mar 26, 2021
97ad660
netlify test
slorber Mar 26, 2021
99974a4
netlify test
slorber Mar 26, 2021
670bda9
netlify test
slorber Mar 26, 2021
45694f0
netlify test
slorber Mar 26, 2021
77ab6b0
netlify test
slorber Mar 26, 2021
6194907
netlify test
slorber Mar 26, 2021
83e4758
netlify test
slorber Mar 26, 2021
594d82f
netlify test
slorber Mar 26, 2021
0f41a4b
fix existsSync() calls
slorber Mar 29, 2021
1dacd0b
replace @ts-nocheck by a temporary Webpack type
slorber Mar 29, 2021
bba7827
replace @ts-nocheck by a temporary Webpack type
slorber Mar 29, 2021
1254ba8
replace @ts-nocheck by a temporary Webpack type
slorber Mar 29, 2021
eab2b5b
migrate existing stats.warningsFilter to config.ignoreWarnings
slorber Mar 29, 2021
040ae94
remove stats from postBuild lifecycle data doc, as it is likely unuse…
slorber Mar 29, 2021
87f8d95
improve build.ts TS issues + move some sync code to async
slorber Mar 29, 2021
e51ce39
cleanup TS of start.ts
slorber Mar 29, 2021
a67220c
fix TS error
slorber Mar 29, 2021
a88ab06
fix TS issues
slorber Mar 29, 2021
a38617f
fix TS issues
slorber Mar 29, 2021
7fc0318
fix ts error
slorber Mar 29, 2021
89d4145
netlify test
slorber Mar 30, 2021
31ce3ba
netlify test
slorber Mar 30, 2021
0c28adf
netlify test
slorber Mar 30, 2021
b69618b
netlify test
slorber Mar 30, 2021
12e6bae
netlify test
slorber Mar 30, 2021
783f0e7
script cleanup
slorber Mar 30, 2021
c9bc610
script cleanup
slorber Mar 30, 2021
42f9026
re-enable @typescript-eslint/ban-ts-comment
slorber Mar 30, 2021
267f3e3
Deprecate getCacheLoader / getBabelLoader but keep retrocompatibility
slorber Mar 30, 2021
1871db8
useless TS
slorber Mar 30, 2021
aed7d60
fix and comment gca(chunkName) prefetching function
slorber Mar 30, 2021
915021f
remove deprecated mainTemplate.requireFn
slorber Mar 30, 2021
05cf1df
temporarily use react-loadable-ssr-addon-v5-slorber until PR merged: …
slorber Mar 30, 2021
abc6bbf
comment unsafeCache option
slorber Mar 30, 2021
18bac95
add explicit and more precise webpack targets
slorber Mar 30, 2021
42be951
splitChunks, use new type: "css/mini-extract" as it seems recommended…
slorber Mar 31, 2021
525e490
Merge branch 'master' into webpack-5
slorber Mar 31, 2021
0bb10d2
webpack error handling:
slorber Mar 31, 2021
c12041e
fix webpack5 warnings for evalSourceMapMiddleware.js
slorber Apr 1, 2021
3e773ba
typo
slorber Apr 1, 2021
4bc8f97
rename webpackHotDevClient
slorber Apr 1, 2021
aa137b4
make all modifications of react-dev-utils explicit with a comment
slorber Apr 1, 2021
48c03ba
revert LogPlugin adapter
slorber Apr 1, 2021
3cc6dc8
loader-utils update
slorber Apr 1, 2021
a34b514
add useful share cache comment
slorber Apr 1, 2021
ff391b7
add useful comments regarding the null-loader used in SSR for css files
slorber Apr 1, 2021
9c71697
upgrade webpack-merge in a retrocompatible way
slorber Apr 1, 2021
a142783
use MiniCssExtractPlugin.emit false as recommended
slorber Apr 1, 2021
ed4e0cd
use @docusaurus/responsive-loader
slorber Apr 2, 2021
f0524c0
revert MiniCssExtractPlugin esModule: false change
slorber Apr 2, 2021
a4bb878
add link to PR for custom CleanWebpackPlugin
slorber Apr 2, 2021
0f91f4a
pwa: add fallback to env variable or webpack 5 fails to build
slorber Apr 6, 2021
cb5550f
Merge branch 'master' into webpack-5
slorber Apr 16, 2021
81bcc36
upgrade to CssMinimizerPlugin 2.0
slorber Apr 16, 2021
68e8b8b
only build en locale for windows tests
slorber Apr 16, 2021
91f0c12
line breaks between errors
slorber Apr 16, 2021
bf5642d
add useful comment
slorber Apr 16, 2021
972cff4
Fix e2e tests with Yarn2 not finding new init template dependencies
slorber Apr 16, 2021
b305145
fix bad import
slorber Apr 16, 2021
e1b798a
disable browserslist target as webpack already tries to use browserli…
slorber Apr 16, 2021
a3c784f
webpack5 TS fixes
slorber Apr 17, 2021
351f1c5
fix getMinimizer order (even if it does not work yet)
slorber Apr 17, 2021
38ad2bf
update postcss to v8, fix cssnano minimizer errors
slorber Apr 18, 2021
adf2a52
Merge branch 'master' into webpack-5
slorber Apr 22, 2021
cafe2b4
add NavbarItem position to types (useful for QuestDB site upgrade to …
slorber Apr 27, 2021
46b1b82
Merge branch 'master' into webpack-5
slorber Apr 27, 2021
867d034
add webpack cache env variable to reduce risk of webpack 5 adoption
slorber Apr 30, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/v2-build-time-perf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ jobs:
# Ensure build with a cold cache does not increase too much
- name: Build (cold cache)
run: yarn workspace docusaurus-2-website build --locale en
timeout-minutes: 10
timeout-minutes: 8

# Ensure build with a warm cache does not increase too much
- name: Build (warm cache)
run: yarn workspace docusaurus-2-website build --locale en
timeout-minutes: 10
timeout-minutes: 2

# TODO post a Github comment with build with perf warnings?
2 changes: 1 addition & 1 deletion .github/workflows/v2-tests-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ jobs:
- name: Docusaurus Jest Tests
run: yarn test
- name: Docusaurus Build
run: yarn build:v2
run: yarn build:v2 --locale en
env:
CI: true
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,11 @@
"@formatjs/intl-datetimeformat": "^3.2.12",
"@formatjs/intl-numberformat": "^6.2.2",
"@formatjs/intl-pluralrules": "^4.0.11",
"@types/cssnano": "^4.0.0",
"@types/express": "^4.17.2",
"@types/fs-extra": "^9.0.6",
"@types/jest": "^26.0.20",
"@types/loader-utils": "^1.1.3",
"@types/loader-utils": "^2.0.2",
"@types/lodash": "^4.14.168",
"@types/node": "^14.14.22",
"@types/prismjs": "^1.16.2",
Expand All @@ -87,9 +88,7 @@
"@types/semver": "^7.1.0",
"@types/shelljs": "^0.8.6",
"@types/wait-on": "^5.2.0",
"@types/webpack": "^4.41.0",
"@types/webpack-dev-server": "^3.9.0",
"@types/webpack-merge": "^4.1.5",
"@types/webpack-dev-server": "^3.11.1",
"@typescript-eslint/eslint-plugin": "^4.18.0",
"@typescript-eslint/parser": "^4.18.0",
"concurrently": "^5.3.0",
Expand Down
21 changes: 12 additions & 9 deletions packages/docusaurus-cssnano-preset/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ const advancedBasePreset = require('cssnano-preset-advanced');
const postCssSortMediaQueries = require('postcss-sort-media-queries');
const postCssRemoveOverriddenCustomProperties = require('./src/remove-overridden-custom-properties');

const preset = advancedBasePreset({
autoprefixer: {add: false},
discardComments: {removeAll: true},
});
module.exports = function docusaurusCssnanoPreset(opts) {
const advancedPreset = advancedBasePreset({
autoprefixer: {add: false},
discardComments: {removeAll: true},
...opts,
});

preset.plugins.unshift(
[postCssSortMediaQueries],
[postCssRemoveOverriddenCustomProperties],
);
advancedPreset.plugins.unshift(
[postCssSortMediaQueries],
[postCssRemoveOverriddenCustomProperties],
);

module.exports = preset;
return advancedPreset;
};
6 changes: 3 additions & 3 deletions packages/docusaurus-cssnano-preset/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
"directory": "packages/docusaurus-cssnano-preset"
},
"dependencies": {
"cssnano-preset-advanced": "^4.0.7",
"postcss": "^7.0.2",
"postcss-sort-media-queries": "^1.7.26"
"cssnano-preset-advanced": "^5.0.0",
"postcss": "^8.2.10",
"postcss-sort-media-queries": "^3.8.9"
},
"devDependencies": {
"to-vfile": "^6.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,38 @@
* LICENSE file in the root directory of this source tree.
*/

const postcss = require('postcss');

/*
This PostCSS plugin will remove duplicate/same custom properties (which are actually overridden ones) **only** from `:root` selector.

Depending on the presence of an `!important` rule in value of custom property, the following actions will happens:

- If the same custom properties do **not** have an `!important` rule, then all of them will be removed except for the last one (which will actually be applied).
- If the same custom properties have at least one `!important` rule, then only those properties that do not have this rule will be removed.
*/

module.exports = postcss.plugin(
'postcss-remove-overridden-custom-properties',
() => {
return (root) => {
root.walkDecls((decl) => {
if (decl.parent.selector !== ':root') {
return;
}

const sameProperties =
decl.parent.nodes.filter((n) => n.prop === decl.prop) || [];
const hasImportantProperties = sameProperties.some((p) =>
Object.prototype.hasOwnProperty.call(p, 'important'),
);

const overriddenProperties = hasImportantProperties
? sameProperties.filter(
(p) => !Object.prototype.hasOwnProperty.call(p, 'important'),
)
: sameProperties.slice(0, -1);

overriddenProperties.map((p) => p.remove());
});
};
},
);
/**
* This PostCSS plugin will remove duplicate/same custom properties (which are actually overridden ones) **only** from `:root` selector.
*
* Depending on the presence of an `!important` rule in value of custom property, the following actions will happens:
*
* - If the same custom properties do **not** have an `!important` rule, then all of them will be removed except for the last one (which will actually be applied).
* - If the same custom properties have at least one `!important` rule, then only those properties that do not have this rule will be removed.
* @returns {import('postcss').Plugin}
*/
module.exports = function creator() {
return {
postcssPlugin: 'postcss-remove-overridden-custom-properties',
Declaration(decl) {
if (decl.parent.selector !== ':root') {
return;
}

const sameProperties =
decl.parent.nodes.filter((n) => n.prop === decl.prop) || [];
const hasImportantProperties = sameProperties.some((p) =>
Object.prototype.hasOwnProperty.call(p, 'important'),
);

const overriddenProperties = hasImportantProperties
? sameProperties.filter(
(p) => !Object.prototype.hasOwnProperty.call(p, 'important'),
)
: sameProperties.slice(0, -1);

overriddenProperties.map((p) => p.remove());
},
};
};

module.exports.postcss = true;
9 changes: 6 additions & 3 deletions packages/docusaurus-init/templates/bootstrap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@
"dependencies": {
"@docusaurus/core": "2.0.0-alpha.73",
"@docusaurus/preset-bootstrap": "2.0.0-alpha.73",
"@mdx-js/react": "^1.5.8",
"classnames": "^2.2.6",
"@mdx-js/react": "^1.6.21",
"@svgr/webpack": "^5.5.0",
"clsx": "^1.1.1",
"file-loader": "^6.2.0",
"react": "^17.0.1",
"react-dom": "^17.0.1"
"react-dom": "^17.0.1",
"url-loader": "^4.1.1"
slorber marked this conversation as resolved.
Show resolved Hide resolved
},
"browserslist": {
"production": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import React from 'react';
import classnames from 'classnames';
import clsx from 'clsx';
import Layout from '@theme/Layout';
import Link from '@docusaurus/Link';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
import useBaseUrl from '@docusaurus/useBaseUrl';

import styles from './styles.module.css';

const features = [
Expand Down Expand Up @@ -43,7 +42,7 @@ const features = [
function Feature({imageUrl, title, description}) {
const imgUrl = useBaseUrl(imageUrl);
return (
<div className={classnames('col col--4', styles.feature)}>
<div className={clsx('col col--4', styles.feature)}>
{imgUrl && (
<div className="text--center">
<img className={styles.featureImage} src={imgUrl} alt={title} />
Expand Down
5 changes: 4 additions & 1 deletion packages/docusaurus-init/templates/classic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
"@docusaurus/core": "2.0.0-alpha.73",
"@docusaurus/preset-classic": "2.0.0-alpha.73",
"@mdx-js/react": "^1.6.21",
"@svgr/webpack": "^5.5.0",
"clsx": "^1.1.1",
"file-loader": "^6.2.0",
"react": "^17.0.1",
"react-dom": "^17.0.1"
"react-dom": "^17.0.1",
"url-loader": "^4.1.1"
},
"browserslist": {
"production": [
Expand Down
5 changes: 4 additions & 1 deletion packages/docusaurus-init/templates/facebook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@
"@docusaurus/core": "2.0.0-alpha.73",
"@docusaurus/preset-classic": "2.0.0-alpha.73",
"@mdx-js/react": "^1.6.21",
"@svgr/webpack": "^5.5.0",
"clsx": "^1.1.1",
"file-loader": "^6.2.0",
"react": "^17.0.1",
"react-dom": "^17.0.1"
"react-dom": "^17.0.1",
"url-loader": "^4.1.1"
},
"devDependencies": {
"@babel/eslint-parser": "^7.13.10",
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-mdx-loader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
"file-loader": "^6.2.0",
"fs-extra": "^9.1.0",
"github-slugger": "^1.3.0",
"loader-utils": "^2.0.0",
"gray-matter": "^4.0.2",
"mdast-util-to-string": "^2.0.0",
"remark-emoji": "^2.1.0",
"stringify-object": "^3.3.0",
"unist-util-visit": "^2.0.2",
"url-loader": "^4.1.1",
"webpack": "^4.44.1"
"webpack": "^5.28.0"
},
"devDependencies": {
"@docusaurus/types": "2.0.0-alpha.73",
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-mdx-loader/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* LICENSE file in the root directory of this source tree.
*/

const {getOptions} = require('loader-utils');
const {readFile} = require('fs-extra');
const mdx = require('@mdx-js/mdx');
const emoji = require('remark-emoji');
Expand All @@ -27,7 +26,8 @@ const DEFAULT_OPTIONS = {

module.exports = async function docusaurusMdxLoader(fileString) {
const callback = this.async();
const reqOptions = getOptions(this) || {};

const reqOptions = this.getOptions() || {};

const {frontMatter, content: contentWithTitle} = parseFrontMatter(fileString);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const createJSX = (node, pathUrl) => {
};

slorber marked this conversation as resolved.
Show resolved Hide resolved
async function ensureImageFileExist(imagePath, sourceFilePath) {
const imageExists = await fs.exists(imagePath);
const imageExists = await fs.pathExists(imagePath);
if (!imageExists) {
throw new Error(
`Image ${toMessageRelativeFilePath(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const {
} = getFileLoaderUtils();

async function ensureAssetFileExist(fileSystemAssetPath, sourceFilePath) {
const assetExists = await fs.exists(fileSystemAssetPath);
const assetExists = await fs.pathExists(fileSystemAssetPath);
if (!assetExists) {
throw new Error(
`Asset ${toMessageRelativeFilePath(
Expand Down Expand Up @@ -85,12 +85,12 @@ async function convertToAssetLinkIfNeeded({node, staticDir, filePath}) {
toAssetLinkNode(fileSystemAssetPath);
} else if (path.isAbsolute(assetPath)) {
const fileSystemAssetPath = path.join(staticDir, assetPath);
if (await fs.exists(fileSystemAssetPath)) {
if (await fs.pathExists(fileSystemAssetPath)) {
toAssetLinkNode(fileSystemAssetPath);
}
} else {
const fileSystemAssetPath = path.join(path.dirname(filePath), assetPath);
if (await fs.exists(fileSystemAssetPath)) {
if (await fs.pathExists(fileSystemAssetPath)) {
toAssetLinkNode(fileSystemAssetPath);
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-plugin-content-blog/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
"feed": "^4.2.2",
"fs-extra": "^9.1.0",
"globby": "^11.0.2",
"loader-utils": "^1.2.3",
"loader-utils": "^2.0.0",
"lodash": "^4.17.20",
"reading-time": "^1.3.0",
"remark-admonitions": "^1.2.1",
"tslib": "^2.1.0",
"webpack": "^4.44.1"
"webpack": "^5.28.0"
},
"peerDependencies": {
"react": "^16.8.4 || ^17.0.0",
Expand Down
9 changes: 4 additions & 5 deletions packages/docusaurus-plugin-content-blog/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import {
OptionValidationContext,
ValidationResult,
} from '@docusaurus/types';
import {Configuration, Loader} from 'webpack';
import {Configuration} from 'webpack';
import {
generateBlogFeed,
generateBlogPosts,
Expand Down Expand Up @@ -401,7 +401,7 @@ export default function pluginContentBlog(
configureWebpack(
_config: Configuration,
isServer: boolean,
{getBabelLoader, getCacheLoader}: ConfigureWebpackUtils,
{getJSLoader}: ConfigureWebpackUtils,
) {
const {
rehypePlugins,
Expand Down Expand Up @@ -441,8 +441,7 @@ export default function pluginContentBlog(
// Trailing slash is important, see https://github.com/facebook/docusaurus/pull/3970
.map(addTrailingPathSeparator),
use: [
getCacheLoader(isServer),
getBabelLoader(isServer),
getJSLoader({isServer}),
{
loader: require.resolve('@docusaurus/mdx-loader'),
options: {
Expand All @@ -466,7 +465,7 @@ export default function pluginContentBlog(
loader: path.resolve(__dirname, './markdownLoader.js'),
options: markdownLoaderOptions,
},
].filter(Boolean) as Loader[],
].filter(Boolean),
},
],
},
Expand Down
17 changes: 11 additions & 6 deletions packages/docusaurus-plugin-content-blog/src/markdownLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,21 @@
* LICENSE file in the root directory of this source tree.
*/

import {loader} from 'webpack';
import {truncate, linkify} from './blogUtils';
import {parseQuery, getOptions} from 'loader-utils';
import {parseQuery} from 'loader-utils';
import {BlogMarkdownLoaderOptions} from './types';

const markdownLoader: loader.Loader = function (source) {
// TODO temporary until Webpack5 export this type
// see https://github.com/webpack/webpack/issues/11630
interface Loader extends Function {
(this: any, source: string): string | Buffer | void | undefined;
}

const markdownLoader: Loader = function (source) {
const filePath = this.resourcePath;
const fileString = source as string;
const callback = this.async();
const markdownLoaderOptions = getOptions(this) as BlogMarkdownLoaderOptions;
const markdownLoaderOptions = this.getOptions() as BlogMarkdownLoaderOptions;

// Linkify blog posts
let finalContent = linkify({
Expand All @@ -24,8 +29,8 @@ const markdownLoader: loader.Loader = function (source) {
});

// Truncate content if requested (e.g: file.md?truncated=true).
const truncated: string | undefined = this.resourceQuery
? parseQuery(this.resourceQuery).truncated
const truncated: boolean | undefined = this.resourceQuery
? !!parseQuery(this.resourceQuery).truncated
: undefined;

if (truncated) {
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-plugin-content-docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"shelljs": "^0.8.4",
"tslib": "^2.1.0",
"utility-types": "^3.10.0",
"webpack": "^4.44.1"
"webpack": "^5.28.0"
},
"peerDependencies": {
"react": "^16.8.4 || ^17.0.0",
Expand Down
Loading