Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const outPath = outSrcPath + '.js';
const fileDirectory = dirname(filePath);
const outDirPath = dirname(outPath);
const cssAssetFilename = nameTemplate(outputCSSNameTemplate, {
filename: basename(outSrcPath, '.st.css')
});
const cssAssetOutPath = join(dirname(outSrcPath), cssAssetFilename);
log('[Build]', filePath + ' --> ' + outPath);
tryRun(() => ensureDirectory(outDirPath, fs), `Ensure directory: ${outDirPath}`);
const content = tryRun(
() => fs.readFileSync(filePath).toString(),
`Read File Error: ${filePath}`
);
const res = stylable.transform(content, filePath);
const optimizer = new StylableOptimizer();
if (optimize) {
optimizer.optimize(
{
removeComments: true,
removeEmptyNodes: true,
removeStylableDirectives: true,
classNameOptimizations: false,
removeUnusedComponents: false
},
res,
{}
);
}
handleDiagnostics(diagnostics, res, diagnosticsMsg, filePath);
// st.css
if (outputSources) {
// meta.namespace = getNamespaceFromBuiltStylsheet()
// TODO: move to stylable as param.
if (this.options.optimize.shortNamespaces) {
meta.namespace = stylable.optimizer!.namespaceOptimizer.getNamespace(
meta,
compiler.context,
stylable
);
}
return meta;
},
undefined,
this.options.transformHooks,
compiler.options.resolve,
this.options.optimizer || new StylableOptimizer(),
compiler.options.mode as any,
this.options.resolveNamespace || resolveNamespace
);
this.stylable = stylable;
}
public injectPlugins(compiler: webpack.Compiler) {