Skip to content

document rewriting index.html's asset paths in dev #7

@raycohen

Description

@raycohen

To get my built development index.html file to point at my ember server, I had to

npm install --save-dev broccoli-string-replace

then inside ember-cli-build.js

// added to top of file
var replace = require('broccoli-string-replace');

// added before app.toTree()
  app.index = function() {
    var indexTree = EmberApp.prototype.index.call(this);

    if (this.env === 'development') { // asset-rev handles this for staging and production
      // make the js and css urls in the built development index.html
      // file point at the ember server
      var emberDevServerBaseUrl = "http://localhost:4200/";

      indexTree = replace(indexTree, {
        files: [ 'index.html' ],
        patterns: [{
          match: /href="assets\//g,
          replacement: 'href="' + emberDevServerBaseUrl + 'assets/'
        },
        {
          match: /src="assets\//g,
          replacement: 'src="' + emberDevServerBaseUrl + 'assets/'
        }]
      });
    }
    return indexTree;
  };

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions