Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

js-yaml-loader

wwilsman332.5kMIT1.2.2

YAML loader for webpack

yaml, webpack, loader

readme

js-yaml-loader for Webpack

JS-YAML loader for webpack.

Installation

yarn add js-yaml-loader

Usage

Webpack documentation on using loaders.

Using the loader inline:

import doc from 'js-yaml-loader!./file.yml';
// => returns a javascript object. see https://github.com/nodeca/js-yaml

Or using the loader via Webpack configuration (recommended):

// webpack.config.js
module: {
  rules: [{
    test: /\.yaml$/,
    use: 'js-yaml-loader',
  }]
}

Loader options

safe (boolean) (default=true)

Use safeLoad instead of load. Set safe to false to allow unsafe types to load, such as regular expressions, functions, and undefined.

iterator (function) (default=undefined)

The iterator option passed to safeLoadAll and loadAll. Applies iterator to each document if specified.

...options

Any other options are passed directly to to safeLoad or load as the options parameter.

Difference from yaml-loader

yaml-loader loads YAML files as JSON and is commonly used in conjuction with json-loader.

In contrast, this loader loads YAML files as JavaScript objects using the un-eval library. This allows YAML value types otherwise disallowed in JSON such as Infinity, RegExp, Function, etc. See js-yaml's supported YAML types

License

MIT

changelog

! /usr/bin/env node

const { spawn, spawnSync } = require('child_process'); const { readFileSync } = require('fs'); const { join } = require('path');

/**

  • Returns true if a package's version has not been published *
  • @param {String} pkg.name - package name
  • @param {String} pkg.version - package version
  • @returns {Boolean} true if the package version is not published */ function isUnpublished(pkg) { let published = spawnSync('npm', ['view', pkg.name, 'versions']);

    if (published.status === 0) { let versions = JSON.parse(published.stdout.toString().replace(/'/g, '"')); return !versions.includes(pkg.version); } else { return true; } }

/**

  • Publish the current package to NPM if it was not already *
  • @param {Object} pkg - package.json contents
  • @param {Array} args - array of arguments to pass to npm publish */ function publish(pkg, args) { if (isUnpublished(pkg)) { spawn('npm', ['publish', ...args], { stdio: [null, 1, 2] }).on('exit', process.exit); } }

// get the current package and publish it with any passed arguments const cwd = process.cwd(); const pkg = JSON.parse(readFileSync(join(cwd, 'package.json'))); const [,,...args] = process.argv;

publish(pkg, args);