From f0d11a63ee45b04b26f1772f2974206ee0cc5982 Mon Sep 17 00:00:00 2001 From: Trey Huffine Date: Mon, 4 Dec 2017 10:42:09 -0800 Subject: [PATCH 1/3] Add absolute paths with alias --- packages/react-scripts/config/alias.js | 13 +++++++++++++ packages/react-scripts/config/webpack.config.dev.js | 5 +++-- .../react-scripts/config/webpack.config.prod.js | 5 +++-- 3 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 packages/react-scripts/config/alias.js diff --git a/packages/react-scripts/config/alias.js b/packages/react-scripts/config/alias.js new file mode 100644 index 00000000000..162eaff4a73 --- /dev/null +++ b/packages/react-scripts/config/alias.js @@ -0,0 +1,13 @@ +const packageJson = require('../package.json'); +const definedAliases = packageJson.alias || []; + +if (!Array.isArray(definedAliases)) { + throw new Error('Your aliases declaraction must be an array'); +} + +const alias = definedAliases.alias.reduce((accum, current) => { + accum[current.expose] = current.source; + return accum; +}, {}); + +module.exports = alias; diff --git a/packages/react-scripts/config/webpack.config.dev.js b/packages/react-scripts/config/webpack.config.dev.js index a6be022ba25..853520c506a 100644 --- a/packages/react-scripts/config/webpack.config.dev.js +++ b/packages/react-scripts/config/webpack.config.dev.js @@ -17,6 +17,7 @@ const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin'); const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin'); const eslintFormatter = require('react-dev-utils/eslintFormatter'); const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin'); +const alias = require('./alias'); const getClientEnvironment = require('./env'); const paths = require('./paths'); @@ -91,7 +92,7 @@ module.exports = { // `web` extension prefixes have been added for better support // for React Native Web. extensions: ['.web.js', '.mjs', '.js', '.json', '.web.jsx', '.jsx'], - alias: { + alias: Object.assign({ // @remove-on-eject-begin // Resolve Babel runtime relative to react-scripts. // It usually still works on npm 3 without this but it would be @@ -104,7 +105,7 @@ module.exports = { // Support React Native Web // https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/ 'react-native': 'react-native-web', - }, + }, alias), plugins: [ // 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. diff --git a/packages/react-scripts/config/webpack.config.prod.js b/packages/react-scripts/config/webpack.config.prod.js index 457a9672892..01ff5b4f140 100644 --- a/packages/react-scripts/config/webpack.config.prod.js +++ b/packages/react-scripts/config/webpack.config.prod.js @@ -18,6 +18,7 @@ const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin'); const SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin'); const eslintFormatter = require('react-dev-utils/eslintFormatter'); const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin'); +const alias = require('./alias'); const paths = require('./paths'); const getClientEnvironment = require('./env'); @@ -97,7 +98,7 @@ module.exports = { // `web` extension prefixes have been added for better support // for React Native Web. extensions: ['.web.js', '.mjs', '.js', '.json', '.web.jsx', '.jsx'], - alias: { + alias: Object.assign({ // @remove-on-eject-begin // Resolve Babel runtime relative to react-scripts. // It usually still works on npm 3 without this but it would be @@ -110,7 +111,7 @@ module.exports = { // Support React Native Web // https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/ 'react-native': 'react-native-web', - }, + }, alias), plugins: [ // 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. From 105ba5cc850a40851603e04b334d8abe7f3b0dff Mon Sep 17 00:00:00 2001 From: Trey Huffine Date: Tue, 5 Dec 2017 08:00:55 -0800 Subject: [PATCH 2/3] Fix bug and check for correct structure --- packages/react-scripts/config/alias.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/react-scripts/config/alias.js b/packages/react-scripts/config/alias.js index 162eaff4a73..7317b2e8d29 100644 --- a/packages/react-scripts/config/alias.js +++ b/packages/react-scripts/config/alias.js @@ -5,8 +5,10 @@ if (!Array.isArray(definedAliases)) { throw new Error('Your aliases declaraction must be an array'); } -const alias = definedAliases.alias.reduce((accum, current) => { - accum[current.expose] = current.source; +const alias = definedAliases.reduce((accum, current) => { + if (current.expost && current.source) { + accum[current.expose] = current.source; + } return accum; }, {}); From c3b37340c6f49a164a980251afffcae5309394e8 Mon Sep 17 00:00:00 2001 From: Trey Huffine Date: Tue, 5 Dec 2017 08:22:01 -0800 Subject: [PATCH 3/3] Match internal conventions --- packages/react-scripts/config/alias.js | 9 +++++---- packages/react-scripts/package.json | 8 +++++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/react-scripts/config/alias.js b/packages/react-scripts/config/alias.js index 7317b2e8d29..f1d4098aad0 100644 --- a/packages/react-scripts/config/alias.js +++ b/packages/react-scripts/config/alias.js @@ -1,12 +1,13 @@ -const packageJson = require('../package.json'); -const definedAliases = packageJson.alias || []; +const paths = require('./paths'); +const appPackageJson = require(paths.appPackageJson); +const definedAliases = appPackageJson.alias || []; if (!Array.isArray(definedAliases)) { - throw new Error('Your aliases declaraction must be an array'); + throw new Error('Your alias declaration must be an array'); } const alias = definedAliases.reduce((accum, current) => { - if (current.expost && current.source) { + if (current.expose && current.source) { accum[current.expose] = current.source; } return accum; diff --git a/packages/react-scripts/package.json b/packages/react-scripts/package.json index dcac53cf49f..e5e01cb56e7 100644 --- a/packages/react-scripts/package.json +++ b/packages/react-scripts/package.json @@ -64,5 +64,11 @@ }, "optionalDependencies": { "fsevents": "1.1.2" - } + }, + "alias": [ + { + "source": "./src", + "expose": "src" + } + ] }