UNPKG

@omnia/tooling-vue

Version:

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

47 lines (46 loc) 2.13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.sharedVendorImportPath = exports.vendorImportPath = void 0; const tslib_1 = require("tslib"); const path_1 = tslib_1.__importDefault(require("path")); const vite_1 = require("vite"); const base_1 = require("./base"); const importPath_1 = require("./importPath"); /** Transform node module import paths to browser runtime variables */ exports.vendorImportPath = (0, base_1.defineTransformer)("omnia-vendor-import-path", (replacers) => { return createTransformer(replacers, 'omniaVendor'); }); /** Transform node module import paths to browser runtime variables */ exports.sharedVendorImportPath = (0, base_1.defineTransformer)("omnia-shared-vendor-import-path", (replacers) => { return createTransformer(replacers, 'omniaSharedVendor'); }); function createTransformer(replacers, runtimeVariable) { const importPathReplacers = replacers.map(r => { const from = typeof r == 'string' ? r : r.from; const ignore = typeof r == 'string' ? false : r.ignore; return { from: from, ignore: ignore, to(defaultImport) { let resolvedPath = null; if (typeof r == 'string') { const [_, distPath] = require.resolve(r).split('node_modules'); resolvedPath = (0, vite_1.normalizePath)(path_1.default.join('node_modules', distPath)); } else if (r.to) { resolvedPath = (0, vite_1.normalizePath)(path_1.default.join('node_modules', r.to)); } else { const [_, distPath] = require.resolve(r.from).split('node_modules'); resolvedPath = (0, vite_1.normalizePath)(path_1.default.join('node_modules', distPath)); } return `${runtimeVariable}('./${resolvedPath.toLowerCase()}')`; } }; }, []); const instance = (0, importPath_1.importPath)(importPathReplacers); return { test: instance.test, transform: instance.transform }; }