UNPKG

edge-fe-meta-loader

Version:

Edge Platform FE Meta Template loader for webpack

25 lines (20 loc) 634 B
const uneval = require('un-eval'); const { getOptions } = require('loader-utils'); const yaml = require('js-yaml'); const unsafe = require('js-yaml-js-types').all; const schema = yaml.DEFAULT_SCHEMA.extend(unsafe); module.exports = function(source) { this.cacheable && this.cacheable(); try { const options = getOptions(this); const res = yaml.loadAll(source, { schema, ...options }); return [ `const React = require('react');`, `const doc = ${uneval(res)};`, 'module.exports = doc.length <= 1 ? doc[0] : doc;' ].join('\n'); } catch (err) { this.emitError(err); return null; } };