Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mrkou47/raw-module-require-hook
require html,markdown or txt file in Node.js
https://github.com/mrkou47/raw-module-require-hook
hook-script nodejs
Last synced: 15 days ago
JSON representation
require html,markdown or txt file in Node.js
- Host: GitHub
- URL: https://github.com/mrkou47/raw-module-require-hook
- Owner: MrKou47
- License: mit
- Created: 2018-05-25T09:18:15.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-11-25T04:46:30.000Z (about 3 years ago)
- Last Synced: 2024-04-24T04:32:32.026Z (8 months ago)
- Topics: hook-script, nodejs
- Language: JavaScript
- Size: 27.3 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# raw-module-require-hook
[![Build Status](https://travis-ci.org/MrKou47/raw-module-require-hook.svg?branch=master)](https://travis-ci.org/MrKou47/raw-module-require-hook)
require html,markdown or txt file in Node.js
## Install
```sh
npm install raw-module-require-hook
``````sh
yarn add raw-module-require-hook
```## Usage
```js
// index.js
require('raw-module-require-hook')({
extensions: ['html', 'txt'],
});const html = require('../assets/html/test.html'); // your html content
const txt = require('../assets/txt/test.txt'); // your txt content
```## When to use it?
If you building an universal react app, you might want to require raw file in the Node.js, like `import html from '../assets/test.html'` or import markdown file for [react-markdown](https://github.com/rexxars/react-markdown) component.
⚠️ If you want to use both `raw-module-require-hook` and *Typescript*. You shouldn't include your raw file use es module.
**incorrent:**
```ts
import html form '../assets/test.html';import * as html form '../assets/test.html';
```**corrent:**
```ts
const html = require('../assets/test.html');
```Because this hook turn `html` file to `module.exports = 'some html content'`, and `tsc` can not transform this commonjs module currently.