【发布时间】:2014-06-22 03:36:15
【问题描述】:
如何使用nodejs搭建跨平台项目?
我在 Windows 上开发,但我的代码库构建在基于 Linux 的 CI 服务器上。它使用 Grunt 构建前端,并且需要几个 nodejs 模块。
Nodejs 需要将模块安装到项目本地,以便 grunt.task.loadNpmTasks 加载。问题是我必须从某个地方安装它们,无论是 Windows 还是 Linux,当我从一个安装它们时,它在另一个上不起作用。
我的项目需要的列表模块在本地安装如下:
npm install connect-livereload --production
npm install time-grunt --production
npm install load-grunt-tasks --production
npm install jshint-stylish --production
npm install load-grunt-tasks --production
npm install grunt-contrib-copy --production
npm install grunt-contrib-concat --production
npm install grunt-contrib-uglify --production
npm install grunt-contrib-compass --production
npm install grunt-contrib-jshint --production
npm install grunt-contrib-cssmin --production
npm install grunt-contrib-connect --production
npm install grunt-contrib-clean --production
npm install grunt-contrib-htmlmin --production
npm install grunt-contrib-imagemin --production
npm install grunt-contrib-watch --production
npm install grunt-rev --production
npm install grunt-usemin --production
npm install grunt-mocha --production
npm install grunt-exec --production
npm install grunt-open --production
npm install grunt-svgmin --production
npm install grunt-concurrent --production
npm install grunt-ember-templates --production
npm install grunt-replace --production
npm install grunt-neuter --production
如果我从 Windows 安装它,然后在 Windows 的项目文件夹上运行 grunt,它仍然可以正常工作。如果我随后将代码签入 git 并在 linux 框中构建,chmod 777 和 chown 给我的用户,然后运行相同的 grunt 命令。它失败了,出现了很多类似这样的错误:
Running "mocha:all" (mocha) task
Testing: http://localhost:9000/index.html
Fatal error: spawn ENOENT
我运行了npm install,但它开始失败并显示另一条消息:
Running "mocha:all" (mocha) task
Testing: http://localhost:9000/index.html
/home/administrator/platform/frontend/node_modules/grunt-contrib-compass/node_modules/tmp/lib/tmp.js:261
throw err;
^
Error: spawn ENOENT
at errnoException (child_process.js:998:11)
at Process.ChildProcess._handle.onexit (child_process.js:789:34)
我所做的一切都无法让它发挥作用。
因此,我从 Linux 框中删除了项目中的整个 node_modules 目录,然后重新运行上面的安装命令。现在一切都可以在 Linux 上完美运行。
然后我将其签入 git 并在 Windows 中签出。然后我转到项目文件夹并运行grunt,然后它失败了:
Running "mocha:all" (mocha) task
Testing: http://localhost:9000/index.html
Running PhantomJS...ERROR
>> 'c:\Users\Edy' is not recognized as an internal or external command,
0 [ '\'c:\\Users\\Edy\' is not recognized as an internal or external command,\r',
>> 'operable program or batch file.' ]
>> operable program or batch file. 1 [ '\'c:\\Users\\Edy\' is not recognized as an internal or external command,\r',
>> 'operable program or batch file.' ]
Warning: PhantomJS exited unexpectedly with exit code 1. Use --force to continue.
卸载 phantomjs 并在本地安装它没有帮助。全局安装也无济于事。所以让它在 Windows 上工作的唯一方法似乎是删除 node_modules 目录并在 Windows 上重新安装,这让我想到了 Linux 上的第一个问题。
有没有办法在像我这样的跨平台环境中使用 nodejs 的东西?我不敢相信我是第一个有这种设置的人,呵呵
感谢任何提示或帮助。谢谢!
【问题讨论】:
标签: node.js gruntjs cross-platform phantomjs mocha.js