diff --git a/config/webpack.config.dev.js b/config/webpack.config.dev.js index 819ca0e9562..fe628e912ab 100644 --- a/config/webpack.config.dev.js +++ b/config/webpack.config.dev.js @@ -10,6 +10,7 @@ const path = require('path'); const webpack = require('webpack'); +const PnpWebpackPlugin = require('pnp-webpack-plugin'); const HtmlWebpackPlugin = require('html-webpack-plugin'); const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin'); const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin'); @@ -150,6 +151,9 @@ module.exports = { 'react-native': 'react-native-web', }, plugins: [ + // Adds support for installing with Plug'n'Play, leading to faster installs and adding + // guards against forgotten dependencies and such. + PnpWebpackPlugin, // Prevents users from importing files from outside of src/ (or node_modules/). // This often causes confusion because we only process files within src/ with babel. // To fix this, we prevent you from importing files out of src/ -- if you'd like to, @@ -158,6 +162,13 @@ module.exports = { new ModuleScopePlugin(paths.appSrc, [paths.appPackageJson]), ], }, + resolveLoader: { + plugins: [ + // Also related to Plug'n'Play, but this time it tells Webpack to load its loaders + // from the current package. + PnpWebpackPlugin.moduleLoader(module), + ], + }, module: { strictExportPresence: true, rules: [ diff --git a/config/webpack.config.prod.js b/config/webpack.config.prod.js index d71f2979caf..b1db45d778e 100644 --- a/config/webpack.config.prod.js +++ b/config/webpack.config.prod.js @@ -10,6 +10,7 @@ const path = require('path'); const webpack = require('webpack'); +const PnpWebpackPlugin = require('pnp-webpack-plugin'); const HtmlWebpackPlugin = require('html-webpack-plugin'); const InlineChunkHtmlPlugin = require('react-dev-utils/InlineChunkHtmlPlugin'); const TerserPlugin = require('terser-webpack-plugin'); @@ -214,6 +215,9 @@ module.exports = { 'react-native': 'react-native-web', }, plugins: [ + // Adds support for installing with Plug'n'Play, leading to faster installs and adding + // guards against forgotten dependencies and such. + PnpWebpackPlugin, // Prevents users from importing files from outside of src/ (or node_modules/). // This often causes confusion because we only process files within src/ with babel. // To fix this, we prevent you from importing files out of src/ -- if you'd like to, @@ -222,6 +226,13 @@ module.exports = { new ModuleScopePlugin(paths.appSrc, [paths.appPackageJson]), ], }, + resolveLoader: { + plugins: [ + // Also related to Plug'n'Play, but this time it tells Webpack to load its loaders + // from the current package. + PnpWebpackPlugin.moduleLoader(module), + ], + }, module: { strictExportPresence: true, rules: [ diff --git a/package.json b/package.json index 7170e4ff98b..659eb02ecb3 100644 --- a/package.json +++ b/package.json @@ -47,8 +47,11 @@ "html-webpack-plugin": "4.0.0-alpha.2", "identity-obj-proxy": "3.0.0", "jest": "23.6.0", + "jest-pnp-resolver": "1.0.1", + "jest-resolve": "23.6.0", "mini-css-extract-plugin": "0.4.3", "optimize-css-assets-webpack-plugin": "5.0.1", + "pnp-webpack-plugin": "1.1.0", "postcss-flexbugs-fixes": "4.1.0", "postcss-loader": "3.0.0", "postcss-preset-env": "6.0.6", diff --git a/scripts/init.js b/scripts/init.js index 2904ae70cfe..8ec24967528 100644 --- a/scripts/init.js +++ b/scripts/init.js @@ -81,9 +81,9 @@ module.exports = function( originalDirectory, template ) { - const ownPackageName = require(path.join(__dirname, '..', 'package.json')) - .name; - const ownPath = path.join(appPath, 'node_modules', ownPackageName); + const ownPath = path.dirname( + require.resolve(path.join(__dirname, '..', 'package.json')) + ); const appPackage = require(path.join(appPath, 'package.json')); const useYarn = fs.existsSync(path.join(appPath, 'yarn.lock')); diff --git a/scripts/utils/createJestConfig.js b/scripts/utils/createJestConfig.js index 22e52dbdca4..af085383f0b 100644 --- a/scripts/utils/createJestConfig.js +++ b/scripts/utils/createJestConfig.js @@ -22,7 +22,8 @@ module.exports = (resolve, rootDir, isEjecting) => { // in Jest configs. We need help from somebody with Windows to determine this. const config = { collectCoverageFrom: ['src/**/*.{js,jsx}'], - setupFiles: ['react-app-polyfill/jsdom'], + resolver: require.resolve('jest-pnp-resolver'), + setupFiles: [require.resolve('react-app-polyfill/jsdom')], setupTestFrameworkScriptFile: setupTestsFile, testMatch: [ '/src/**/__tests__/**/*.{js,jsx}',