Skip to content

Commit

Permalink
fix(v2): fix babel transpilation include/exclude logic (#1868)
Browse files Browse the repository at this point in the history
* fix(v2): fix babel transpilation include/exclude logic

* nits

* optimize

* docs migration before alpha.30 hotfix
  • Loading branch information
endiliey authored Oct 22, 2019
1 parent b56adb7 commit 4c4e6ad
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 24 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG-2.x.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Docusaurus 2 Changelog

## 2.0.0-alpha.30
- Fix babel transpilation include/exclude logic to be more efficient. This also fix a very weird bug `TypeError: Cannot assign to read only property 'exports' of object '#<Object>'` if your website path contains `docusaurus` word in it.

## 2.0.0-alpha.29

**HOTFIX for 2.0.0-alpha.28**.
Expand Down
10 changes: 8 additions & 2 deletions packages/docusaurus/src/webpack/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export function createBaseConfig(
): Configuration {
const {outDir, siteDir, baseUrl, generatedFilesDir, routesPaths} = props;

const clientDir = path.join(__dirname, '..', 'client');
const totalPages = routesPaths.length;
const isProd = process.env.NODE_ENV === 'production';
return {
Expand Down Expand Up @@ -115,9 +116,14 @@ export function createBaseConfig(
{
test: /\.jsx?$/,
exclude: modulePath => {
// Don't transpile node_modules except any docusaurus package
// always transpile client dir
if (modulePath.startsWith(clientDir)) {
return false;
}
// Don't transpile node_modules except any docusaurus npm package
return (
/node_modules/.test(modulePath) && !/docusaurus/.test(modulePath)
/node_modules/.test(modulePath) &&
!/(docusaurus)((?!node_modules).)*\.jsx?$/.test(modulePath)
);
},
use: [getCacheLoader(isServer), getBabelLoader(isServer)].filter(
Expand Down
10 changes: 7 additions & 3 deletions packages/docusaurus/src/webpack/plugins/LogPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ class LogPlugin extends WebpackBar {
super.apply(compiler);

compiler.hooks.done.tap('WebpackNiceLog', stats => {
const messages = formatWebpackMessages(stats.toJson('errors-only', true));
if (messages.errors.length) {
showError(messages.errors);
if (stats.hasErrors()) {
const messages = formatWebpackMessages(
stats.toJson('errors-only', true),
);
if (messages.errors.length) {
showError(messages.errors);
}
}
});
}
Expand Down
9 changes: 8 additions & 1 deletion packages/docusaurus/src/webpack/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,14 @@ export function getBabelLoader(isServer: boolean, babelOptions?: {}): Loader {
configFile: false,
presets: [
isServer
? '@babel/env'
? [
'@babel/env',
{
targets: {
node: 'current',
},
},
]
: [
'@babel/env',
{
Expand Down
8 changes: 4 additions & 4 deletions website/docs/migrating-from-v1-to-v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ Meanwhile, the default doc site functionalities provided by Docusaurus 1 are now
{
dependencies: {
- "docusaurus": "^1.x.x",
+ "@docusaurus/core": "^2.0.0-alpha.29",
+ "@docusaurus/preset-classic": "^2.0.0-alpha.29",
+ "@docusaurus/core": "^2.0.0-alpha.30",
+ "@docusaurus/preset-classic": "^2.0.0-alpha.30",
}
}
```
Expand Down Expand Up @@ -71,8 +71,8 @@ A typical Docusaurus 2 `package.json` may look like this:
"deploy": "docusaurus deploy"
},
"dependencies": {
"@docusaurus/core": "^2.0.0-alpha.29",
"@docusaurus/preset-classic": "^2.0.0-alpha.29",
"@docusaurus/core": "^2.0.0-alpha.30",
"@docusaurus/preset-classic": "^2.0.0-alpha.30",
"classnames": "^2.2.6",
"react": "^16.10.2",
"react-dom": "^16.10.2"
Expand Down
18 changes: 4 additions & 14 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4410,20 +4410,10 @@ caniuse-api@^3.0.0:
lodash.memoize "^4.1.2"
lodash.uniq "^4.5.0"

caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000971:
version "1.0.30000974"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30000974.tgz#b7afe14ee004e97ce6dc73e3f878290a12928ad8"
integrity sha512-xc3rkNS/Zc3CmpMKuczWEdY2sZgx09BkAxfvkxlAEBTqcMHeL8QnPqhKse+5sRTi3nrw2pJwToD2WvKn1Uhvww==

caniuse-lite@^1.0.30000980, caniuse-lite@^1.0.30000981, caniuse-lite@^1.0.30000984:
version "1.0.30000984"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30000984.tgz#dc96c3c469e9bcfc6ad5bdd24c77ec918ea76fe0"
integrity sha512-n5tKOjMaZ1fksIpQbjERuqCyfgec/m9pferkFQbLmWtqLUdmt12hNhjSwsmPdqeiG2NkITOQhr1VYIwWSAceiA==

caniuse-lite@^1.0.30000989:
version "1.0.30000989"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30000989.tgz#b9193e293ccf7e4426c5245134b8f2a56c0ac4b9"
integrity sha512-vrMcvSuMz16YY6GSVZ0dWDTJP8jqk3iFQ/Aq5iqblPwxSVVZI+zxDyTX0VPqtQsDnfdrBDcsmhgTEOh5R8Lbpw==
caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000971, caniuse-lite@^1.0.30000980, caniuse-lite@^1.0.30000981, caniuse-lite@^1.0.30000984, caniuse-lite@^1.0.30000989:
version "1.0.30001002"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001002.tgz#ba999a737b1abd5bf0fd47efe43a09b9cadbe9b0"
integrity sha512-pRuxPE8wdrWmVPKcDmJJiGBxr6lFJq4ivdSeo9FTmGj5Rb8NX3Mby2pARG57MXF15hYAhZ0nHV5XxT2ig4bz3g==

capture-exit@^2.0.0:
version "2.0.0"
Expand Down

0 comments on commit 4c4e6ad

Please sign in to comment.