我尝试将我的应用部署到heroku。一切似乎都起作用,节点包正在安装,但是然后grunt无法解析'require('angular')'。
我怀疑变换的东西是失败的,因此角度的路径未知?
或者我是否需要专门为package.json添加角度?我很困惑它在本地工作。
Running "browserify:dist" (browserify) task
>> Error: ENOENT, open '/tmp/build_001656dd-4d72-40f4-b89a-b6bb75190d23/bower_components/angular/angular.js' while resolving "angular" from file /tmp/build_001656dd-4d72-40f4-b89a-b6bb75190d23/sections/_default/angular-app.js
Warning: Error running grunt-browserify. Use --force to continue.
Aborted due to warnings.
! Push rejected, failed to compile Node.js app
我的gruntfile:
/* jslint node: true */
'use strict';
module.exports = function (grunt) {
var transformify = require('transformify');
var requires = require('./sections/_default/browser-requires.js')();
var addRequires = transformify(function (x) {
return x.replace('/* modules browserify */', requires);
});
// Project configuration.
grunt.initConfig({
pkg : grunt.file.readJSON('package.json'),
jshint : {
all : [ 'Gruntfile.js', 'index.js', 'sections/**/*.js' ]
},
browserify: {
dist: {
files: {
'static/js/app.js': ['sections/_default/angular-app.js']
},
options: {
transform: [ addRequires, 'browserify-shim']
}
}
},
uglify : {
target : {
files : { 'static/js/app.min.js' : 'static/js/app.js' }
},
options: {
mangle: false
}
},
clean : [ 'static/js/app.js' ]
});
grunt.loadNpmTasks('grunt-browserify');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-clean');
// Default task(s).
grunt.registerTask('default', [
'jshint',
'browserify',
'uglify',
'clean'
]
);
grunt.registerTask('heroku', [
'jshint',
'browserify',
'uglify',
'clean'
]
);
};
下面是我的package.json:
{
"name": "developdavid",
"version": "0.0.0-7",
"main": "index.js",
"dependencies": {
"express": "~3.2.6",
"jade": "~0.31.2",
"di": "0.0.1",
"transformify": "~0.1.2",
"express-less": "0.0.2",
"browserify": "~3.28.1",
"browserify-shim": "^3.3.1",
"mongodb": "*",
"monk": "*",
"grunt": "~0.4.2",
"grunt-contrib-jshint": "~0.6.3",
"grunt-browserify": "^1.3.1",
"grunt-contrib-uglify": "^0.4.0",
"grunt-contrib-clean": "^0.5.0"
},
"scripts": {
"test": "grunt",
"start": "node index.js"
},
"browser": {
"jquery": "./bower_components/jquery/dist/jquery.js",
"angular": "./bower_components/angular/angular.js",
"bootstrap": "./bower_components/bootstrap/dist/js/bootstrap.js",
"angular-resource": "./bower_components/angular-resource/angular-resource.js",
"angular-route": "./bower_components/angular-route/angular-route.js",
"angular-bootstrap": "./bower_components/angular-bootstrap/ui-bootstrap-tpls.js",
"angular-animate": "./bower_components/angular-animate/angular-animate.js",
"angular-sanitize": "./bower_components/textAngular/src/textAngular-sanitize.js",
"text-angular-setup": "./bower_components/textAngular/src/textAngularSetup.js",
"text-angular": "./bower_components/textAngular/src/textAngular.js"
},
"browserify-shim": {
"jquery": "$",
"angular": {
"exports": "angular",
"depends": [
"jquery:$"
]
},
"text-angular-setup": {
"depends": [
"angular:angular"
]
},
"text-angular": {
"depends": [
"angular:angular"
]
},
"angular-sanitize": {
"depends": [
"angular:angular"
]
},
"angular-bootstrap": {
"depends": [
"angular:angular"
]
},
"angular-animate": {
"depends": [
"angular:angular"
]
},
"angular-resource": {
"depends": [
"angular:angular"
]
},
"angular-route": {
"depends": [
"angular:angular"
]
},
"bootstrap": {
"depends": [
"jquery:$"
]
}
},
"devDependencies": {
"grunt": "~0.4.2",
"grunt-contrib-jshint": "~0.6.3",
"grunt-browserify": "^1.3.1",
"grunt-contrib-uglify": "^0.4.0",
"grunt-contrib-clean": "^0.5.0"
},
"subdomain": "developDavid",
"engines": {
"node": "0.10.x"
}
}
grunt文件使用的'browser-requires':
/* jslint node: true */
'use strict';
var fs = require('fs');
module.exports = function () {
var requires = [];
fs.readdirSync('./sections/').forEach(function (file) {
var fullpath = './sections/' + file,
isDirectory = fs.lstatSync(fullpath).isDirectory();
if (isDirectory && file !== '_default') {
var dir = file;
fs.readdirSync('./sections/' + dir).forEach(function (file) {
if (/.*\.browser.js$/.test(file)) {
requires.push('injector.invoke(require(\'../' + dir + '/' + file + '\'));');
}
});
}
});
return requires.join('');
};
答案 0 :(得分:0)
丑陋的修复:
刚刚在提交中添加了bower_components,然后在heroku上找到了所有文件。也许他们将凉亭组件安装在不同的文件夹或其他东西...... 在那种情况下,我现在应该有两个。