UNPKG

@stencil/postcss

Version:

The Stencil PostCSS Plugin

33 lines (32 loc) 1.29 kB
import * as path from 'path'; export function usePlugin(fileName) { return /(\.css|\.pcss|\.postcss)$/i.test(fileName); } export function getRenderOptions(opts, sourceText, context) { const renderOpts = { plugins: opts.plugins || [], }; // always set "data" from the source text renderOpts.data = sourceText || ''; const injectGlobalPaths = Array.isArray(opts.injectGlobalPaths) ? opts.injectGlobalPaths.slice() : []; if (injectGlobalPaths.length > 0) { // automatically inject each of these paths into the source text const injectText = injectGlobalPaths .map((injectGlobalPath) => { if (!path.isAbsolute(injectGlobalPath)) { // convert any relative paths to absolute paths relative to the project root injectGlobalPath = path.join(context.config.rootDir, injectGlobalPath); } return `@import "${injectGlobalPath}";`; }) .join(''); renderOpts.data = injectText + renderOpts.data; } return renderOpts; } export function createResultsId(fileName) { // create what the new path is post transform (.css) const pathParts = fileName.split('.'); pathParts[pathParts.length - 1] = 'css'; return pathParts.join('.'); }