Skip to content

Commit

Permalink
feat(gatsby): set up webpack config for eventual PnP support (#12315)
Browse files Browse the repository at this point in the history
## Description

This diff adds `pnp-webpack-plugin` in the configuration so that users don't have to manually extend the Webpack configuration to support PnP.

Note that the plugin [is a strict no-op](https://github.com/arcanis/pnp-webpack-plugin/blob/master/index.js#L110-L138) when not operating within a PnP environment, so it shouldn't break any existing workflow 🙂 

## Related Issues

Part of #10245 
Depends on #12163
  • Loading branch information
arcanis authored and DSchau committed Mar 15, 2019
1 parent b62816f commit ad6319b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/gatsby/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
"optimize-css-assets-webpack-plugin": "^5.0.1",
"parseurl": "^1.3.2",
"physical-cpu-count": "^2.0.0",
"pnp-webpack-plugin": "^1.4.1",
"postcss-flexbugs-fixes": "^3.0.0",
"postcss-loader": "^2.1.3",
"prop-types": "^15.6.1",
Expand Down
12 changes: 12 additions & 0 deletions packages/gatsby/src/utils/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const fs = require(`fs-extra`)
const path = require(`path`)
const dotenv = require(`dotenv`)
const FriendlyErrorsWebpackPlugin = require(`@pieh/friendly-errors-webpack-plugin`)
const PnpWebpackPlugin = require(`pnp-webpack-plugin`)
const { store } = require(`../redux`)
const { actions } = require(`../redux/actions`)
const debug = require(`debug`)(`gatsby:webpack-config`)
Expand Down Expand Up @@ -333,6 +334,14 @@ module.exports = async (
),
"create-react-context": directoryPath(`.cache/create-react-context.js`),
},
plugins: [
// Those two folders are special and contain gatsby-generated files
// whose dependencies should be resolved through the `gatsby` package
PnpWebpackPlugin.bind(directoryPath(`.cache`), module),
PnpWebpackPlugin.bind(directoryPath(`public`), module),
// Transparently resolve packages via PnP when needed; noop otherwise
PnpWebpackPlugin,
],
}
}

Expand All @@ -351,6 +360,9 @@ module.exports = async (

return {
modules: [...root, path.join(__dirname, `../loaders`), `node_modules`],
// Bare loaders should always be loaded via the user dependencies (loaders
// configured via third-party like gatsby use require.resolve)
plugins: [PnpWebpackPlugin.moduleLoader(`${directory}/`)],
}
}

Expand Down
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15441,6 +15441,13 @@ pngquant-bin@^5.0.0:
execa "^0.10.0"
logalot "^2.0.0"

pnp-webpack-plugin@^1.4.1:
version "1.4.1"
resolved "https://registry.yarnpkg.com/pnp-webpack-plugin/-/pnp-webpack-plugin-1.4.1.tgz#e8f8c683b496a71c0d200e664c4bb399a9c9585e"
integrity sha512-S4kz+5rvWvD0w1O63eTJeXIxW4JHK0wPRMO7GmPhbZXJnTePcfrWZlni4BoglIf7pLSY18xtqo3MSnVkoAFXKg==
dependencies:
ts-pnp "^1.0.0"

portfinder@^1.0.9:
version "1.0.17"
resolved "https://registry.yarnpkg.com/portfinder/-/portfinder-1.0.17.tgz#a8a1691143e46c4735edefcf4fbcccedad26456a"
Expand Down Expand Up @@ -19419,6 +19426,11 @@ trough@^1.0.0:
dependencies:
glob "^7.1.2"

ts-pnp@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/ts-pnp/-/ts-pnp-1.0.1.tgz#fde74a6371676a167abaeda1ffc0fdb423520098"
integrity sha512-Zzg9XH0anaqhNSlDRibNC8Kp+B9KNM0uRIpLpGkGyrgRIttA7zZBhotTSEoEyuDrz3QW2LGtu2dxuk34HzIGnQ==

tsickle@^0.27.2:
version "0.27.5"
resolved "https://registry.yarnpkg.com/tsickle/-/tsickle-0.27.5.tgz#41e1a41a5acf971cbb2b0558a9590779234d591f"
Expand Down

0 comments on commit ad6319b

Please sign in to comment.