st-bundle
Version:
CLI for watching and bundling SpringType projects.
37 lines (36 loc) • 1.81 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const path = require("path");
const utils_1 = require("../utils/utils");
const bundleStrings_1 = require("../bundle/bundleStrings");
const pluginStrings_1 = require("../plugins/pluginStrings");
function cssDevModuleRender(props) {
const { ctx, module, data } = props;
const filePath = module.pkg.getPublicName() + '/' + module.props.fuseBoxPath;
// let the context know
let cssData = data.css;
if (ctx.config.sourceMap.css && data.map) {
const resourceConfig = ctx.config.getResourceConfig(props.options);
// generating a new name for our sourcemap
const name = `${utils_1.fastHash(module.props.absPath)}.css.map`;
// defining a public path (that browser will be able to reach)
const publicPath = utils_1.joinFuseBoxPath(resourceConfig.resourcePublicRoot, 'css', name);
// replace existing sourceMappingURL
if (/sourceMappingURL/.test(cssData)) {
cssData = cssData.replace(/(sourceMappingURL=)([^\s]+)/, `$1${publicPath}`);
}
else {
cssData += bundleStrings_1.sourceMapsCSSURL(publicPath);
}
// figuring out where to write that css
const targetSourceMapPath = path.join(resourceConfig.resourceFolder, 'css', name);
ctx.log.info('css', 'Writing css sourcemap to $file', { file: targetSourceMapPath });
ctx.writer.write(targetSourceMapPath, data.map);
}
let contents = `require("fuse-box-css")(${JSON.stringify(filePath)},${JSON.stringify(cssData)})`;
if (props.data.json) {
contents += '\n' + pluginStrings_1.wrapContents(JSON.stringify(props.data.json), props.useDefault);
}
module.contents = contents;
}
exports.cssDevModuleRender = cssDevModuleRender;