Skip to content

Commit f04f0dd

Browse files
author
Maël Nison
committed
Adds the PnP plugin for Webpack to find dependencies when working under PnP
1 parent e4270bd commit f04f0dd

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

Diff for: packages/react-scripts/config/webpack.config.dev.js

+17
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
const path = require('path');
1212
const webpack = require('webpack');
13+
const PnpWebpackPlugin = require('pnp-webpack-plugin');
1314
const HtmlWebpackPlugin = require('html-webpack-plugin');
1415
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
1516
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
@@ -149,13 +150,29 @@ module.exports = {
149150
'react-native': 'react-native-web',
150151
},
151152
plugins: [
153+
// Adds support for installing with Plug'n'Play, leading to faster installs and adding
154+
// guards against forgotten dependencies and such.
155+
PnpWebpackPlugin,
152156
// Prevents users from importing files from outside of src/ (or node_modules/).
153157
// This often causes confusion because we only process files within src/ with babel.
154158
// To fix this, we prevent you from importing files out of src/ -- if you'd like to,
155159
// please link the files into your node_modules/ and let module-resolution kick in.
156160
// Make sure your source files are compiled, as they will not be processed in any way.
157161
new ModuleScopePlugin(paths.appSrc, [paths.appPackageJson]),
158162
],
163+
// Plug'n'Play relies on symlink for its virtual paths (ie peer dependencies), which Webpack
164+
// always resolve to the absolute path on disk by default.
165+
symlinks: false,
166+
},
167+
resolveLoader: {
168+
plugins: [
169+
// Also related to Plug'n'Play, but this time it tells Webpack to load its loaders
170+
// from the current package.
171+
PnpWebpackPlugin.moduleLoader(module),
172+
],
173+
// Plug'n'Play relies on symlink for its virtual paths (ie peer dependencies), which Webpack
174+
// always resolve to the absolute path on disk by default.
175+
symlinks: false,
159176
},
160177
module: {
161178
strictExportPresence: true,

Diff for: packages/react-scripts/config/webpack.config.prod.js

+17
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
const path = require('path');
1212
const webpack = require('webpack');
13+
const PnpWebpackPlugin = require('pnp-webpack-plugin');
1314
const HtmlWebpackPlugin = require('html-webpack-plugin');
1415
const InlineChunkHtmlPlugin = require('react-dev-utils/InlineChunkHtmlPlugin');
1516
const TerserPlugin = require('terser-webpack-plugin');
@@ -204,13 +205,29 @@ module.exports = {
204205
'react-native': 'react-native-web',
205206
},
206207
plugins: [
208+
// Adds support for installing with Plug'n'Play, leading to faster installs and adding
209+
// guards against forgotten dependencies and such.
210+
PnpWebpackPlugin,
207211
// Prevents users from importing files from outside of src/ (or node_modules/).
208212
// This often causes confusion because we only process files within src/ with babel.
209213
// To fix this, we prevent you from importing files out of src/ -- if you'd like to,
210214
// please link the files into your node_modules/ and let module-resolution kick in.
211215
// Make sure your source files are compiled, as they will not be processed in any way.
212216
new ModuleScopePlugin(paths.appSrc, [paths.appPackageJson]),
213217
],
218+
// Plug'n'Play relies on symlink for its virtual paths (ie peer dependencies), which Webpack
219+
// always resolve to the absolute path on disk by default.
220+
symlinks: false,
221+
},
222+
resolveLoader: {
223+
plugins: [
224+
// Also related to Plug'n'Play, but this time it tells Webpack to load its loaders
225+
// from the current package.
226+
PnpWebpackPlugin.moduleLoader(module),
227+
],
228+
// Plug'n'Play relies on symlink for its virtual paths (ie peer dependencies), which Webpack
229+
// always resolve to the absolute path on disk by default.
230+
symlinks: false,
214231
},
215232
module: {
216233
strictExportPresence: true,

Diff for: packages/react-scripts/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"jest": "23.6.0",
5050
"mini-css-extract-plugin": "0.4.3",
5151
"optimize-css-assets-webpack-plugin": "5.0.1",
52+
"pnp-webpack-plugin": "1.0.2",
5253
"postcss-flexbugs-fixes": "4.1.0",
5354
"postcss-loader": "3.0.0",
5455
"postcss-preset-env": "6.0.6",

0 commit comments

Comments
 (0)