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

Hot reloading text #74

Closed
peteruithoven opened this issue Apr 5, 2016 · 12 comments
Closed

Hot reloading text #74

peteruithoven opened this issue Apr 5, 2016 · 12 comments

Comments

@peteruithoven
Copy link
Contributor

I have a project where I'm loading shader (.glsl) files with the text loader plugin, but changes to these files don't trigger a hot reload.
I've tried creating a simple example, loading a text file using import content from './content.text!text';. The systemjs-hot-reloader code seems to get the change event, but it can't get the module record?
https://github.com/capaj/systemjs-hot-reloader/blob/master/hot-reloader.js#L176
It emits the following error:

Error: module was not found in Systemjs moduleRecords
@happylinks
Copy link

I think this is the same issue as I was having with json files, check out #31
At the end I explained how I fixed that. The key is to not use !text anymore but use meta config.
Not 100% sure though.

@peteruithoven
Copy link
Contributor Author

@happylinks Thanks! You where right. I moved my file to a content folder, removed the !text from the import and added the following config (to config.js):

  packages: {
    "content": {
      meta: {
        '*.text': { loader: 'text' }
      }
    }
  },

This reloads the file and the files that depend on it.

But, people will sometimes try to use !... in imports, would be nice to find a solution to get that working as well.

@capaj
Copy link
Collaborator

capaj commented Apr 5, 2016

@peteruithoven probably wouldn't be bad idea to mention it in the readme somewhere.

npbenjohnson referenced this issue in npbenjohnson/plugin-text Apr 16, 2016
this was disabled pending rollout of systemjs/builder@13ed8f8
@npbenjohnson
Copy link
Contributor

npbenjohnson commented Apr 20, 2016

When that PR goes in, as long as you are using a transpiler (unless the fix the only loading esmodule issue) then 'file.txt!', and any other resource loader that functions by embedding an esmodule will detect changes. I'm pretty sure you have to use the ! notation with nothing following though, hot-reloader does it's own thing with !'s and I think it ends up not figuring out the reference if you put file.txt!text.js

@svi3c
Copy link

svi3c commented May 24, 2016

The hot module reloading does not work for me with html files.
I tried the meta configuration in the jspm.config.js, but when I change a file, it will not be reloaded.
Here is my change which puts the html templates into separate html files: flaviait/ng2-jspm-template@master...ng2-jspm-template-9
Any Idea what's wrong here?

@npbenjohnson
Copy link
Contributor

I've never successfully gotten the meta section to do anything, I'm running under the assumption there's some vague incompatibility, or just features that are lagging between jspm/systemjs/hot-reloader. map: {'html': 'text'} and using the trailing ! notation on html is the only way I've seen it work. If you get meta working I'd love a guide!

@peteruithoven
Copy link
Contributor Author

@svi3c but you're also using the @beta version of jspm / systemjs, maybe it deserves a separate issue? Does this work with the last stable? @npbenjohnson which jspm / systemjs version you use?

@npbenjohnson
Copy link
Contributor

I've only been on the latest minor stable of both. I haven't spent much time trying to get meta working because config related issues seem to generally fail in silent, non-fatal, and mysterious ways.

@svi3c
Copy link

svi3c commented May 25, 2016

@peteruithoven I just created #91 for the jspm 0.17 beta issue.
@npbenjohnson I did not get hmr to work with the !text suffix either. Do you have a reference for a working solution?

@npbenjohnson
Copy link
Contributor

npbenjohnson commented May 25, 2016

Don't put the plugin name after the !, map: {'html': 'text'} and then file.html! resolves to the plugin you have mapped to html. from description here

@svi3c
Copy link

svi3c commented May 26, 2016

Thanks, @npbenjohnson.

Now I tried the following three variants with jspm 0.17 beta:

  1. Specify a loader for *.html files via meta in the configuration
  2. Explicitly import html files with the plugin-text like this: someComponent.component.html!text
  3. Import html file with ! suffix and map html to plugin-text

All variants worked for loading the template via plugin-text, but none of them triggered a hot module replacement when changing the template.

@capaj
Copy link
Collaborator

capaj commented May 26, 2016

@svi3c I have hot reload for templates working with one small issue, which has a simple workaround for now. You can see it in the latest https://github.com/capaj/jspm-ng2 repo with 0.5.9

Workaround is that hot reload must be called on the root file just after initial load. I have mentioned it to @guybedford here: #73 (comment)

hopefully, he'll point us to the right direction of fixing that problem as well.

@peteruithoven so can you test with 0.5.9 release if it works for you? It should be, if not, we can reopen.

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

5 participants