Skip to content

Instantly share code, notes, and snippets.

@ivanvanderbyl
Last active March 10, 2017 14:54
Show Gist options
  • Save ivanvanderbyl/4b1c2ab7904542aa08f7ef1b83bdb342 to your computer and use it in GitHub Desktop.
Save ivanvanderbyl/4b1c2ab7904542aa08f7ef1b83bdb342 to your computer and use it in GitHub Desktop.
Fix <base> tag in Ember so that SVG patterns and defs work correctly
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>MyApp</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
{{content-for 'head'}}
<link rel="stylesheet" href="@@assets/vendor.css">
<link rel="stylesheet" href="@@assets/my-app.css">
{{content-for 'head-footer'}}
</head>
<body>
{{content-for 'body'}}
<script src="@@assets/vendor.js"></script>
<script src="@@assets/my-app.js"></script>
{{content-for 'body-footer'}}
</body>
</html>
/* global require, module, process */
var EmberApp = require('ember-cli/lib/broccoli/ember-app');
var config = require('./config/environment')(process.env.EMBER_ENV);
module.exports = function(defaults) {
var env = EmberApp.env()|| 'development';
var app = new EmberApp(defaults, {
// Add a leading / to assets so that we can do without a <base> tag.
replace: {
enabled: true,
files: [
'index.html'
],
patterns: [
{
match: "assets",
replacement: config.rootURL + 'assets'
},
],
usePrefix: true
},
});
return app.toTree();
};
  1. Add this to your devDependencies in package.json.
"ember-cli-replace": "^0.3.0",
  1. Add the replace config of ember-cli-build to yours.
  2. Replace baseURL with rootURL in /config/environment.js.
  3. Configure router to use rootURL, as seen in router.js
  4. Update your app/index.html as per app-index.html below, such that you just append @@ in place of assets. This will be used as the replace instruction when compiling. For some reason regex doesn't work as expected.
import Ember from 'ember';
import config from './config/environment';
let Router = Ember.Router.extend({
location: config.locationType,
rootURL: config.rootURL,
});
// ... rest of router.js here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment