UNPKG

firejsx

Version:

The React Framework for SSB, SSR and Serverless technologies

30 lines (29 loc) 1.33 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const path_1 = require("path"); function default_1({ types: t }) { const WrapJsPath = path_1.join(__dirname, "../web/Wrap"); return { visitor: { "ExportDefaultDeclaration"(path, { filename, opts: { pagesPath, proOrSSR } }) { const filenames = filename.split(pagesPath); //if filename starts with pagesPath then split returns empty string at index 0 if (!filenames[0]) { path.replaceWith(t.callExpression(t.memberExpression(t.callExpression(t.identifier("require"), [ t.stringLiteral(WrapJsPath) ]), t.identifier("default")), [ t.stringLiteral(filenames[1].replace(/\\/g, "/").substring(1)), t.toExpression(path.node.declaration), ...(proOrSSR ? [] : [ t.memberExpression(t.callExpression(t.identifier("require"), [ t.stringLiteral("react-hot-loader/root") ]), t.identifier("hot")) ]) ])); } } } }; } exports.default = default_1;