Transform AngularJS templateUrl relative paths to absolute URLs.
$ npm install babel-plugin-ng-template-url-absolutify --save-dev
Use in either package.json or with gulp:
Add the transform in package.json:
{
"babel": {
"presets": ["env"],
"extensions": [".es6"],
"plugins": [
["babel-plugin-ng-template-url-absolutify", {"baseDir": "./app", "baseUrl": "http://mysite.com/"}]
]
}
}
{
"browserify": {
"transform": [
["babelify", {
"presets": ["env"],
"extensions": [".es6"],
"plugins": [
["babel-plugin-ng-template-url-absolutify", {"baseDir": "./app", "baseUrl": "http://mysite.com/"}]
]
}
]
]
}
}
Add it to the babelify object and specify a baseDir
and baseUrl
.
var gulp = require('gulp'),
browserify = require('browserify');
gulp.task('scripts', function() {
return browserify('./src/app.js')
.transform("babelify", {
presets: ["env"],
extensions: [".es6"],
plugins: [[
"babel-plugin-ng-template-url-absolutify",
{baseDir: "./app", baseUrl: "http://mysite.com/"}
]]
})
.bundle()
.pipe(source('bundle.js'))
.pipe(gulp.dest('./dist'));
});
'use strict';
angular.module('app').component('cmp', {
controller: function () {/* ... */},
templateUrl: './template.html'
});
'use strict';
angular.module('app').component('cmp', {
controller: function () {/* ... */},
templateUrl: 'http://mysite.com/app/template.html'
});