forked from facebook/create-react-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow webpack aliases to be defined in an env variable to prevent dup…
…licate React issue (create-react-app#675) facebook#675 (comment)
- Loading branch information
Showing
3 changed files
with
86 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
const paths = require('./paths'); | ||
|
||
const mapDependenciesToFolder = (dependencies, folder) => | ||
dependencies.reduce( | ||
(accumulator, dependency) => | ||
Object.assign( | ||
{}, | ||
{ | ||
[dependency]: path.resolve(folder, dependency), | ||
}, | ||
accumulator | ||
), | ||
{} | ||
); | ||
|
||
const topLevelModuleNames = () => { | ||
const config = process.env.TOP_LEVEL_MODULES; | ||
if (config) { | ||
if (config.toLowerCase() === 'true') { | ||
// return defaults | ||
return ['react', 'react-dom']; | ||
} | ||
|
||
let json; | ||
try { | ||
json = JSON.parse(config); | ||
} catch (e) { | ||
// continue regardless of error | ||
} | ||
|
||
if (Array.isArray(json)) { | ||
return json; | ||
} else { | ||
return config; | ||
} | ||
} | ||
}; | ||
|
||
const getTopLevelModules = () => { | ||
const modulesNames = topLevelModuleNames(); | ||
if (modulesNames) { | ||
mapDependenciesToFolder(modulesNames, paths.appNodeModules); | ||
} | ||
return {}; | ||
}; | ||
|
||
module.exports = getTopLevelModules; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters