mirror of
https://github.com/zhigang1992/create-react-app.git
synced 2026-04-24 05:05:53 +08:00
55
packages/react-scripts/scripts/init.js
vendored
55
packages/react-scripts/scripts/init.js
vendored
@@ -118,11 +118,55 @@ module.exports = function(
|
||||
templateJson = require(templateJsonPath);
|
||||
}
|
||||
|
||||
const templatePackage = templateJson.package || {};
|
||||
|
||||
// Keys to ignore in templatePackage
|
||||
const templatePackageBlacklist = [
|
||||
'name',
|
||||
'version',
|
||||
'description',
|
||||
'keywords',
|
||||
'bugs',
|
||||
'license',
|
||||
'author',
|
||||
'contributors',
|
||||
'files',
|
||||
'main',
|
||||
'browser',
|
||||
'bin',
|
||||
'man',
|
||||
'directories',
|
||||
'repository',
|
||||
'devDependencies',
|
||||
'peerDependencies',
|
||||
'bundledDependencies',
|
||||
'optionalDependencies',
|
||||
'engineStrict',
|
||||
'os',
|
||||
'cpu',
|
||||
'preferGlobal',
|
||||
'private',
|
||||
'publishConfig',
|
||||
];
|
||||
|
||||
// Keys from templatePackage that will be merged with appPackage
|
||||
const templatePackageToMerge = ['dependencies', 'scripts'];
|
||||
|
||||
// Keys from templatePackage that will be added to appPackage,
|
||||
// replacing any existing entries.
|
||||
const templatePackageToReplace = Object.keys(templatePackage).filter(key => {
|
||||
return (
|
||||
!templatePackageBlacklist.includes(key) &&
|
||||
!templatePackageToMerge.includes(key)
|
||||
);
|
||||
});
|
||||
|
||||
// Copy over some of the devDependencies
|
||||
appPackage.dependencies = appPackage.dependencies || {};
|
||||
|
||||
// Setup the script rules
|
||||
const templateScripts = templateJson.scripts || {};
|
||||
// TODO: deprecate 'scripts' key directly on templateJson
|
||||
const templateScripts = templatePackage.scripts || templateJson.scripts || {};
|
||||
appPackage.scripts = Object.assign(
|
||||
{
|
||||
start: 'react-scripts start',
|
||||
@@ -152,6 +196,11 @@ module.exports = function(
|
||||
// Setup the browsers list
|
||||
appPackage.browserslist = defaultBrowsers;
|
||||
|
||||
// Add templatePackage keys/values to appPackage, replacing existing entries
|
||||
templatePackageToReplace.forEach(key => {
|
||||
appPackage[key] = templatePackage[key];
|
||||
});
|
||||
|
||||
fs.writeFileSync(
|
||||
path.join(appPath, 'package.json'),
|
||||
JSON.stringify(appPackage, null, 2) + os.EOL
|
||||
@@ -221,7 +270,9 @@ module.exports = function(
|
||||
}
|
||||
|
||||
// Install additional template dependencies, if present
|
||||
const templateDependencies = templateJson.dependencies;
|
||||
// TODO: deprecate 'dependencies' key directly on templateJson
|
||||
const templateDependencies =
|
||||
templatePackage.dependencies || templateJson.dependencies;
|
||||
if (templateDependencies) {
|
||||
args = args.concat(
|
||||
Object.keys(templateDependencies).map(key => {
|
||||
|
||||
Reference in New Issue
Block a user