-
Notifications
You must be signed in to change notification settings - Fork 12k
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
Feature Request: Copy assets outside of src folder (e.g. node_modules) #3555
Comments
We also need this to copy a file from node_modules to output folder. |
Same situation here. It would be awesome if angular-cli could merge several sources into joined the public foulders eg.: "assets":[ output is merged in public folders /css and /js. It also would be really handy do specify different targets to avoid naming conflicts eg.
|
There was something similar to @manuelfink's suggestion added for scripts/styles in #3402. Something similar could be added for assets. |
@filipesilva is it available in beta.24 ? if so I can test |
@serhiisol it doesn't exist for assets, just for scripts/styles. |
@filipesilva right, ok, I can try to help with it |
@serhiisol I'd prefer to take this one myself since it requires a few changes throughout parts of the app that I already had to do for other PRs. I might end up consolidating that mechanism. |
What's the latest on this? This would be an amazing feature. |
Any update on this? It's really unfortunate that you manually have to copy the files from npm deps into your own assets directory. Especially given that there is no way to add any custom scripts into the build that could do this automatically. |
@mcgraphix I agree that it's unfortunate that we can't currently configure external assets in angular.cli.json, but you can easily add a custom script to package.json to copy assets. I have this one added to copy the svg file from Octicons:
(Use a module like eg. copyfiles if you want cross-platform copy.) If you launch your project with I currently only use it for that one file, but you could do the same for all of your external assets until a better solution is implemented. |
Looks like you can use explicit file-loader calls!
I'm still hacking on it |
Fix angular#3555 BREAKING CHANGE: 'assets' as a string in angular-cli.json is no longer allowed, use an array instead.
I just wanted to thank @filipesilva for getting this feature in. Thanks man! |
@jeffaxial glad you're finding it useful! |
Thanks, @filipesilva! If I understand the documentation right, I have to configure something like
for my own use-case if I want to have the Octicons svg files available both during development and in the production build. Is that right? |
@fleskesvor that sounds mostly right, except |
@filipesilva Yes, you're absolutely right, of course. The reason why that appeared to be working must have been that I had already built my project using the correct syntax. On a new project with angular-cli up to date (v. 1.0.0-rc.1), this configuration works:
Both during development and an AoT build. |
Fix angular#3555 Close angular#4691 BREAKING CHANGE: 'assets' as a string in angular-cli.json is no longer allowed, use an array instead.
I tried that option '{ "glob": "**/*", "input": "../../foo", "output": "_artifacts/foo"' then ran "ng build" and it doesn't do anything. |
@fletchsod-developer It's working for me in version 1.0.0-rc.1. Which version are you on, and are you 100% sure of that input path? |
@filipesilva I am using @angular/cli: 1.0.4 But it does not copy anything. |
The idea of this feature is great, but it seems that this solution doesn't work for the development environment at all. I would like to use this feature to include CSS from a node_modules directory, but if I'm unable to access the files while developing the app this doesn't seem to be the way to solve that problem. So am I missing something here or is this feature just for show? |
Honestly, it's a little bit rude to assume they've spent time on a feature that only looks like it works. I'm using it locally while developing my app as well in a production environment, and it works great. Here is how I am using it: In .angular-cli.json: Do note that you need to restart ng serve after adding the line. All I can say is that I have this working on several projects, and it works just as advertised. |
Yep, as noted by me just a few comments up, I also have it working both in development and production. |
But, I am facing the problem. Error is like the following: I provided the option using glob to copy assets but it does not copy it. It seems styles processing happens before copy and it tries to reference the fonts and images so it just fails and could not copy (Just a guess). |
@filipesilva Work like a charm! Thanks for putting in the work. I almost pull in Gulp to copy a few files from node_modules. @rajramo61 for stylesheets, if you use SASS/LESS, you can use the import statement without having to copy them over. Also, can you post your "apps" section in .angular-cli.json for further troubleshooting? |
@hieunt88 Here is the app section. style.scss has This modern is again combination of multiple scss files which are pre-build and I need to use them. This variable is utilized in many places for the path for fonts. Like I tried to override this variable $font-path but could not make it work. |
@rajramo61 this is my script to copy external fonts. { "glob": "**/*", "input": "../node_modules/font-awesome/fonts", "output": "./assets/fonts/" } For Also, you need to drop $font-path: 'assets/fonts/' For SASS, I believe the problem is not with Angular CLI referencing external .scss. The build most likely broke because of the asset path issue above. Try the setting below. "stylePreprocessorOptions": {
"includePaths": [
"../node_modules/path/to/modern/scss"
]
} Then, in your $font-path: 'assets/fonts/'
@import 'modern'; |
That doesn't seem to work with JSON files (to use with "assets": [
"assets",
"favicon.ico",
{ "glob": "**/*", "input": "../node_modules/angular-slickgrid/i18n", "output": "./assets/i18n/" },
{ "glob": "*", "input": "../node_modules/angular-slickgrid/i18n", "output": "./assets/i18n/" },
{ "glob": "*/", "input": "../node_modules/angular-slickgrid/i18n", "output": "./assets/i18n/" },
{ "glob": "**/*", "input": "../node_modules/angular-slickgrid/i18n", "output": "./assets/i18n" }
], Would that work with JSON files or is that a restricted file type? |
As @ghiscoding mentioned above, looks like it doesn't work with JSON files. |
@ghiscoding Have you tried with:
|
This does not appear to work with
It will work fine with |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
So this is a feature request for ability to copy assets from different folders of the project, e.g.
node_modules
etc. Currently it doesn't seem to be supported even if you'll specify this:angular-cli.json
It's actually common use case, when you need to copy assets from third-party modules from
node_modules
Below you can see additional information about cli and steps to reproduce:
OS?
Versions.
Repro steps.
Stack trace
you won't see any stack trace, all good, but file won't be copied
Mention any other details that might be useful.
What if you want to include assets from node_modules, which seems like a fairly common use case
The text was updated successfully, but these errors were encountered: