Ember CLI fails in production

…衆ロ難τιáo~ 提交于 2019-12-13 15:46:53

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!