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

Add raw-loader to webpack rules. #1938

Closed
wants to merge 2 commits into from

Conversation

aaronplanell
Copy link

I added the raw-loader to webpack for txt files.
It will be useful for reading markdown files and print their content inside a component.

@facebook-github-bot
Copy link

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at [email protected]. Thanks!

If you are contributing on behalf of someone else (eg your employer): the individual CLA is not sufficient - use https://developers.facebook.com/opensource/cla?type=company instead. Contact [email protected] if you have any questions.

@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@viankakrisna
Copy link
Contributor

Why not use .md extension? Isn't it the default extension for markdown?

@aaronplanell
Copy link
Author

Mmmm... I think you're all right @viankakrisna . Maybe I could put both (txt is useful for other purposes).
What do you think about it?

@viankakrisna
Copy link
Contributor

Personally I think this functionality can be done by fetching the *.md / *.txt files from public folder, but it would mean that the code would be async rather than using webpack's loader to read the files on requires/import, I think this has been discussed before in #1304

@aaronplanell
Copy link
Author

Hello,

Ummm... But if you want to publish your README.md file inside an About component, for instance, you couldn't because it will be in the root folder. In my humble opinion, I think this loader will be useful for the community in many different ways.

If you want, I can add the Markdown extension too in a new commit. Or I can Close and comment this PR. Whatever you want @viankakrisna .

Best regards from Barcelona!

@viankakrisna
Copy link
Contributor

viankakrisna commented Apr 6, 2017

Well, i'm not the maintainer, so it's not up to me :D Just a curious stargazer.

They also don't recommend imports from outside src, so i think it's not something they consider. I agree it could be beneficial, but there are pros and cons of adding feature as stated in #1304. Right now i think it's better to just use fetch or whatever to read .md files :)

@Timer
Copy link
Contributor

Timer commented Apr 7, 2017

I do not believe we will merge this as-is but I believe it's worth keeping open for now so that we address this by the time 0.10 is released.
I'll tag this so it doesn't slip through the cracks.

Unfortunately, any changes like this are considered breaking, so I'd rather explore a different option which enables this in a more generic way (since I'm sure there will be requests for other things).

Something along the lines of browserify's brfs, maybe (e.g. fs.readFileSync inlining).

@Timer Timer added this to the 0.10.0 milestone Apr 7, 2017
@Timer Timer mentioned this pull request Apr 7, 2017
@gaearon
Copy link
Contributor

gaearon commented Apr 7, 2017

It will be useful for reading markdown files and print their content inside a component.

What is your use case for this? Why not use regular JS files with template literals?

export default `
  lalalala
  lalalala
`;

@aaronplanell
Copy link
Author

Hello @gaearon !!!

It will be useful for avoiding duplicities. For instance, I need printing the README.md file inside a component of React. Every time that I, or another mate, make a change in this file this component will be automatically updated. And a MD file doesn't have export by default.

I thought it was an interesting plugin of webpack to include, but maybe I'm wrong.

@gaearon
Copy link
Contributor

gaearon commented Apr 7, 2017

I think we won’t be adding this for now.

CRA is meant for apps and doesn’t really work well for component libraries right now. The use case you are suggesting sounds more like a component library. I think nwb supports that use case better, so I encourage you to take a look at it.

We might support component libraries in the future. When we do, it will be a good time to add support for this (and Markdown files).

@gaearon gaearon closed this Apr 7, 2017
@aaronplanell
Copy link
Author

Okay! Don't worry about it @gaearon . I thought it will be a useful plugin for the community.
Maybe next time.

Best regards!

@gre
Copy link

gre commented Jul 1, 2017

That would be neat to have this support..
my app is a cookbook with examples ( gl-react-cookbook.surge.sh ) and I want to show the source code of each example.. I used to be able to do require("!raw!./" + name + "/index.js") in react-scripts @ 0.9.5 but now support of this seems gone! not sure about the reason of that regression?

my current workaround is a script that will copy all the index.js into a index.source.js and that do

module.exports=`...source_code_that_escape_some_characters`

but it's an ugly workaround ( https://github.com/gre/gl-react/blob/bc4612c597b9b2c7431eeb1486609bb6cd4a0552/packages/cookbook/src/examples/gen.sh )

@gaearon
Copy link
Contributor

gaearon commented Jul 1, 2017

@gre I understand that, but we don’t support this use case (cookbooks, library examples etc) very well right now. It would be nice to do comprehensively at some point, but I don’t want to dilute the focus until features important for apps are all done (and they’re not).

@lock lock bot locked and limited conversation to collaborators Jan 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants