ludohenin / gulp-inline-ng2-template

Gulp plugin to inline HTML and CSS into Angular 2 component decorators
MIT License
126 stars 26 forks source link

Resolve relative path, not only aside files #65

Open damoncasale opened 8 years ago

damoncasale commented 8 years ago

Templates are supposed to be declared relative to the individual folders that the template files are in, whereas this plugin expects them to be declared relative to the root module. That's wrong, and should be fixed.

And yes, UseRelativePaths is set to false and I'm still seeing that behavior. I looked at the code and there's no possible way for it to properly detect the paths of templates in subfolders, relative to their components.

In getFilePath, absPath simply cannot determine the correct relative path. file.path is always the path of app.module.ts, rather than the path of the related component.

ludohenin commented 8 years ago

If you thing something is wrong you are very much welcome to send a PR.

gregjacobs commented 8 years ago

Yes, this is definitely an issue when using relative html/css paths in components.

For instance, my component looks like this:

// app/my-component/my.component.ts
@Component( {
    selector: 'my-component',
    moduleId: __moduleName,
    templateUrl: './my.component.html',
    styleUrls: [ './my.component.css' ]
} )
export class MyComponent {}

Here, gulp-inline-ng2-template looks for ./my.component.html instead of ./app/my-component/my.component.html

gregjacobs commented 8 years ago

Err, never mind, totally missed the useRelativePaths option. Works as expected!

damoncasale commented 8 years ago

That's odd. useRelativePaths didn't work for me, setting it to either true or false.

gforceg commented 8 years ago

This solved the problem for me too! It seems to me that it would be more intuitive if useRelativePaths was true by default, but now I know to set it when I use this plugin.

unsafePtr commented 7 years ago

How to deal with systemjs and module.id property in angular component? Setting UseRelativePaths doesn't help - base: "/appTS", target: "es5", UseRelativePaths: true,. The plugin does not look at sub-folders and try to find all templates in the base folder.

gregjacobs commented 7 years ago

@unsafePtr Make sure useRelativePaths has a lowercase u

unsafePtr commented 7 years ago

@gregjacobs Thanks. It was source mistake where is written with big U. May be you can help cause it is a very big headache for me.