Reputation: 31
I'm building Polymer.dart app that uses Django as a backend. And i want to keep all static files in "/static/" directory, or use cdn server for example. But "pub build" makes relative urls for scripts and other assets. Is there any way to inject absolute prefix for release in url during "pub build"?
UPD: So simplest solution was to make a transformer:
import 'dart:async';
import 'package:barback/barback.dart';
class UrlTransformer extends Transformer {
UrlTransformer.asPlugin();
String get allowedExtensions => '.html';
Future apply(Transform transform) {
return transform.primaryInput.readAsString().then((contents) {
transform.addOutput(new Asset.fromString(
transform.primaryInput.id,
contents.replaceAllMapped(
new RegExp(r'src="([^\{"]+)"'),
(Match m) => "src=\"/static/${m[1]}\"").replaceAll("href=\"", "href=\"/static/")
)
);
});
}
}
But i dont know how to put results of dart2js transformer to apropriate folder. Resulting JS files are in the same directory as *.html now.
I tried to put my transformer after $dart2js in pubspec but it throws errors when pub build
at transformer initialisation step. So i can't make the transformer for that.
Upvotes: 3
Views: 292
Reputation: 657416
There is an open Polymer issue to support this http://dartbug.com/20691
The linked discussion mentions a workaround:
The server could redirect all requests containing [.../]package/...
Upvotes: 0