當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript postcss類代碼示例

本文整理匯總了TypeScript中postcss的典型用法代碼示例。如果您正苦於以下問題:TypeScript postcss類的具體用法?TypeScript postcss怎麽用?TypeScript postcss使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了postcss類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: reject

    }, (err, result) => {
      if (err) {
        return reject(`failed to compile ${file}: ${err}`);
      }

      const css = result.css.toString();

      postcss([autoprefixer({browsers: ['last 2 versions']}), cssnano])
        .process(css)
        .then(postResult => {
          postResult.warnings().forEach(warn => {
              console.warn(warn.toString());
          });

          // do not write to file if output is identical to previous version
          const productionCss = postResult.css.toString();
          if (resourceChecksum.update(checksums, path.basename(outputFile), productionCss)) {
            console.log(`[scss]:${file}`);

            fs.writeFile(outputFile, productionCss, werr => {
              if (werr) {
                return reject(`faile to write css file: ${outputFile}: ${werr}`);
              }

              resolve(`${file} compiled`);
            });
          } else {
            console.log(`[unchanged]:${file}`);
            resolve(`${file} unchanged`);
          }
        });
    });
開發者ID:cpylua,項目名稱:cheli.im,代碼行數:32,代碼來源:styles.ts

示例2: postcss

 })).then(results => {
     let r = results[0].root;
     for (let i = 1; i < results.length; i++) {
         r = r.append(results[i].root);
     }
     return postcss([cssnano({ safe: true })]).process(r.toResult());
 });
開發者ID:Bobris,項目名稱:bobril-build,代碼行數:7,代碼來源:cssHelpers.ts

示例3: postCSS

/**
 * @description 傳入 css string ,返回 postCSS 處理後的 css string
 * @param {string} css
 * @param {string} filePath
 * @param {object} projectConfig
 * @returns {Function | any}
 */
function postCSS({css, filePath, projectConfig}) {
  const pxTransformConfig = {
    designWidth: projectConfig.designWidth || 750
  }
  if (projectConfig.hasOwnProperty(DEVICE_RATIO)) {
    pxTransformConfig[DEVICE_RATIO] = projectConfig.deviceRatio
  }
  return postcss([
    require('stylelint')(stylelintConfig),
    require('postcss-reporter')({clearReportedMessages: true}),
    pxtransform(
      {
        platform: 'rn',
        ...pxTransformConfig
      }
    )
  ])
    .process(css, {from: filePath})
    .then((result) => {
      return {
        css: result.css,
        filePath
      }
    }).catch((e) => {
      Util.printLog(processTypeEnum.ERROR, '樣式轉換', filePath)
      console.log(e.stack)
    })
}
開發者ID:YangShaoQun,項目名稱:taro,代碼行數:35,代碼來源:styleProcess.ts

示例4: processCss

export function processCss(source: string, from: string, callback: (url: string, from: string) => string): PromiseLike<any> {
    return postcss([postcssUrl({
        url: (oldUrl: string, decl: any, from: string, dirname: string, to: string, options: any, result: any) => {
            if (oldUrl.startsWith("data:")) return oldUrl;
            return callback(oldUrl, from);
        }
    })]).process(source, { from });
}
開發者ID:Bobris,項目名稱:bobril-build,代碼行數:8,代碼來源:cssHelpers.ts

示例5: autoprefix

function autoprefix(input: Buffer, options: AutoprefixOptions, callback: TransformCallback) {
  const input_string = input.toString('utf8');
  postcss([autoprefixer]).process(input_string).then(result => {
    result.warnings().forEach(warning => console.warn(warning.toString()));
    const output = new Buffer(result.css, 'utf8');
    callback(null, output);
  }, error => callback(error));
}
開發者ID:chbrown,項目名稱:fapply,代碼行數:8,代碼來源:applicators.ts

示例6: postcss

export const processSync = ({
  css,
  filters,
  postcssSyntax,
  preserveLines,
}: IProcessOptions) => postcss(postcssSelectorExtract(filters, preserveLines))
  .process(css, { syntax: postcssSyntax }).css
  .replace(new RegExp(`\\/\\* ${PRESERVE_LINES_START}|${PRESERVE_LINES_END} \\*\\/`, `g`), ``);
開發者ID:Trevery,項目名稱:blog,代碼行數:8,代碼來源:index.ts

示例7: styleUnitTransform

 async styleUnitTransform (filePath: string, content: string) {
   const postcssResult = await postcss([
     unitTransform()
   ]).process(content, {
     from: filePath
   })
   return postcssResult
 }
開發者ID:YangShaoQun,項目名稱:taro,代碼行數:8,代碼來源:index.ts

示例8: processStyleUseCssModule

