ionic-framework icon indicating copy to clipboard operation
ionic-framework copied to clipboard

relative template and style urls in ionic2

Open michaelknoch opened this issue 10 years ago • 11 comments

is there a possibility to use relative template and style urls for ionic2 components when using browserify bundle?

I am running an angular2 web app using CommonJS and module.id in my components. The plan is to reuse these ng2 components in my ionic application, but i was not able to fix the relative/absolute path problem for now.

Anny suggestions?

michaelknoch avatar Jun 15 '16 14:06 michaelknoch

Ionic uses WebPack, which allows us to use require() or import.

Require: (did not work for me because of missing typings which I didn't want to include)

import { Component } from '@angular/core';

@Component({
  selector: 'my-app',
  template: require('./header.component.html'),
  styles: [require('./header.component.css')]
})
export class HeaderComponent implements OnInit {
}

Import:

import { Component } from '@angular/core';

import { Component }  from '@angular/core';
import headerTemplate from './header.component.html';
import headerStyle    from './header.component.css';

@Component({
  selector : 'my-app',
  template : headerTemplate,
  styles   : [headerStyle]
})
export class HeaderComponent implements OnInit {
}

Source: Component-Relative Paths in Angular 2 on ThoughtRam. Thomas Burleson describes how to achieve the ability to use relative paths while using WebPack there.

ghost avatar Jun 17 '16 10:06 ghost

Hello @BenjaminDieter we actually use browserify for Ionic 2 (we used to use Webpack). @michaelknoch i will speak with some of our build team and see if they have an answer for this question. Thanks for using Ionic!

jgw96 avatar Jun 17 '16 14:06 jgw96

I made some experience with https://github.com/ludohenin/gulp-inline-ng2-template. Maybe rendering referenced templateurl and style files inline is a solution @jgw96

https://github.com/driftyco/ionic-gulp-tasks/pull/35

michaelknoch avatar Jun 17 '16 22:06 michaelknoch

Is there a way this could be handled by the @Component's moduleId property instead of inlining the html/css? https://angular.io/docs/ts/latest/api/core/index/ComponentMetadata-class.html#!#moduleId-anchor

natevecc avatar Jun 19 '16 13:06 natevecc

any news about relative paths?

441N143G avatar Jul 06 '16 12:07 441N143G

Hello all, just a heads up that were changing up our build chain to support minification, tree shaking and offline template compilation, so all this will be changing relatively soon. Once that is done I will be revisiting this issue. Thanks everyone!

jgw96 avatar Jul 06 '16 13:07 jgw96

@jgw96 this is a pain that need to be addressed. I would suggest that you guys remove the need of using templateUrl and styleUrls out (as you guys did with selector) and let it handle by the build. So, as long as the app developer keep their html and scss files in the same folder as .ts file, then the build will grab those html and scss and place them in the correct place and add a correct path into app.bundle.js.

example:

Let's say a developer has hello-ionic page in his app and here is the structure of his files

app/
------ pages/
------ ------ hello-ionic/
------ ------ ------ hello-ionic.html
------ ------ ------ hello-ionic.scss
------ ------ ------ another-hello-ionic.scss
------ ------ ------ hello-ionic.ts

and here's need to be added into hello-ionic.ts

import {Component} from '@angular/core';

@Component({
// developer doesn't need to config templateUrl and styleUrls here
})
export class HelloIonicPage {
  constructor() { }
}

vong-srey avatar Jul 07 '16 18:07 vong-srey

Following. Currently, code generated by ionic start has e.g.

@Component({
  templateUrl: 'build/pages/home/home.html'
})

and it's not immediately clear 1. where that build folder comes from; and 2. why it only references home.html and not home.scss. Too much magic going on there.

mirkonasato avatar Jul 20 '16 07:07 mirkonasato

yeap, we realy need normal angular2-style with relative paths 4 this.

441N143G avatar Jul 20 '16 13:07 441N143G

This issue was moved to driftyco/ionic-cli#1196

jgw96 avatar Jul 21 '16 19:07 jgw96

Hello all! I have decided to move this issue to the ionic-cli repo as it is more of a cli/build related issue than a framework issue. Thanks for using Ionic!

jgw96 avatar Jul 21 '16 19:07 jgw96