UNPKG

vite-ssr-vue2

Version:

Vite utility for vue2 server side rendering

29 lines (23 loc) 890 B
'use strict'; var pluginVue2 = require('@vitejs/plugin-vue2'); var path = require('path'); function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } var path__default = /*#__PURE__*/_interopDefaultLegacy(path); var pluginId = () => { return { name: "vue-add-file", transform(code, id, opt) { const ssr = opt?.ssr === true; const { filename, query } = pluginVue2.parseVueRequest(id); if (!query.vue && ssr && /\.vue$/.test(filename)) { const id2 = path__default["default"].relative(path__default["default"].resolve(), filename); code = code.replace(/export\s+default\s+__component__\.exports(;)?/, `__component__.options.__id = ${JSON.stringify(id2)}; export default __component__.exports;`); return { code }; } } }; }; module.exports = pluginId;