我在Sails中很新。
我已经从Sails模板创建了一个新的Web应用程序,并尝试将其上传到Heroku。一切都很好,除了资产,没有找到任何资产(js,css,图像等)。
我发现Sails使用Grunt将文件复制到.tmp文件夹。我已经检查过,我已将Grunt添加到我的package.json
文件中。我还添加了一个带有web: node app.js
命令的procfile和它指向Heroku中的NODE_ENV
的production
变量。
我没有改变任何Grunt任务,Gruntfile.js
文件和/tasks
目录是默认的。
我还能检查什么?
我通过不同的方式解决了这个问题。除了在OP的答案中包含一些grunt
deps之外,我在postinstall
的脚本部分添加了package.json
:
"scripts": {
"start": "NODE_ENV=production node app.js",
"test": "npm run lint && npm run custom-tests && echo 'Done.'",
"lint": "eslint . --max-warnings=0 --report-unused-disable-directives && echo '✔ Your .js files look so good.' && htmlhint -c ./.htmlhintrc views/*.ejs && htmlhint -c ./.htmlhintrc views/**/*.ejs && htmlhint -c ./.htmlhintrc views/**/**/*.ejs && htmlhint -c ./.htmlhintrc views/**/**/**/*.ejs && htmlhint -c ./.htmlhintrc views/**/**/**/**/*.ejs && htmlhint -c ./.htmlhintrc views/**/**/**/**/**/*.ejs && htmlhint -c ./.htmlhintrc views/**/**/**/**/**/**/*.ejs && echo '✔ So do your .ejs files.' && lesshint assets/styles/ --max-warnings=0 && echo '✔ Your .less files look good, too.'",
"custom-tests": "echo \"(No other custom tests yet.)\" && echo",
"postinstall": "grunt build", // added this
...
这对heroku的影响是需要运行的grunt任务build
,它将资产编译并复制到适当引用的位置(即:.tmp
)
解决方案非常简单。事实证明,我没有为生产环境添加Grunt依赖项,仅用于我的package.json
中的开发环境。我添加了它们并且完美地工作了。
"dependencies": {
"@sailshq/connect-redis": "^3.2.1",
"@sailshq/lodash": "^3.10.3",
"@sailshq/socket.io-redis": "^5.2.0",
"async": "2.0.1",
"sails": "^1.0.2",
"sails-hook-apianalytics": "^2.0.0",
"sails-hook-organics": "^0.13.0",
"sails-hook-orm": "^2.0.0-16",
"sails-hook-sockets": "^1.4.0",
"sails-postgresql": "^1.0.1",
"grunt": "1.0.1", // I've added these two lines
"sails-hook-grunt": "^3.0.2" // I've added these two lines
},
"devDependencies": {
"@sailshq/eslint": "^4.19.3",
"@sailshq/htmlhint": "^0.9.16",
"@sailshq/lesshint": "^4.6.6",
"grunt": "1.0.1",
"sails-hook-grunt": "^3.0.2"
},