@omnia/tooling-vue
Version:
Used to bundle and serve manifests web component that build on Vue framework.
52 lines (51 loc) • 2.47 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.preBundleImportPath = void 0;
const base_1 = require("../base");
const importPath_1 = require("../importPath");
const manifest_1 = require("../../manifest");
const utils_1 = require("../../utils");
/** Transform pre bundle import paths to browser runtime variables */
exports.preBundleImportPath = (0, base_1.defineTransformer)("omnia-pre-bundle-import-path", async (alias) => {
const preBundles = await (0, manifest_1.getPreBundleInfo)();
if (preBundles.length == 0) {
return;
}
const importPathReplacers = preBundles.filter(preBundle => utils_1.pathUtils.isNodeModulePath(preBundle.path)).map(preBundle => {
const moduleFilePath = preBundle.path.replace('./node_modules/', '');
const moduleBareImport = Object.keys(alias).find(name => alias[name] == moduleFilePath);
if (!!moduleBareImport) {
return {
from: moduleBareImport,
to(defaultImport, ctx) {
const variable = getPreBundleResourceImportStatement(preBundle.serviceId, preBundle.resourceId, preBundle.path);
const fileGraph = ctx.getFileGraph(moduleBareImport);
if (fileGraph && fileGraph.bareImport && fileGraph.js && !fileGraph.js.bareImportVariable) {
fileGraph.js.bareImportVariable = variable;
}
return variable;
}
};
}
const modulePath = moduleFilePath.replace('/index.js', '').replace('.js', '');
return {
from: modulePath,
to(defaultImport, ctx) {
const variable = getPreBundleResourceImportStatement(preBundle.serviceId, preBundle.resourceId, preBundle.path);
const fileGraph = ctx.getFileGraph(modulePath);
if (fileGraph && fileGraph.bareImport && fileGraph.js && !fileGraph.js.bareImportVariable) {
fileGraph.js.bareImportVariable = variable;
}
return variable;
}
};
});
const instance = (0, importPath_1.importPath)(importPathReplacers);
return {
test: instance.test,
transform: instance.transform
};
});
function getPreBundleResourceImportStatement(serviceId, resourceId, path) {
return `omniaWebpackJsonp['${serviceId}']['${resourceId}']('${path.toLowerCase()}')`;
}