https://github.com/seanmorris/rawquire
Import raw plaintext into your javascript with a babel macro.
https://github.com/seanmorris/rawquire
babel-plugin-macros
Last synced: 3 months ago
JSON representation
Import raw plaintext into your javascript with a babel macro.
- Host: GitHub
- URL: https://github.com/seanmorris/rawquire
- Owner: seanmorris
- License: apache-2.0
- Created: 2020-09-08T21:24:21.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-09-09T02:39:15.000Z (over 3 years ago)
- Last Synced: 2024-05-02T04:32:21.044Z (about 1 year ago)
- Topics: babel-plugin-macros
- Language: JavaScript
- Homepage:
- Size: 24.4 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rawquire for babel
Import raw plaintext.
## Install with npm:
```sh
$ npm install babel-plugin-macros --save-dev
$ npm install rawquire --save-dev
```## Add "macros" to your `.babelrc`, or preferred babel config:
```json
{
"plugins": ["macros"]
}
```## Import raw text into your javascript:
Call `rawquire` with a file path relative to the current script in the source tree.
Any `rawquire` function calls will be replaced with a string literal containing the text from the file.
### Source code:
`hello-world.js`:
```javascript
import { rawquire } from 'rawquire/rawquire.macro';const myHtml = rawquire('./hello-world.html');
```
`hello-world.html`:
```htmlHello, world!
```### Compiled code:
`hello-world.js`:
```javascript
const myHtml = "Hello, world!
";
```