yaml-loader
Advanced tools
Comparing version 0.3.0 to 0.4.0
@@ -6,3 +6,3 @@ var yaml = require('js-yaml'); | ||
var res = yaml.safeLoad(source); | ||
return 'module.exports = ' + JSON.stringify(res, undefined, '\t'); | ||
return JSON.stringify(res, undefined, '\t'); | ||
}; |
{ | ||
"name": "yaml-loader", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "YAML loader for webpack (converts YAML to JSON)", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# yaml-loader for webpack | ||
YAML loader for [webpack](http://webpack.github.io/). Converts YAML to JSON. | ||
YAML loader for [webpack](http://webpack.github.io/). Converts YAML to a valid JSON. If you want a JS Object, chain it with [json-loader](https://github.com/webpack/json-loader). | ||
@@ -13,7 +13,34 @@ ## Installation | ||
Simplest case would be: | ||
``` javascript | ||
var json = require("yaml!./file.yml"); | ||
var json = require("json!yaml!./file.yml"); | ||
// => returns file.yml as javascript object | ||
``` | ||
This loader is also useful for getting a valid JSON from YML. For example: | ||
```js | ||
// webpack.config.js | ||
module: { | ||
loaders: [ | ||
{ | ||
test: /\.yaml$/, | ||
include: path.resolve('data'), | ||
loader: 'yaml', | ||
}, | ||
], | ||
} | ||
``` | ||
and then | ||
```js | ||
// applicatin.js | ||
const actualFilename = require(`file?name=[name].json!./../data/${file}.yaml`); | ||
window.fetch(actualFilename).then(res => { | ||
// ... | ||
}); | ||
``` | ||
## License | ||
@@ -20,0 +47,0 @@ |
3330
49