将 Sails 应用程序部署到 Heroku 时找不到资产
Assets not found when deploying Sails app to Heroku
我是 Sails 的新手。
我已经从 Sails 模板创建了一个新的网络应用程序并尝试将其上传到 Heroku。一切都很好,除了资产,none 的资产被发现(js、css、图像等)。
我发现 Sails 使用 Grunt 将文件复制到 .tmp 文件夹。我已经检查并将 Grunt 添加到我的 package.json
文件中。我还添加了一个带有 web: node app.js
命令和 NODE_ENV
变量的 Procfile,它指向 Heroku 中的 production
。
我没有更改任何 Grunt 任务,Gruntfile.js
文件和 /tasks
目录是默认的。
还有什么我可以检查的想法吗?
解决方案非常简单。原来我没有为生产环境添加 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"
},
我通过不同的方式解决了这个问题。除了在 OP 的答案中包含一些 grunt
之外,我还在 package.json
:
的脚本部分添加了 postinstall
"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
)
我是 Sails 的新手。
我已经从 Sails 模板创建了一个新的网络应用程序并尝试将其上传到 Heroku。一切都很好,除了资产,none 的资产被发现(js、css、图像等)。
我发现 Sails 使用 Grunt 将文件复制到 .tmp 文件夹。我已经检查并将 Grunt 添加到我的 package.json
文件中。我还添加了一个带有 web: node app.js
命令和 NODE_ENV
变量的 Procfile,它指向 Heroku 中的 production
。
我没有更改任何 Grunt 任务,Gruntfile.js
文件和 /tasks
目录是默认的。
还有什么我可以检查的想法吗?
解决方案非常简单。原来我没有为生产环境添加 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"
},
我通过不同的方式解决了这个问题。除了在 OP 的答案中包含一些 grunt
之外,我还在 package.json
:
postinstall
"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
)