项目作者: seanmorris

项目描述 :
Import raw plaintext into your javascript with a babel macro.
高级语言: JavaScript
项目地址: git://github.com/seanmorris/rawquire.git
创建时间: 2020-09-08T21:24:21Z
项目社区:https://github.com/seanmorris/rawquire

开源协议:Apache License 2.0

下载


rawquire for babel

Import raw plaintext.

Install with npm:

  1. $ npm install babel-plugin-macros --save-dev
  2. $ npm install rawquire --save-dev

Add “macros” to your .babelrc, or preferred babel config:

  1. {
  2. "plugins": ["macros"]
  3. }

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:

  1. import { rawquire } from 'rawquire/rawquire.macro';
  2. const myHtml = rawquire('./hello-world.html');

hello-world.html:

  1. <h1>Hello, world!</h1>

Compiled code:

hello-world.js:

  1. const myHtml = "<h1>Hello, world!</h1>";