Socket
Book a DemoInstallSign in
Socket

yaml-js-loader

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

yaml-js-loader

A YAML file loader for webpack

0.1.1
latest
Source
npmnpm
Version published
Weekly downloads
213
-8.58%
Maintainers
1
Weekly downloads
 
Created
Source

yaml-js-loader

npm version Build Status codecov Scrutinizer Code Quality

Tells webpack how to load YAML files.

Installation

Open up your terminal and type the following

$ npm install --save-dev yaml-js-loader

Usage

The usage is quite easy.

Create a yaml file.

config.yml
name: Izuku Midoriya
quirk: One for all
friends:
 - Todoroki
 - Lida
 - Ochacho
 - Bakugo 

import the YAML file in your javascript file.

my-file.js
import config from './config.yml';

console.log(config);
// output -> {
//  url: "",
//  json: {
//    name: "Izuku Midoriya",
// .  quirk: "One for all",
//    friends: [
//      "Todoroki",
//      "Lida",
//      "Ochacho",
//      "Bakugo"
//    ]
// .},
//  text:"name: Izuku Midoriya\nquirk: One for all\nfriends:\n - Todoroki\n - Lida\n - Ochacho\n - Bakugo"\n
//}

Add the following configuration to webpack config file.

webpack.config.js
...

{
    test: /\.yml$/,
    loader: 'yaml-js-loader'
}
...

Usage(with file-loader)

Using with file loader provides a live URL to where the YAML file is served. The file can be accessed by visiting [base_url][webpack_public_path][url] for example,

if,

  • base_url = http://localhost:3005
  • webpack_public_path = /public
  • url = /static/config.d23e812af.yml

then, to access the file in the browser, you would need to visit: http://localhost:3005/public/static/config.d23e812af.yml

Create a yaml file.

config.yml
name: Izuku Midoriya
quirk: One for all
friends:
 - Todoroki
 - Lida
 - Ochacho
 - Bakugo 

import the YAML file in your javascript file. Now, the url property should have a value.

my-file.js
import config from './config.yml';

console.log(config);
// output -> {
//  url: "/static/[name].[hash:8].[ext]",
//  json: {
//    name: "Izuku Midoriya",
// .  quirk: "One for all",
//    friends: [
//      "Todoroki",
//      "Lida",
//      "Ochacho",
//      "Bakugo"
//    ]
// .},
//  text:"name: Izuku Midoriya\nquirk: One for all\nfriends:\n - Todoroki\n - Lida\n - Ochacho\n - Bakugo"\n
//}

Add the following configuration to webpack config file.

webpack.config.js
module.exports = {
...

    {
        test: /\.(yml|yaml)$/,
        use: [
          { loader: 'yaml-js-loader' },
          {
            loader: 'file-loader',
            options: {
              name: 'static/[name].[hash:8].[ext]'
            }
          }
        ]
    }
...
}

FAQs

Package last updated on 04 Feb 2018

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.