Research
Security News
Kill Switch Hidden in npm Packages Typosquatting Chalk and Chokidar
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
yaml-loader
Advanced tools
YAML loader for Webpack. Allows importing YAML files as JS objects. Uses yaml
internally.
npm install --save-dev yaml-loader
// webpack.config.js
module.exports = {
module: {
rules: [
{
test: /\.ya?ml$/,
use: 'yaml-loader'
}
]
}
}
# file.yaml
---
config:
js:
key: test
hello: world
// application.js
import file from './file.yaml'
file.hello === 'world'
In addition to all yaml
options used by its parsing methods,
the loader supports the following additional options:
asJSON
If enabled, the loader output is stringified JSON rather than stringified JavaScript. For Webpack v4, you'll need to set the rule to have type: "json"
. Also useful for chaining with other loaders that expect JSON input.
asStream
If enabled, parses the source file as a stream of YAML documents. With this, the output will always be an array, with entries for each document. If set, namespace
is ignored.
To use this option for only some YAML files, it's probably easiest to use a query parameter and match that using Rule.resourceQuery:
// webpack.config.js
module.exports = {
module: {
rules: [
{
test: /\.ya?ml$/,
oneOf: [
{
resourceQuery: /stream/,
options: { asStream: true },
loader: 'yaml-loader'
},
{ loader: 'yaml-loader' }
]
}
]
}
}
Then, importing ./foo.yaml
will expect it to contain only one document, but ./bar.yaml?stream
may contain multiple documents.
namespace
Allows for exposing a sub-tree of the source document:
import jsCfg from './file.yaml?namespace=config.js'
jsCfg.key === 'test'
The namespace
should be a series of keys, dot separated. Note that any options
object in your webpack.config.js
rule will be superseded by a ?query
.
FAQs
YAML loader for Webpack
The npm package yaml-loader receives a total of 304,109 weekly downloads. As such, yaml-loader popularity was classified as popular.
We found that yaml-loader demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers 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.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.