Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
compiler(config, (err, data) => {
if (err) {
return cb(err);
}
const memoryFs = new MemoryFS(data);
const bundle = memoryFs.readFileSync(
`/build/${config.output.filename}`,
"UTF8"
);
const bundleHash = hashBuilder.fromString(bundle);
const bundleName = "react-component";
const bundlePath = path.join(publishPath, `${bundleName}.js`);
const wrappedBundle = reactComponentWrapper(bundleHash, bundle);
fs.outputFileSync(bundlePath, wrappedBundle);
let css = null;
if (data.build["main.css"]) {
// This is an awesome hack by KimTaro that will blow your mind.
// Remove it once this get merged: https://github.com/webpack-contrib/css-loader/pull/523
css = fontFamilyUnicodeParser(
memoryFs.readFileSync(`/build/main.css`, "UTF8")
);
// We convert single quotes to double quotes in order to
// support the viewTemplate's string interpolation
css = minifyFile(".css", css).replace(/\'/g, '"');
fs.outputFileSync(cssPath, css);
}
const reactRoot = `oc-reactRoot-${componentPackage.name}`;
const templateString = viewTemplate({
reactRoot,
css,
externals,
bundleHash,
bundleName
});
const templateStringCompressed = production
? templateString.replace(/\s+/g, " ")
: templateString;
const hash = hashBuilder.fromString(templateStringCompressed);
const view = ocViewWrapper(hash, templateStringCompressed);
return cb(null, {
template: { view, hash },
bundle: { hash: bundleHash }
});
});
};
err =>
next(
err,
err
? null
: {
type: "node.js",
hashKey: hashBuilder.fromString(
compiledFiles[publishFileName]
),
src: publishFileName
}
)
)