You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I’m getting a bit tired of extending our whitelist like in #665.
I think we should have a “catch all” loader that uses file-loader for any unknown extensions.
This makes sense because it’s easy to explain: “if you import something that isn’t JS or CSS, it becomes a part of the build, you get its filename, and can do whatever with it”.
Looking at webpack.config.dev.js, I'm wondering: why use url-loader for audio / video, but file-loader for images? In the scenarios I'm most familiar with, you'd usually do the complete opposite of that: you want essential images, like sprite sheets, to load immediately, but sound and video can wait.
I think this using file-loader for unknown resources is a good default.
@gaearon Any word on this? I wanted to use a php file, to ajax from a form. But I have to manually copy it over after the build process since there's no included loader for php
@iRoachie I think any backend files (like php) should live outside the project folder. The project folder is only meant to be for files related to the front-end client-side app.
How's this similar to PHP? I'm using the php to send and email when the data from the form is posted. The link you provided assumes using Node and using endpoints to access the data.
By similar I meant that, like in that tutorial, you can put client and server code in the different folders, and you can use proxy in development to call /mybackend.php which would get resolved to the specified port. In production, you can have index.php serve built index.html.
This is interesting. We are having the same issue with the angular-cli. In my opinion, regardless of "how" you treat the file (emitted with file-loader into dist, or converted to js, etc), my opinion is that you want it managed by webpack in some way or another.
A catchall unknown-source loader feels like it would be pretty beneficial. I wonder if perhaps leveraging the include property on the loader object to pass a Regex of a folder path like ./assets or w/e.
@fson, @gaearon I can take this if we agree on a few assumptions:
I don't think we should rely on naming conventions. When loading a .png and .svg works, loading a .bmp should really not feel any different to a developer. Instead, I suggest that we load anything in /src that's not already addressed by another loader.
@cesarandreu why not preferring the url-loader with 10k limit for unmatched files?
I don't think there's an explicit "use this loader if no other addresses it", so I'll suggest using a test regex with a negative lookahead. Unfortunately that'll require re-typing all the file extensions handled by other loaders, but it looks like a small price to pay, I can add comments.
While at it, if everyone agrees I'll move all items that are currently handled by file loader to url-loader as well per @cesarandreu suggestion.
Turns out our regex in the Jest moduleNameMapper config didn't work as we had thought, which caused issues when JS files with . in the module name were treated as file resources and stubbed (#1145, #1147).
As a stopgap measure, I reverted the Jest config back to the previous regex which whitelists non-JS/CSS extensions separately, but we still need to find a way to get the same behaviour as our Webpack configuration in Jest.
Maybe @cpojer can help us here? We're trying to create a Jest config that matches this Webpack config:
However, this doesn't work because moduleNameMapper matches the module name, not the absolute file path like Webpack. Because JS files can be imported without specifying the extension, the module name doesn't necessarily end with .js. This caused false positives where imports like import assign from 'lodash.assign' or import a from '../a' were stubbed.
Is it even possible at the moment to replicate this Webpack config in Jest? I think being able to somehow match against the absolute file path would be necessary for that.
Thanks Dan for sharing my messages to you. Yes, the transform field is meant to be used for this. If you guys are building css-jest and scss-jest and all, I'm happy to support this officially in Jest – this was my long term plan so we can also have style information in JS, just like we do in react-native:
Activity
cesarandreu commentedon Sep 18, 2016
Looking at webpack.config.dev.js, I'm wondering: why use url-loader for audio / video, but file-loader for images? In the scenarios I'm most familiar with, you'd usually do the complete opposite of that: you want essential images, like sprite sheets, to load immediately, but sound and video can wait.
I think this using file-loader for unknown resources is a good default.
gaearon commentedon Sep 18, 2016
I didn’t really think it through. If you have better ideas for defaults please submit a PR.
iRoachie commentedon Sep 21, 2016
@gaearon Any word on this? I wanted to use a php file, to ajax from a form. But I have to manually copy it over after the build process since there's no included loader for php
gaearon commentedon Sep 21, 2016
@iRoachie I think any backend files (like php) should live outside the project folder. The project folder is only meant to be for files related to the front-end client-side app.
gaearon commentedon Sep 21, 2016
This is a good example of working with backend APIs. It assumes Node but PHP would work similarly.
iRoachie commentedon Sep 21, 2016
How's this similar to PHP? I'm using the php to send and email when the data from the form is posted. The link you provided assumes using Node and using endpoints to access the data.
gaearon commentedon Sep 21, 2016
By similar I meant that, like in that tutorial, you can put
clientandservercode in the different folders, and you can useproxyin development to call/mybackend.phpwhich would get resolved to the specified port. In production, you can haveindex.phpserve builtindex.html.iRoachie commentedon Sep 21, 2016
@gaearon I messaged you on twitter
TheLarkInn commentedon Oct 7, 2016
This is interesting. We are having the same issue with the angular-cli. In my opinion, regardless of "how" you treat the file (emitted with file-loader into dist, or converted to js, etc), my opinion is that you want it managed by webpack in some way or another.
A catchall unknown-source loader feels like it would be pretty beneficial. I wonder if perhaps leveraging the
includeproperty on the loader object to pass a Regex of a folder path like./assetsor w/e.bebbi commentedon Nov 18, 2016
@fson, @gaearon I can take this if we agree on a few assumptions:
12 remaining items
fson commentedon Nov 22, 2016
Fixed by #1059 & #1077.
fson commentedon Dec 4, 2016
Turns out our regex in the Jest
moduleNameMapperconfig didn't work as we had thought, which caused issues when JS files with.in the module name were treated as file resources and stubbed (#1145, #1147).As a stopgap measure, I reverted the Jest config back to the previous regex which whitelists non-JS/CSS extensions separately, but we still need to find a way to get the same behaviour as our Webpack configuration in Jest.
Maybe @cpojer can help us here? We're trying to create a Jest config that matches this Webpack config:
Files with
.js,.cssand.jsonextensions are handled separately. Everything else is treated as a file – they should be stubbed in Jest.The first attempt was a regex with a negative lookahead like this:
However, this doesn't work because
moduleNameMappermatches the module name, not the absolute file path like Webpack. Because JS files can be imported without specifying the extension, the module name doesn't necessarily end with.js. This caused false positives where imports likeimport assign from 'lodash.assign'orimport a from '../a'were stubbed.Is it even possible at the moment to replicate this Webpack config in Jest? I think being able to somehow match against the absolute file path would be necessary for that.
gaearon commentedon Dec 5, 2016
What @cpojer told me:
cpojer commentedon Dec 5, 2016
Thanks Dan for sharing my messages to you. Yes, the transform field is meant to be used for this. If you guys are building
css-jestandscss-jestand all, I'm happy to support this officially in Jest – this was my long term plan so we can also have style information in JS, just like we do in react-native:etc.