You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.1 KiB
44 lines
1.1 KiB
const babel = require("@babel/core");
|
|
const addDataLocator = require("./add-data-locator.cjs");
|
|
|
|
module.exports = function (source, inputSourceMap) {
|
|
if (process.env.NODE_ENV !== "development") {
|
|
return source;
|
|
}
|
|
|
|
const filename = this.resourcePath;
|
|
if (!filename || filename.includes("node_modules")) {
|
|
return source;
|
|
}
|
|
|
|
// Quick check: if there are no angle brackets, no JSX to transform
|
|
if (!source.includes("<")) {
|
|
return source;
|
|
}
|
|
|
|
try {
|
|
const result = babel.transformSync(source, {
|
|
filename,
|
|
presets: [
|
|
["@babel/preset-react", { runtime: "automatic" }],
|
|
"@babel/preset-typescript",
|
|
],
|
|
plugins: [addDataLocator],
|
|
configFile: false,
|
|
babelrc: false,
|
|
sourceMaps: true,
|
|
inputSourceMap: inputSourceMap || undefined,
|
|
});
|
|
|
|
if (result && result.code) {
|
|
this.callback(null, result.code, result.map);
|
|
return;
|
|
}
|
|
} catch (err) {
|
|
console.error(
|
|
`[jsx-locator-loader] Skipped ${filename} due to parse notice: ${err.message}`,
|
|
);
|
|
}
|
|
|
|
return source;
|
|
};
|