I\'m building an Angular (2+) component library using jvandemo/generator-angular2-library as a starter, which uses Rollup as a module builder. The component I am creating in
In the sample directive I had no problem compiling when I used the following:
import { Directive, ElementRef } from '@angular/core';
import * as moment from '../node_modules/moment/moment';
@Directive({
selector: '[sampleDirective]'
})
export class SampleDirective {
constructor(private el: ElementRef) {
moment.isDate('test');
}
}
The files are compiled from a build directory that is a sub-dir off the root. You do get a further warn about "this", mentioned here:
https://github.com/rollup/rollup/issues/794
I need to say in the gulfile that the library is external:
external: [
'@angular/core',
'@angular/common',
'moment'
],
And from the github link, you should add a onwarn block to both rollup sections: That is section 'rollup:umd' and 'rollup:fesm'
onwarn: function(warning) {
// Skip certain warnings
// should intercept ... but doesn't in some rollup versions
if ( warning.code === 'THIS_IS_UNDEFINED' ) { return; }
// console.warn everything else
console.warn( warning.message );
},
Does that get you any further?