// .babelrc
{
"presets": [
"env",
"react"
],
"plugins": [
"transform-object-rest-spread",
["transform-class-properties", { "spec": true }]
]
}
import mardownContent from '../contents/help.md';
console.log(mardownContent); // `# Title \n Paragraph`
import mardownContent from '../contents/help.md';
console.log(mardownContent); // 12d7fdaf521be8a4e6ac363931673970.md
Allow this natively or make it a plugin?
Isolating content from code seems like a fair idea.
| Software | Version(s) |
| ---------------- | ---------- |
| Parcel | ^1.4.1 |
| Node | v8.0.0 |
| npm/Yarn | 5.0.0 |
| Operating System | Linux |
I think this should be part of the Parcel core.
This is a great issue for for anyone new to Parcel looking for contribute. Just create a new MarkdownAsset that spits out the markdown without any transforms.
Hi David,
Thanks for reaching. I could have a look at this eventually. Let's clarify a bit first:
Best
There is a plugin https://github.com/jaywcjlove/parcel-plugin-markdown-string :arrow_up:
You can also natively read the raw content of any file using fs.readFileSync, Parcel will parse it. This keeps your code unopinionated and compatible with Node.js :
import {readFileSync} from 'fs'
const mardownContent = readFileSync(__dirname + '../contents/help.md', 'utf-8')
@fathyb I hardly see how this can work. We are talking about importing it at build time in the bundle. Once bundled, readFileSync won't be available in the browser.
Or did I miss something?
@augnustin Parcel will parse readFileSync at build time and replace it with the contents of your file. You won't have any fs calls in the final bundle/in the browser.
Previous discussion here: https://github.com/parcel-bundler/parcel/pull/1160
@fathyb That's a cool idea and it's awesome that it works in Parcel. Is there any way to make this work in rollup as well?
Is this still considered an issue? Looks to me like parcel already supports the use-case, albeit maybe missing a clear documentation?
Closing this, feel free to reopen if needed
Most helpful comment
@augnustin Parcel will parse
readFileSyncat build time and replace it with the contents of your file. You won't have anyfscalls in the final bundle/in the browser.