All Projects → pveyes → Raw.macro

pveyes / Raw.macro

Licence: mit
Read file contents at build time via babel-plugin-macros. webpack-less raw-loader

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Raw.macro

Frontie Webpack
Front-end Boilerplate | Gulp 4 + Webpack 4 + Babel + ITCSS Architecture + BEM Methodology + Twig.js
Stars: ✭ 102 (-11.3%)
Mutual labels:  webpack, babel
Universal React Redux
🧐 A sensible universal starter kit for React + Redux
Stars: ✭ 112 (-2.61%)
Mutual labels:  webpack, babel
Koa Mobx React Starter
A straightforward starter for Node javascript web projects. Using Koa, MobX and ReactJS (with universal / isomorphic server rendering)
Stars: ✭ 102 (-11.3%)
Mutual labels:  webpack, babel
Nodefony Starter
Nodefony Starter Node.js Framework
Stars: ✭ 95 (-17.39%)
Mutual labels:  webpack, babel
Lecture Frontend Dev Env
"[인프런] 프론트엔드 개발환경의 이해와 실습" 강의 실습 자료입니다.
Stars: ✭ 108 (-6.09%)
Mutual labels:  webpack, babel
React From Scratch
Building a Modern React App from Scratch in 2021
Stars: ✭ 87 (-24.35%)
Mutual labels:  webpack, babel
Webpack Seed
🚀 A Multi-Page Application base on webpack and babel. webpack搭建基于ES6,支持模板的多页面项目
Stars: ✭ 113 (-1.74%)
Mutual labels:  webpack, babel
React Boilerplate
This project is deprecated. Please use CRA instead.
Stars: ✭ 88 (-23.48%)
Mutual labels:  webpack, babel
React Start Kit
A boilerplate of SPA, built with React.js, Webpack, ES6+, Redux, Router, Babel, Express, Ant Design...
Stars: ✭ 107 (-6.96%)
Mutual labels:  webpack, babel
Angular Es6
Angular ES6 utility library. Write directives, controllers and services as ES6 classes.
Stars: ✭ 103 (-10.43%)
Mutual labels:  webpack, babel
Webpack Core Usage
webpack2完整系列课程,欢迎阅读。同时欢迎移步我的react全家桶文章全集: https://github.com/liangklfangl/react-article-bucket
Stars: ✭ 94 (-18.26%)
Mutual labels:  webpack, babel
React Workshop
⚒ 🚧 This is a workshop for learning how to build React Applications
Stars: ✭ 114 (-0.87%)
Mutual labels:  webpack, babel
Awesome Coding Javascript
📌 持续构建个人的源码库(JavaScript 原生、常用库、数据结构、算法)
Stars: ✭ 88 (-23.48%)
Mutual labels:  webpack, babel
Wordless
All the power of Pug, Sass, Coffeescript and WebPack in your WordPress theme. Stop writing themes like it's 1998.
Stars: ✭ 1,374 (+1094.78%)
Mutual labels:  webpack, babel
Award
⚙基于react的服务端渲染框架
Stars: ✭ 91 (-20.87%)
Mutual labels:  webpack, babel
Babel Plugin Prismjs
A babel plugin to use PrismJS with standard bundlers.
Stars: ✭ 114 (-0.87%)
Mutual labels:  webpack, babel
Compiled
A familiar and performant compile time CSS-in-JS library for React.
Stars: ✭ 1,235 (+973.91%)
Mutual labels:  webpack, babel
Cookiecutter Webpack
Boilerplate for webpack 2, babel, react + redux + hmr, and karma. Can be inserted into existing django projects.
Stars: ✭ 87 (-24.35%)
Mutual labels:  webpack, babel
React Bootstrap Webpack Starter
ReactJS 16.4 + new React Context API +react Router 4 + webpack 4 + babel 7+ hot Reload + Bootstrap 4 + styled-components
Stars: ✭ 103 (-10.43%)
Mutual labels:  webpack, babel
React Starter
A basic template that consists of the essential elements that are required to start building a React (v16.3) application using Webpack (v4)
Stars: ✭ 108 (-6.09%)
Mutual labels:  webpack, babel

raw.macro

Actions Status Babel Macro

Webpack raw-loader implemented as babel-plugin-macros

Installation

In order to use raw.macro in your own project, you can use one of the following commands:

$ yarn add --dev raw.macro
# or
$ npm install --save-dev raw.macro

Make sure babel-plugin-macros already installed. If you're using Create React App, it's installed by default.

Usage

raw.macro is similar to Node’s require call:

import raw from "raw.macro";

const markdown = raw("./README.md");

Note: Because raw.macro uses babel internally to replace raw() calls, your transpiled code won't be changed if you only change the file that you import. This is because from babel perspective, your JS file is unchanged

One workaround that you can do that doesn't involve restarting your build system is making small changes where you put raw() calls, for example by adding console.log() with different content.

Dynamic path import

You can also use import dynamic path using template literal. You can even use them inside a function / React component!

import raw from "raw.macro";

function Article(props) {
  const content = raw(`../content/${props.locale}.md`);
  return <Markdown content={content} />;
}

This method has 2 caveats:

  1. You can only use up to two variables inside template literal. 1 for directory name, and 1 for file name.
  2. Using dynamic path import will includes all files that matches your dynamic path, which can make your JS bundle a lot bigger. This is also partly the reason of limitation described in #1

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].