Skip to content
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

Template files are not coppied to dist folder #15

Closed
LunicLynx opened this issue Aug 9, 2016 · 19 comments
Closed

Template files are not coppied to dist folder #15

LunicLynx opened this issue Aug 9, 2016 · 19 comments

Comments

@LunicLynx
Copy link

LunicLynx commented Aug 9, 2016

The template files of components are not copied to the dist folder.

It would be possible to create them there directly but this does not seem like a clean solution.

@Component({
    moduleId: module.id,
    templateUrl: require('./abc.html'), // <<-----
})
export class AbcComponent implements OnInit {
@jvandemo
Copy link
Owner

I think, for now, the best approach is to use inline templates for libraries (see https://github.com/valor-software/ng2-bootstrap/blob/development/components/alert/alert.component.ts for an example).

Because Angular 2 recently started using Webpack, another option may be to use a Webpack build process to generate a bundle for production.

Any other thoughts would be appreciated.

@jbrecht
Copy link

jbrecht commented Nov 30, 2016

not the best solution, but I added these scripts in package.json:

    "htmlcopy": "copyfiles src/**/*.html dist",
    "lesscopy": "copyfiles src/**/*.less dist",
    "dist": "npm run tsc && npm run htmlcopy && npm run lesscopy",

which means you must add this to devDependencies:
"copyfiles": "1.0.0"

@jvandemo
Copy link
Owner

jvandemo commented Dec 2, 2016

@jbrecht — Thanks for your input. I will leave this issue open until Angular CLI comes with a recommendation that we can port to this generator.

ptitdam2001 added a commit to ptitdam2001/dsu-google-geolocation that referenced this issue Dec 6, 2016
@jvandemo
Copy link
Owner

As a reference, Angular Material uses Gulp to copy the files over the dist directory: https://github.com/angular/material2/blob/master/tools/gulp/tasks/components.ts

@caroso1222
Copy link
Contributor

caroso1222 commented Feb 27, 2017

Something cool that material does is to inline html and scss files into the generated js components. This way, you'd only be shipping js. Checkout this where the task is initiated, then it calls another gulp task called :inline-resources which, after going through a bunch of functions, gets to this function. It basically replaces all instances of templateUrl with the content of the respective file. Same with styleUrls .scss files.

I found this datepicker library which does the same. You can check out the gulp file here. I pointed out the gulp task which makes the template and style inlining into the component. It's simpler than the material's one to understand, but the idea is the same.

If this makes sense to you, @jvandemo, I can go ahead and take a stab at adding this to the generator so we can include it into the build & publish pipeline.

@jvandemo
Copy link
Owner

jvandemo commented Mar 7, 2017

@caroso1222 — Indeed, we are currently waiting for recommendations by the Angular team on how we can best approach this. Thank you for sharing your thoughts and offering to help. Much appreciated.

For now, I would suggest to only take action when we know what the official recommendation is.

@caroso1222
Copy link
Contributor

Sure, sounds good! Lets wait for the official recommendation then.

@AhsanAyaz
Copy link

I just published my library over npm and found the same issue. Not loading templates . Looks like I'll have to use inline templates for now 😅

@jvandemo
Copy link
Owner

@AhsanAyaz — Inline templates indeed seem to be the way to go (for now). Thank you for your feedback and trying out the generator.

@gilbertogwa
Copy link

The below has some solutions and comments on how to solve this, I tried to replicate but I could not make it work yet. If anyone wants to try it is here:

https://blog.thoughtram.io/angular/2016/06/08/component-relative-paths-in-angular-2.html

Another info: http://blog.mgechev.com/2017/01/21/distributing-an-angular-library-aot-ngc-types/#checklist

@tonkla
Copy link

tonkla commented Mar 19, 2017

Another solution, use asset-loader such as html-loader, sass-loader

@Component({
    selector: 'app-abc',
    template: require('./abc.component.html'),
    styles: [require('./abc.component.scss')]
})
export class AbcComponent implements OnInit {

webpack.conf.js

module: {
  rules: [{
    test: /\.html$/,
    loader: 'html-loader',
    exclude: /node_modules/
  }, {
    test: /\.scss$/,
    loader: 'raw-loader!sass-loader',
    exclude: /node_modules/
  }]
}

This might help, https://github.com/nsmolenskii/ng-demo-lib

@jvandemo
Copy link
Owner

@gilbertowa, @tonkla — Thank you both for the great suggestions! 👍

@BioPhoton
Copy link

BioPhoton commented Apr 6, 2017

So is there a solution beside inline templates? Same for css which is not so nice inlined.
Would be cool to have the html and css in a separate file. :-)

thx Michael

@caroso1222
Copy link
Contributor

@BioPhoton what material currently does is to inline CSS and HTML into the component via gulp in build step. ngconf just announced they will be releasing a guideline on how to properly build ng libraries, so I guess we'll be able to address a lot of issues when this comes out.

@jvandemo
Copy link
Owner

There is an experimental branch with Gulp that should support Mac, Linux and Windows (see #65).

Can any of you please install the Gulp version:

$ npm install -g https://github.com/jvandemo/generator-angular2-library#feat/gulp

After generating a library, you should be able to build your library using:

$ npm run build

or use watch mode to build whenever a file changes in src:

$ npm run build:watch

Templates and styles should now be inlined automatically in the resulting bundle in the dist directory.

Can anyone please verify if everything works as expected on your machine?

Thanks in advance!

@jvandemo
Copy link
Owner

v9.0.0 has been released with automatic inlining of HTML and CSS files.

Feel free to report issues if you experience problems. Thanks!

@abalad
Copy link

abalad commented Sep 19, 2017

@jvandemo It seems that it happened again in the latest versions:

#199

@tonysamperi
Copy link
Contributor

Quote @abalad

@jvandemo
Copy link
Owner

#199 was resolved 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants