
Security News
Open Source CAI Framework Handles Pen Testing Tasks up to 3,600× Faster Than Humans
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Webpack
raw-loader
implemented asbabel-plugin-macros
and SWC plugins
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.
Alternatively you can use SWC plugins and skip installing babel-plugins-macros
entirely.
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.
If you want to use custom encoding (by default it will use utf-8
), you can pass it to the second argument
import raw from "raw.macro";
const binary = raw("./path/to/binary", "binary");
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:
You can also use raw.macro
in a swc-based project (e.g: Next.js) by using the SWC plugins.
Due to how the plugins is loaded, you have to pass rootDir
option pointing to the root directory of your project (where your node_modules
directory lives). Typically it's enough to pass __dirname
.
// next.config.js
module.exports = {
experimental: {
swcPlugins: [
[
"raw.macro/swc",
{
rootDir: __dirname,
},
],
],
},
};
Note that currently SWC plugins only support reading text file from relative path and node_modules content. Using custom encoding or dynamic path import is not supported.
MIT
FAQs
Read file contents at build time, similar to webpack raw-loader
The npm package raw.macro receives a total of 8,733 weekly downloads. As such, raw.macro popularity was classified as popular.
We found that raw.macro demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.