2015-04-05 10 views
8

मुझे package.json फाइलों के 2 स्तर मिल गए हैं।एनपीएम रन <script> बच्चे पैकेज.जेसन को कैसे प्रतिनिधि है?

उदाहरण यहाँ है:

https://github.com/justin808/react-webpack-rails-tutorial

कारण यह है कि शीर्ष स्तर एक रेल अनुप्रयोग है, और मैं एक निर्देशिका कहा जाता है ग्राहक के तहत सभी नोड उपकरण डाल रहा हूँ, साथ उसके अपने package.json फ़ाइल। शीर्ष स्तर package.json फ़ाइल एक सुविधा के रूप में अच्छी तरह से नोड buildpack npm install स्क्रिप्ट चलाने के लिए के लिए एक हुक है।

मैं gulp आदेश अग्रेषण का एक उदाहरण मिल गया है। बच्चे के लिए शीर्ष स्तर package.json से कुछ भी सामान्य रूप से अग्रेषित करने का कोई तरीका नहीं है?

शीर्ष स्तरीय package.json

{ 
    "name": "react-webpack-rails-tutorial", 
    "version": "1.1.1", 
    "description": "Code from the React Webpack tutorial.", 
    "main": "server.js", 
    "engines": { 
    "node": "0.10.32" 
    }, 
    "scripts": { 
    "postinstall": "cd ./client && npm install", 
    "gulp": "cd ./client && npm run gulp" 
    }, 
    "repository": { 
    "type": "git", 
    "url": "https://github.com/justin808/react-webpack-rails-tutorial.git" 
    }, 
    "keywords": [ 
    "react", 
    "tutorial", 
    "comment", 
    "example" 
    ], 
    "author": "justin808", 
    "license": "MIT", 
    "bugs": { 
    "url": "https://github.com/justin808/react-webpack-rails-tutorial/issues" 
    }, 
    "homepage": "https://github.com/justin808/react-webpack-rails-tutorial" 
} 

Subdirectory package.json

{ 
    "name": "react-webpack-rails-tutorial", 
    "version": "1.1.0", 
    "description": "Code from the React Webpack tutorial.", 
    "main": "server.js", 
    "engines": { 
    "node": "0.10.32" 
    }, 
    "repository": { 
    "type": "git", 
    "url": "https://github.com/justin808/react-webpack-rails-tutorial.git" 
    }, 
    "keywords": [ 
    "react", 
    "tutorial", 
    "comment", 
    "example" 
    ], 
    "author": "justin808", 
    "license": "MIT", 
    "bugs": { 
    "url": "https://github.com/justin808/react-webpack-rails-tutorial/issues" 
    }, 
    "homepage": "https://github.com/justin808/react-webpack-rails-tutorial", 
    "dependencies": { 
    "babel-core": "^5.0.8", 
    "babel-loader": "^5.0.0", 
    "body-parser": "^1.12.2", 
    "es5-shim": "^4.1.0", 
    "imports-loader": "^0.6.3", 
    "jquery": "^2.1.3", 
    "loader-utils": "^0.2.6", 
    "marked": "^0.3.3", 
    "react": "^0.13.1", 
    "react-bootstrap": "^0.20.1", 
    "sleep": "^2.0.0", 
    "webpack": "^1.7.3" 
    }, 
    "devDependencies": { 
    "babel-eslint": "^2.0.2", 
    "bootstrap-sass": "^3.3.4", 
    "bootstrap-sass-loader": "^1.0.3", 
    "css-loader": "^0.9.1", 
    "eslint": "^0.18.0", 
    "eslint-plugin-react": "^2.0.2", 
    "expose-loader": "^0.6.0", 
    "express": "^4.12.3", 
    "file-loader": "^0.8.1", 
    "gulp": "^3.8.11", 
    "gulp-eslint": "^0.8.0", 
    "node-sass": "^2.1.1", 
    "react-hot-loader": "^1.2.4", 
    "sass-loader": "^0.6.0", 
    "style-loader": "^0.9.0", 
    "url-loader": "^0.5.5", 
    "webpack-dev-server": "^1.8.0" 
    }, 
    "scripts": { 
    "test": "echo \"Error: no test specified\" && exit 1", 
    "start": "node server.js", 
    "gulp": "gulp" 
    } 
} 

उत्तर

0

आप एक बैच फ़ाइल जहां gulp -command डाल लिख सकते हैं। फिर आपको त्रुटि की जांच करनी होगी। यही कारण है कि ऐसा दिखाई दे सकता:

@echo off 

:RUN_GULP 
echo Running Gulp... 
gulp 
goto END 

:END 
if %ERRORLEVEL% neq 0 goto PROCESS_ERROR 
exit 

:PROCESS_ERROR 
cd ./client 
gulp 
exit; 

तो फिर तुम सिर्फ इस तरह अपने package.json में स्क्रिप्ट कॉल करनी होगी:

"gulp": "call ./path/to/batfile.bat" 

अपने प्रोजेक्ट पर एक ही था .. ..

संपादित करें: सभी स्क्रिप्ट के लिए .... आप एक बैचफाइल बना सकते हैं जो स्क्रिप्ट नाम को सर्वो के रूप में लेता है eter। लिपि उपरोक्त की तरह ही करता है, लेकिन इसे प्रत्येक कमांड के लिए काम करना चाहिए।

ध्यान दें: आप start path/to/batchfile.bat gulp बजाय npm run gulp की तरह कुछ का उपयोग करने के लिए है। त्रुटि निवारण एनपीएम त्रुटियों के लिए काम नहीं करते हैं!

यह ऐसा दिखाई दे सकता:

@echo off 

:: Check if script is defined 
set _script=%1 
if "%_script%"=="" goto NO_SCRIPT_DEFINED 

:START_APP 
npm run %_script% 
goto END 

:NO_SCRIPT_DEFINED 
echo ERROR: script was not defined 
pause 
exit 

:END 
if %ERRORLEVEL% neq 0 goto NO_PARENT_SCRIPT 
exit 

:NO_PARENT_SCRIPT 
echo searching in ./client ... 
cd ./client 
npm run %_script% 
exit 
7

आप लेन-देन को आसान बनाने के npm run स्क्रिप्ट का उपयोग कर सकते हैं (npm-scripts देखें)।

"scripts": { 
     ... 
    "client-build": "cd client && npm run build" 
    } 

कहाँ ग्राहक क्लाइंट-साइड कोड के निर्माण के लिए npm run build कमांड के साथ एक package.json है: माता-पिता package.json में।

फिर अन्य कार्यों की शेल कमांड के हिस्से के रूप npm run client-build आह्वान। उदाहरण के लिए:

"scripts": { 
    "start": "npm run client-build && gulp some-task", 
    ... 
    } 

यह अपने आप Git रेपो और एक postinstall स्क्रिप्ट के माध्यम से निर्माण के साथ एक अलग मॉड्यूल में बच्चे को परियोजना को तोड़ने के लिए मदद मिल सकती है।उस स्थिति में, जब पेरेंट प्रोजेक्ट पर npm install चलाते हैं, तो बच्चे को खुद को बनाने का मौका मिलेगा।

संबंधित मुद्दे