Ina*_*mus 47 heroku node.js gulp
我正在使用gulp以及gulp-minify-css,gulp-uglify等gulp插件(我的应用程序列为npm依赖项).
此外,我不提交npm_modules文件夹和公共文件夹,其中所有生成的文件都是.在部署和设置我的服务器之后,我无法弄清楚如何构建我的应用程序(我有gulp构建命令)(它已经在寻找公共文件夹).
在上传之前提交我似乎是一个坏主意.也许有一些温和的决定......有什么想法吗?
arb*_*arb 59
我可以通过将其添加到我的"package.json"文件中来实现此功能:
"scripts": {
"start": "node app",
"postinstall": "gulp default"
}
Run Code Online (Sandbox Code Playgroud)
该postinstall脚本在构建包之后运行.请查看此以获取更多信息.唯一令人烦恼的是,所有的依赖都必须存在于"依赖"之下,而不是单独的"devDependencies"
我不需要对buildpacks或配置做任何其他事情.这似乎是最简单的方法.
我写了关于我在这里使用的过程
小智 15
你能行的!
有一些关键措施帮助了我:
heroku config:set NODE_ENV=production - 将您的环境设置为'生产'heroku config:set BUILDPACK_URL=https://github.com/krry/heroku-buildpack-nodejs-gulp-bower - 启用定制的Heroku buildpack.我加入了一些元素来制作一个适合我的元素.一个gulp名为heroku:production执行NODE_ENV ===生产时需要在heroku服务器上执行的构建任务的任务.这是我的:
var gulp = require('gulp')
var runSeq = require('run-sequence')
gulp.task('heroku:production', function(){
runSeq('clean', 'build', 'minify')
})
Run Code Online (Sandbox Code Playgroud)
clean,build和minify是的,当然不同的gulp是做魔术gulpage任务
如果您的申请存在/app.js,请:
(A)Procfile在仅包含:web: node app.js,或的项目根目录中创建一个
(B)为您的package.json:添加一个启动脚本:
"name": "gulp-node-app-name",
"version": "10.0.4",
"scripts": {
"start": "node app.js"
},
Run Code Online (Sandbox Code Playgroud)npm install --productionluc*_*uda 11
我找到的最简单的方法是:
设置gulp在package.json脚本区域:
"scripts": {
"build": "gulp",
"start": "node app.js"
}
Run Code Online (Sandbox Code Playgroud)
Heroku将在启动应用程序之前运行构建.
包括gulpdependencies而不是devDevependencies,否则Heroku将无法找到它.
Heroku开发中心有关于它的更多相关信息:Node.js开发的最佳实践
// gulpfile.js
var gulp = require('gulp');
var del = require('del');
var push = require('git-push');
var argv = require('minimist')(process.argv.slice(2));
gulp.task('clean', del.bind(null, ['build/*', '!build/.git'], {dot: true}));
gulp.task('build', ['clean'], function() {
// TODO: Build website from source files into the `./build` folder
});
gulp.task('deploy', function(cb) {
var remote = argv.production ?
{name: 'production', url: 'https://github.com/<org>/site.com', branch: 'gh-pages'},
{name: 'test', url: 'https://github.com/<org>/test.site.com', branch: 'gh-pages'};
push('./build', remote, cb);
});
Run Code Online (Sandbox Code Playgroud)
$ gulp build --release
$ gulp deploy --production
Run Code Online (Sandbox Code Playgroud)
tools/deploy.js)Heroku提供了一个特定的启动脚本;
"scripts": {
"start": "nodemon app.js",
"heroku-postbuild": "gulp"
}
Run Code Online (Sandbox Code Playgroud)
请注意,在你的gulpfile.js(gulpfile.babel.js,如果你认为你的gulp构建过程),你应该有一个任务名称默认值,它将在通过Heroku安装依赖项后自动运行.
https://devcenter.heroku.com/articles/nodejs-support#heroku-specific-build-steps