猿问

Nodejs里运行npm run dev shell脚本无效果?

问题描述
Nodejs里如何运行npmrundevshell脚本?
问题出现的环境背景及自己尝试过哪些方法
1、在webpack构建的模块里,npmrunscript一个node脚本文件,但是我想在这个脚本文件里运行其它的npmrun,尝试了require('child_process').exec但是无效,执行到这里什么反应都没。
相关代码
varexec=require('child_process').execSyncexec('npmrundev')
你期待的结果是什么?实际看到的错误信息又是什么?
或者在node脚本js文件里如何才能正确执行package.json里的script呢?
补充贴上package.json内容
{
"name":"vue",
"version":"1.0.0",
"description":"AVue.jsproject",
"author":"author@gmail.com",
"private":true,
"scripts":{
"dev":"webpack-dev-server--inline--progress--configbuild/webpack.dev.conf.js",
"modify":"nodescript/modify-path.js",
"build:prod":"npmrunmodify&&npmrunbuild--no-cache",
"start":"npmrundev",
"lint":"eslint--ext.js,.vuesrc",
"build":"nodebuild/build.js"
},
"dependencies":{
"fg-loadcss":"^2.0.1",
"vue-router":"^3.0.1"
},
"devDependencies":{
"autoprefixer":"^7.1.2",
"babel-core":"^6.22.1",
"babel-eslint":"^8.2.1",
"babel-helper-vue-jsx-merge-props":"^2.0.3",
"babel-loader":"^7.1.1",
"babel-plugin-syntax-jsx":"^6.18.0",
"babel-plugin-transform-runtime":"^6.22.0",
"babel-plugin-transform-vue-jsx":"^3.5.0",
"babel-preset-env":"^1.3.2",
"babel-preset-stage-2":"^6.22.0",
"chalk":"^2.0.1",
"commander":"^2.16.0",
"copy-webpack-plugin":"^4.0.1",
"cross-env":"^5.2.0",
"css-loader":"^0.28.0",
"eslint":"^4.19.1",
"eslint-config-standard":"^11.0.0",
"eslint-friendly-formatter":"^4.0.1",
"eslint-loader":"^2.0.0",
"eslint-plugin-import":"^2.13.0",
"eslint-plugin-node":"^6.0.1",
"eslint-plugin-promise":"^3.8.0",
"eslint-plugin-standard":"^3.1.0",
"eslint-plugin-vue":"^4.7.0",
"execa":"^0.10.0",
"file-loader":"^1.1.11",
"fontfaceobserver":"^2.0.13",
"fontmin":"^0.9.7-beta",
"fontmin-webpack":"^2.0.1",
"friendly-errors-webpack-plugin":"^1.6.1",
"html-webpack-plugin":"^3.2.0",
"inquirer":"^6.0.0",
"js-yaml":"^3.12.0",
"mini-css-extract-plugin":"^0.4.1",
"node-notifier":"^5.1.2",
"node-sass":"^4.9.2",
"optimize-css-assets-webpack-plugin":"^5.0.0",
"ora":"^1.2.0",
"portfinder":"^1.0.13",
"postcss-import":"^11.0.0",
"postcss-loader":"^2.0.8",
"postcss-url":"^7.2.1",
"rimraf":"^2.6.0",
"sass-loader":"^7.0.3",
"semver":"^5.3.0",
"shelljs":"^0.7.6",
"uglifyjs-webpack-plugin":"^1.1.1",
"url-loader":"^1.0.1",
"vue":"^2.5.16",
"vue-loader":"^15.2.4",
"vue-style-loader":"^3.0.1",
"vue-template-compiler":"^2.5.2",
"webfont-webpack-plugin":"^0.2.2",
"webpack":"^4.16.0",
"webpack-bundle-analyzer":"^2.9.0",
"webpack-cli":"^3.0.8",
"webpack-dev-server":"^3.1.4",
"webpack-merge":"^4.1.0"
},
"engines":{
"node":">=6.0.0",
"npm":">=3.0.0"
},
"browserslist":[
">1%",
"last2versions",
"notie<=8"
]
}
30秒到达战场
浏览 1703回答 2
2回答

至尊宝的传说

这就是你想要的varspawn=require('child_process').spawn;spawn('npm',['run','dev'],{stdio:'inherit'});或varexec=require('child_process').execSync;exec('npmrundev',{stdio:'inherit'});
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答