Skip to content

Support inlining of css and html resources #296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jelbourn opened this issue Mar 12, 2016 · 19 comments · Fixed by #497
Closed

Support inlining of css and html resources #296

jelbourn opened this issue Mar 12, 2016 · 19 comments · Fixed by #497
Labels
effort2: medium (days) P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@jelbourn
Copy link
Member

The CLI should support swapping out templateUrl and styleUrls with the inlined template and styles, respectively. This will facilitate the publishing of components (such as material2).

There is currently a gulp plugin that does this already. The actual inlining logic is all contained in one module while the gulp-specific parts are in another.

The inlining needs to at least occur after other build steps run for any tools that may output css or html. The material2 source, for example, uses scss to generate the css files that should be inlined into the components.

The pending Angular offline template compiler actually won't cover this use case, as the person running the template compiler is the end application, not the component library.

cc @hansl

@jimitndiaye
Copy link
Contributor

This is indeed needed. Currently I like many others use webpack to require template html files so they get inlined. Would be great if this was supported out of the box.

@filipesilva
Copy link
Contributor

Hm, though cookie. Perhaps this should be part of the bundling functionality.

Also cc @cironunes who was working on prod builds.

@hansl
Copy link
Contributor

hansl commented Mar 17, 2016

this should be prod build only anyway. Assigning to @cironunes to fix.

@cironunes cironunes self-assigned this Mar 25, 2016
Brocco added a commit to Brocco/angular-cli that referenced this issue Apr 22, 2016
Inline templates via "--inline-template" or "-it"
Inline steyles via "--inline-style" or "-is"
Fixes angular#296
Fixes angular#349
Brocco added a commit to Brocco/angular-cli that referenced this issue Apr 22, 2016
Inline templates via "--inline-template" or "-it"
Inline steyles via "--inline-style" or "-is"
Fixes angular#296
Fixes angular#349
Brocco added a commit to Brocco/angular-cli that referenced this issue Apr 22, 2016
Inline templates via "--inline-template" or "-it"
Inline styles via "--inline-style" or "-is"
Fixes angular#296
Fixes angular#349
@jelbourn
Copy link
Member Author

@Brocco your PR looks like it's just for generating components. This issue was about inlining the contents of separate files at build time.

@cironunes cironunes reopened this Apr 22, 2016
@Brocco
Copy link
Contributor

Brocco commented Apr 22, 2016

@jelbourn you are correct, I apologize. This will be handled when the idea of offline template compilation gets added the CLI.

@randyaa
Copy link

randyaa commented Apr 22, 2016

Related to this, when developing locally and using ng serve how do we properly reference the templates? It seems to want to load them relative to the root of the project?

@justindujardin
Copy link

@randyaa use moduleId in your Component decorator:

import {Component} from '@angular/core';
@Component({
  moduleId: module.id,
  selector: 'awesome-component',
  templateUrl: 'awesome.component.html',
  styleUrls: ['awesome.component.css']
})
export class AwesomeComponent {}

@randyaa
Copy link

randyaa commented May 27, 2016

any update on this? would be nice to see soon.

@filipesilva filipesilva added the P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent label Jun 4, 2016
@adamduren
Copy link

@filipesilva Is this the issue to follow for offline template compiler and tree shaking to get build sizes shown at ng-conf or is there a better one to follow?

@adamduren
Copy link

This one also seems to be closely related. angular/angular#6612

@jelbourn
Copy link
Member Author

This is a completely different issue than offline-compiler support (which resides in angular/angular). Inline resources is something that would be done for Angular component libraries which are then consumed into application and compiled as one unit.

@pablodenadai
Copy link

@jimitndiaye would you have more info on how to implement webpack with Angular CLI so I can require the templates?

@jimitndiaye
Copy link
Contributor

@ghpabs I only use angular-cli for the scaffolding (ng generate...). So I only added the minimum necessary to get that to work. The project is based on angular2 webpack starter with minimum config added to enable angular-cli to work.
That webpack template allows in-lining html, css, etc.

@filipesilva
Copy link
Contributor

Inlining of CSS and HTML added in #1455.

@madaraszistvan
Copy link

How can I configure it?

@filipesilva
Copy link
Contributor

@madaraszistvan it happens automatically, there is no configuration for it. Are you having problems with it?

@madaraszistvan
Copy link

madaraszistvan commented Jan 13, 2017

I see, the css and html is in the main.bundle.js. And the styles.bundle.css is containing the global styles. Thank you.

@efreethy
Copy link

efreethy commented Apr 13, 2017

@filipesilva By support for inline templates, we are asking for an option that triggers a transformation layer before compilation. Namely a layer that will turn all templateUrl attrs into template attrs that point to the fetched html template strings.

The lack of this tooling is the primary reason why this library: https://www.npmjs.com/package/gulp-inline-ng2-template is getting ~30,000 downloads a month.

It is the only sensible way to prepare an angular2 package to be properly pulled in from npm (relative paths fail!)

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
effort2: medium (days) P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Projects
None yet
Development

Successfully merging a pull request may close this issue.