md2
md2 copied to clipboard
Not working with [email protected]
Bug, feature request, or proposal:
After upgrade and some breaking changes in @angular/compiler-cli library can't be build with rollup in AoT mode
What is the expected behavior?
Library works in AoT mode
What is the current behavior?
Errors like
[13:25:25] 'rollup' errored after 6.59 s
[13:25:25] Error: Could not resolve './calendar-body' from aot/tmp/node_modules/md2/datepicker/calendar-body.ngfactory.js
at error (/home/andrew/www/riotgames/live/dashboard/node_modules/rollup/dist/rollup.js:185:14)
at then.resolvedId (/home/andrew/www/riotgames/live/dashboard/node_modules/rollup/dist/rollup.js:18244:8)
at <anonymous>
Because paths in compiled files like ./aot/tmp/node_modules/md2/datepicker/calendar-body.ngfactory.js
are relative ex. import * as i3 from "./calendar-body";
My tsconfig.json is:
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": ".",
"target": "es5",
"module": "es2015",
"moduleResolution": "node",
"sourceMap": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": ["es2015", "dom"],
"removeComments": false,
"noImplicitAny": false,
"suppressImplicitAnyIndexErrors": true,
"allowSyntheticDefaultImports": true,
"outDir": "./aot/tmp",
"typeRoots": [
"./node_modules/@types"
]
},
"include": [
"./src/app/**/*",
"./node_modules/@types/**/*"
],
"files": [
"./src/app/app.module.ts",
"./src/app/boot.aot.ts",
"./src/app/boot.development.ts"
],
"exclude": [
"src/**/*.spec.ts",
],
"angularCompilerOptions": {
"debug": true,
"genDir": "./aot/tmp",
"skipMetadataEmit" : true
}
}
What are the steps to reproduce?
- Create any [email protected] app
- Compile it with ngc
- Try to rollup your app
What is the use-case or motivation for changing an existing behavior?
Which versions of Angular, MD2, OS, browsers are affected?
[email protected] [email protected] [email protected]
My workaround
const fs = require('fs');
const path = require('path');
function ensureJsExt(fn) {
return /\.js$/.test(fn) ? fn : fn + '.js';
}
function md2resolveId(importee, from) {
if (from && (/^\.\/.*/.test(importee) || /^\.\.\/.*/.test(importee))) {
var match = from.match(/^.*(node_modules\/md2\/.*$)/);
if (match) {
var dirTmp = path.dirname(from);
var dirReal = path.dirname(match[1]);
var pathTmp = ensureJsExt(dirTmp + '/' + importee);
var pathReal = ensureJsExt('./' + dirReal + '/' + importee);
return fs.realpathSync(fs.existsSync(pathTmp) ? pathTmp : pathReal);
}
}
return false;
}
rollup({
plugins: [
...
{resolveId: resolveId}
...
]
})