Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/react-scripts/config/alias.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const paths = require('./paths');
const appPackageJson = require(paths.appPackageJson);
const definedAliases = appPackageJson.alias || [];

if (!Array.isArray(definedAliases)) {
throw new Error('Your alias declaration must be an array');
}

const alias = definedAliases.reduce((accum, current) => {
if (current.expose && current.source) {
accum[current.expose] = current.source;
}
return accum;
}, {});

module.exports = alias;
5 changes: 3 additions & 2 deletions packages/react-scripts/config/webpack.config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down
5 changes: 3 additions & 2 deletions packages/react-scripts/config/webpack.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down
8 changes: 7 additions & 1 deletion packages/react-scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,11 @@
},
"optionalDependencies": {
"fsevents": "1.1.2"
}
},
"alias": [
{
"source": "./src",
"expose": "src"
}
]
}