To resolve your compilation issue, ensure that you've installed @types/d3
npm install @types/d3
To resolve the AOT relative paths issue (assuming you're referring to relative template URLs), you should inline your template files as a pre-build step, prior to using rollup
.
For example, to inline your HTML component templates using Gulp and a tool called inlineNg2Template
:
gulp.task('compile:es6', function () {
return gulp.src(['./src/**/*.ts'])
.pipe(inlineNg2Template({ base: '/src', useRelativePaths:true }))
.pipe(tsc({
"target": "es5",
"module": "es6",
"moduleResolution": "node",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"lib": ["es6", "dom"]
}))
.pipe(gulp.dest('./dist/src'));
});
Note: the module
system must be es6
for rollup to work.
Then your rollup
Gulp task can create the UMD, AMD, and CJS bundles:
gulp.task('rollup:module', function() {
return rollup.rollup({
entry: pkg.main,
onwarn: function (warning) {
// Skip certain warnings
// should intercept ... but doesn't in some rollup versions
if (warning.code === 'THIS_IS_UNDEFINED') { return; }
// intercepts in some rollup versions
if ( warning.message.indexOf("The 'this' keyword is equivalent to 'undefined'") > -1 ) { return; }
if ( warning.message.indexOf("treating it as an external dependency") > -1 ) { return; }
if (warning.message.indexOf("No name was provided for external module") > -1) { return; }
// console.warn everything else
console.warn(warning.message);
}
}).then( function ( bundle ) {
bundle.write({
dest: `dist/${pkg.name}.bundle.umd.js`,
format: 'umd',
exports: 'named',
moduleName: pkg.name,
globals: {
}
});
bundle.write({
dest: `dist/${pkg.name}.bundle.cjs.js`,
format: 'cjs',
exports: 'named',
moduleName: pkg.name,
globals: {
}
});
bundle.write({
dest: `dist/${pkg.name}.bundle.amd.js`,
format: 'amd',
exports: 'named',
moduleName: pkg.name,
globals: {
}
});
});
});
Demo Starter App with AOT