UNPKG

@omnia/tooling-vue

Version:

Used to bundle and serve manifests web component that build on Vue framework.

45 lines (38 loc) 1.52 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); // borrowed from vue-loader var path = require('path'); var hash = require('hash-sum'); var cache = Object.create(null); var sepRE = new RegExp(path.sep.replace('\\', '\\\\'), 'g'); function genId(file, context) { const contextPath = context.split(path.sep); const rootId = contextPath[contextPath.length - 1]; file = rootId + '/' + path.relative(context, file).replace(sepRE, '/'); return cache[file] || (cache[file] = hash(file)); } function default_1(contents) { const id = genId(this.resourcePath, process.cwd()); return contents + ";\n" + `if (module.hot) { const api = require('vue-hot-reload-api') const Vue = require('vue') api.install(Vue) if (!api.compatible) { throw new Error('vue-hot-reload-api is not compatible with the version of Vue you are using.') } module.hot.accept(); let componentOptionsKey = Object.keys(exports).filter(key => exports[key].prototype && exports[key].prototype instanceof Vue.default)[0]; let componentOptions = exports.default || exports[componentOptionsKey]; if (!componentOptions) { throw new Error('Cannot find Vue component') } if (!module.hot.data) { api.createRecord('${id}', componentOptions); } else { api.rerender('${id}', componentOptions); } }`; } exports.default = default_1;