0.8.1 • Published 10 months ago

yaml-loader v0.8.1

Weekly downloads
522,395
License
MIT
Repository
github
Last release
10 months ago

yaml-loader for Webpack

YAML loader for Webpack. Allows importing YAML files as JS objects. Uses yaml internally.

Installation

npm install --save-dev yaml-loader

Usage

// 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'

Options

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.

License

MIT

magnoabsass-sdfddabc-jdjdjjdfx-webpack-ttk@cfchase/interactive-landscapetzar-components@paxsoftware/coresalinesno-do-vuepack-clibrawl-capped-webpagelc-apmlemonitor-applicationtestmagno@collaveinc/quasar-app-extension-workbench@collaveinc/workbench-nuxt-module@infinitebrahmanuniverse/nolb-yam@everything-registry/sub-chunk-3196vue-cli-plugin-yamlwpackwx-buildsaguiscoutfilereadr-talk-plugin-signinreact-zeroconfigstalactiteroom-booking-appvitaminjsvitaminjs-buildgridsome-makeportalx-apimesaidesrenogridsomeinteractive-landscape-cagiplou-do-vuelee-ts-fusion-climrbuilder-plugin-yamljxml-reactkerygmakotatsuinfrastructure-webpackhammerpackl-panda-skyone-more-react-universal-examplepls-gamesolymp-webpack-lambdapresentation-3profile-servicenisusite-vue-depspoi-preset-yamlreact-chunky-engineqzzr-ui-componentsnetdata-collectors-landscapere-app-builderreact-app-webpack-pluginreact-app-rewire-yamlreact-scripts-stackpath-forkskypager-frameworkskypager-project-bundlerskypager-webpackskypager-helpers-webpacksimsky-mixin-mediaskylor.min-admintrack-buildertouchui-packtouchui-pc-packtrc-client-core@ascorbic/gatsby@atls/code-service@averjs/renderer@adrien-powder/toolbox@alauda-fe/devkit@alexandrov/vue-build-dev@alpacka/plugin-lambda@alpacka/runtime-lambda@best-shot/core@carbon/cli-preset-ui-service@7hci/gatsby-pge@bolt/build-tools@bonobolabs/gatsby@deskpro/apps-react-scripts@destdefe/compact@dashkite/sky-presetswayawaya-sharedwebpack-atomswebsdk@gridonic/webpack@gutenye/fusion-cli@harnessio/playground@hooleyandburch/gridsome@flecks/build@gabeklein/webpack-react-app@frictionlessdata/application@genma/webpack-common@kunlun-dx/compiler@kriya/gridsome@liudeing/do-vue@lowdefy/block-dev
0.8.1

10 months ago

0.8.0

3 years ago

0.7.0

3 years ago

0.6.0

5 years ago

0.5.0

7 years ago

0.4.0

8 years ago

0.3.0

8 years ago

0.2.0

9 years ago

0.1.0

11 years ago