我正在尝试在节点js中创建全局模块,该模块将包含主Vue / Express应用程序。我正在尝试通过全局模块运行Vue前端,并使我的应用程序全局可用:)
我通过进入目录并键入以下内容来安装模块:
npm install -g .
我有一个名为index.js的主文件,在其中有我的代码,但由于某种原因它无法正常工作,因此我无法在全局范围内使用我的模块,每次运行时,我都会收到错误“ ENOET”而不是此类模块。
这是我的index.js
#!/usr/bin/env node
const spawn = require('child_process').spawn;
console.log('Dir name');
console.log(__dirname);
// spaws node process
let child = spawn('./node_modules/@vue/vue-cli-service', [
'serve'
]);
child.stdout.on('data', function (data) {
process.stdout.write(data);
});
child.stderr.on('data', function (data) {
process.stdout.write(data);
});
child.on('exit', function (data) {
process.stdout.write('I\'m done!');
});
和我的package.json
{
"name": "test-app",
"version": "0.1.0",
"private": true,
"preferGlobal": true,
"bin": {
"npm-analyzer": "./index.js"
},
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint",
"test-app-server": "node ./server/www",
"test-app-client": "npm run serve"
},
"dependencies": {
"axios": "^0.18.0",
"bulma": "^0.7.1",
"cors": "^2.8.4",
"express": "^4.16.3",
"font-awesome": "^4.7.0",
"node-sass": "^4.9.3",
"sass-loader": "^7.1.0",
"sort-by": "^1.2.0",
"vue": "^2.5.17"
},
"devDependencies": {
"@vue/cli-plugin-babel": "^3.0.1",
"@vue/cli-plugin-eslint": "^3.0.1",
"@vue/cli-service": "^3.0.1",
"vue-template-compiler": "^2.5.17"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/essential",
"eslint:recommended"
],
"rules": {},
"parserOptions": {
"parser": "babel-eslint"
}
},
"postcss": {
"plugins": {
"autoprefixer": {}
}
},
"browserslist": [
"> 1%",
"last 2 versions",
"not ie <= 8"
]
}
我认为链接存在问题。因为如果我打开终端并打印目录名,它将始终运行与我第一次安装软件包时相同的目录。