问题
I am deploying an Ember CLI app through jenkins and publishing it using nginx. Here is by jenkins build script:
npm install
bower install
node_modules/ember-cli/bin/ember build --environment=production
The nginx configuration simply directs sub.domain.com
to jenkins\jobs\lastStable\archive\dist
. That works fine, but when I go the page, it is blank and the following output in the console:
TypeError: Ember.Handlebars.compile is not a function vendor-92ab6507ac60a5bf7c6819aa8fc418d6.js:18
ReferenceError: Swag is not defined spa-client-9b01c6124f5b2a4cd2e95b62be7f5ba5.js:1
I am guessing that the two errors are related, but I can't figure out what is causing them. I have tried this answer to what appears to be a similar question, but it doesn't work for me. Everything works fine in my dev environment, and I can't see anything suspicious in the Brocfile.js
.
回答1:
Production uses handlebars-runtime which does not include Ember.Handlebars.compile
. The reason is that it's smaller to use that in production and it's more effective to precompile which ember-cli does for you automatically.
Lots of discussion on the PR found here
回答2:
I have same issue with one of third-party libraries I'm using.
I'm using this solution: https://github.com/rwjblue/_____ember-cli-test/commit/1a26911def6f04a4badee94c8a62d8205258867b
My Brocfile.js
diff:
-var app = new EmberApp();
+var app = new EmberApp({
+ vendorFiles: {
+ 'handlebars.js': {
+ production: 'bower_components/handlebars/handlebars.js'
+ }
+ }
+});
回答3:
I encountered this same problem with the bootstrap for ember package. The temporary solution (from GH) was to inlcude the entire handlebars.js file in production:
var fileMover = require('broccoli-file-mover');
var vendorTree = fileMover('vendor', {
files: {
'handlebars/handlebars.js': 'handlebars/handlbars.runtime.js'
}
});
var app = new EmberApp({
vendorFiles: {
'handlebars.js': {
production: 'vendor/handlebars/handlebars.min.js'
}
}
});
来源:https://stackoverflow.com/questions/26250619/ember-cli-fails-in-production