export function processStyleUseCssModule (styleObj: IStyleObj): any {
  const { projectConfig, appPath } = getBuildData()
  const weappConf = Object.assign({}, projectConfig.weapp)
  const useModuleConf = weappConf.module || {}
  const customPostcssConf = useModuleConf.postcss || {}
  const customCssModulesConf = Object.assign({
    enable: false,
    config: {
      generateScopedName: '[name]__[local]___[hash:base64:5]',
      namingPattern: 'global'
    }
  }, customPostcssConf.cssModules || {}) as ICSSModulesConf
  if (!customCssModulesConf.enable) {
    return styleObj
  }
  const namingPattern = customCssModulesConf.config.namingPattern
  if (namingPattern === 'module') {
    // 隻對 xxx.module.[css|scss|less|styl] 等樣式文件做處理
    const DO_USE_CSS_MODULE_REGEX = /^(.*\.module).*\.(css|scss|less|styl)$/
    if (!DO_USE_CSS_MODULE_REGEX.test(styleObj.filePath)) return styleObj
  } else {
    // 對 xxx.global.[css|scss|less|styl] 等樣式文件不做處理
    const DO_NOT_USE_CSS_MODULE_REGEX = /^(.*\.global).*\.(css|scss|less|styl)$/
    if (DO_NOT_USE_CSS_MODULE_REGEX.test(styleObj.filePath)) return styleObj
  }
  const generateScopedName = customCssModulesConf.config.generateScopedName
  const context = appPath
  let scopedName
  if (generateScopedName) {
    scopedName = typeof generateScopedName === 'function'
      ? (local, filename) => generateScopedName(local, filename)
      : genericNames(generateScopedName, { context })
  } else {
    scopedName = (local, filename) => Scope.generateScopedName(local, path.relative(context, filename))
  }
  const postcssPlugins = [
    Values,
    LocalByDefault,
    ExtractImports,
    new Scope({ generateScopedName: scopedName }),
    new ResolveImports({ resolve: Object.assign({}, { extensions: CSS_EXT }) })
  ]
  const runner = postcss(postcssPlugins)
  const result = runner.process(styleObj.css, Object.assign({}, { from: styleObj.filePath }))
  return result
}
開發者ID:YangShaoQun,項目名稱:taro,代碼行數:46,代碼來源:compileStyle.ts

示例9: renderSassSuccess

function renderSassSuccess(context: BuildContext, sassResult: Result, sassConfig: SassConfig): Promise<string> {
  if (sassConfig.autoprefixer) {
    // with autoprefixer

    let autoPrefixerMapOptions: any = false;
    if (sassConfig.sourceMap) {
      autoPrefixerMapOptions = {
        inline: false
      };
    }

    const postcssOptions: any = {
      to: basename(sassConfig.outFile),
      map: autoPrefixerMapOptions
    };

    Logger.debug(`sass, start postcss/autoprefixer`);

    return postcss([autoprefixer(sassConfig.autoprefixer)])
      .process(sassResult.css, postcssOptions).then((postCssResult: any) => {
        postCssResult.warnings().forEach((warn: any) => {
          Logger.warn(warn.toString());
        });

        let apMapResult: string = null;
        if (sassConfig.sourceMap && postCssResult.map) {
          Logger.debug(`sass, parse postCssResult.map`);
          apMapResult = JSON.parse(postCssResult.map.toString()).mappings;
        }

        Logger.debug(`sass: postcss/autoprefixer completed`);
        return writeOutput(context, sassConfig, postCssResult.css, apMapResult);
      });
  }

  // without autoprefixer
  generateSourceMaps(sassResult, sassConfig);

  let sassMapResult: string = null;
  if (sassResult.map) {
    sassMapResult = JSON.parse(sassResult.map.toString()).mappings;
  }

  return writeOutput(context, sassConfig, sassResult.css.toString(), sassMapResult);
}
開發者ID:Kode-Kitchen,項目名稱:ionic-app-scripts,代碼行數:45,代碼來源:sass.ts

示例10: url

import * as postcss from 'postcss';
import * as url from 'postcss-url';

const standard: postcss.Transformer = url();

const single: postcss.Transformer = url({ url: 'copy', assetsPath: 'img', useHash: true });

const multiple: postcss.Transformer = url([
    { filter: '**/assets/copy/*.png', url: 'copy', assetsPath: 'img', useHash: true },
    { filter: '**/assets/inline/*.svg', url: 'inline', optimizeSvgEncode: true },
    { filter: '**/assets/**/*.gif', url: 'rebase' },
    { filter: 'cdn/**/*', url: (asset) => `https://cdn.url/${asset.url}` },
]);

postcss().use(standard);
postcss().use(single);
postcss().use(multiple);
開發者ID:CNBoland,項目名稱:DefinitelyTyped,代碼行數:17,代碼來源:postcss-url-tests.ts


注:本文中的postcss類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。