
Security News
AI Agent Submits PR to Matplotlib, Publishes Angry Blog Post After Rejection
After Matplotlib rejected an AI-written PR, the agent fired back with a blog post, igniting debate over AI contributions and maintainer burden.
tojson-loader
Advanced tools
Serialize module exports as JSON. Cache generated static data as JSON at build time.
If every client needs access to a shared chunk of data, and that data
can be known at build time, a simple option is to bake that data into
clientside build with tojson-loader.
Particularly useful for loading configuration and/or mock data into the client.
Function or Date objects.// webpack.config.js
module.exports = {
...
module: {
loaders: [
{
// Use *.json.js extension to bake exported JS data into JSON
test: /\.json\.js/,
loader: 'tojson'
}
...
]
}
}
.json.js file// data.json.js
// can use serverside-only dependencies
var fs = require('fs')
var readme = fs.readFileSync(__dirname + '/../../Readme.md', 'utf8')
readme = readme.split('\n')[0] // (just grab header for demo)
// any other dependencies that are only used in here won't be included in bundle
var tape = require('tape') // some random dependency
// whatever the value of module.exports is will be serialised to JSON
module.exports = {
readme: readme,
tape: tape, // tape happens to be a function so it won't serialise.
random: Math.random(), // will be fixed to whatever value is generated at compile-time
}
// index.js
console.log(require('./data.json.js'))
The transformed output after being built by webpack is below.
Note:
fs, tape) used.fs.readFileSync is baked into the output.random key will always be the same value until next build.tape key doesn't exist because JSON can't serialise functions....
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {
console.log(__webpack_require__(1))
/***/ },
/* 1 */
/***/ function(module, exports) {
module.exports = {"readme":"# tojson-loader","random":0.5418716457206756}
/***/ }
/******/ ]);
ISC
FAQs
Serialize module exports as JSON. Cache generated static data as JSON at build time.
The npm package tojson-loader receives a total of 17 weekly downloads. As such, tojson-loader popularity was classified as not popular.
We found that tojson-loader 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
After Matplotlib rejected an AI-written PR, the agent fired back with a blog post, igniting debate over AI contributions and maintainer burden.

Security News
HashiCorp disclosed a high-severity RCE in next-mdx-remote affecting versions 4.3.0 to 5.x when compiling untrusted MDX on the server.

Security News
Security researchers report widespread abuse of OpenClaw skills to deliver info-stealing malware, exposing a new supply chain risk as agent ecosystems scale.