How to use the postcss-load-config function in postcss-load-config

To help you get started, we’ve selected a few postcss-load-config examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github WeAreGenki / minna-ui / utils / preprocess / src / style.ts View on Github external
// Merge user provided options into default context
  const context = merge(
    {
      from: filename,
      map: {
        annotation: false,
        inline: false,
      },
      syntax,
      to: filename,
    },
    opts,
  );

  try {
    const { plugins, options } = await postcssrc(context, filename);
    const result = await postcss(plugins).process(content, options);

    for (const err of result.warnings()) {
      // eslint-disable-next-line no-console
      console.warn(err.toString());
    }

    const dependencies: string[] = [];

    // Register dependencies for Rollup to detect changes
    for (const msg of result.messages) {
      if (msg.type === 'dependency') {
        dependencies.push(msg.file);
      }
    }
github meteor-vue / vue-meteor / packages / vue-component / plugin / post-css.js View on Github external
loadPostcssConfig = Meteor.wrapAsync(function (cb) {
  let error = null
  if (!loaded) {
    loaded = load({'vue-meteor': true}).catch(err => {
      // postcss-load-config throws error when no config file is found,
      // but for us it's optional. only emit other errors
      if (err.message.indexOf('No PostCSS Config found') < 0) {
        error = err
        error.message = 'PostCSS config Error: '.red + error.message
      }
    })
  }

  loaded.then(config => {
    let plugins = []
    let options = {}

    // merge postcss config file
    if (config && config.plugins) {
      plugins = plugins.concat(config.plugins)
github egoist / rollup-plugin-postcss / src / postcss-loader.js View on Github external
}
    // Return empty options for PostCSS
    return {}
  }

  configPath = configPath ? path.resolve(configPath) : path.dirname(id)
  const ctx = {
    file: {
      extname: path.extname(id),
      dirname: path.dirname(id),
      basename: path.basename(id)
    },
    options: configOptions || {}
  }

  return findPostcssConfig(ctx, configPath).catch(handleError)
}
github wbyoung / babel-plugin-transform-postcss / src / postcss-server.js View on Github external
if (err.code !== 'ENOENT') {
            throw err;
          }
        }

        if (cache && cache.hash === hash) {
          connection.end(JSON.stringify(cache.tokens));

          return;
        }

        const extractModules = (_, resultTokens: any) => {
          tokens = resultTokens;
        };
        const { plugins, options: postcssOpts } =
          await loadConfig({ extractModules }, path.dirname(cssFile));

        const runner = postcss(plugins);

        await runner.process(source, Object.assign({
          from: cssFile,
          to: cssFile, // eslint-disable-line id-length
        }, postcssOpts));

        cache = {
          hash,
          tokens,
        };

        // eslint-disable-next-line no-sync
        fs.writeFileSync(cachePath, JSON.stringify(cache));
github WeAreGenki / minna-ui / utils / build-css / src / index.ts View on Github external
async function processCss({
  banner = '',
  from,
  optimize = process.env.NODE_ENV === 'production',
  sourcemap,
  to = from,
}: ProcessCssOpts): Promise {
  const src = await readFile(from, 'utf8');

  const ctx = { from, map: sourcemap && { inline: false }, to };
  const source = banner + src;

  const { options, plugins } = await postcssrc(ctx, from);
  const result = await postcss(plugins).process(source, options);

  warn('PostCSS', 'WARN', result.warnings());

  let code = result.css;
  // eslint-disable-next-line prefer-destructuring
  let map: string | { toString(): string } | undefined = result.map;
  const hasMap = sourcemap && !!map;

  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
  const filePath = options.to!;
  const dirPath = dirname(filePath);

  if (optimize) {
    // Minify resulting CSS
    const min = new CleanCSS({
github sebastian-software / edge / packages / edge-postcss / __tests__ / lost.js View on Github external
test("Autoprefixer", () => {
  let input = ":fullscreen a { display: flex }"

  return loadConfig({ map: "inline" }).then(({ plugins, options }) => {
    return postcss(plugins)
      .process(input, options)
      .then((result) => expect(result.css).toMatchSnapshot())
  })
})
github vuejs / rollup-plugin-vue / src / style / postcss.js View on Github external
export default async function (postcssOpt) {
    let options = {}
    let plugins = []

    if (typeof postcssOpt === 'function') {
        plugins = postcssOpt.call(this)
    } else if (Array.isArray(postcssOpt)) {
        plugins = postcssOpt
    } else if (typeof postcssOpt === 'object') {
        plugins = (typeof postcssOpt.plugins === 'function') ? postcssOpt.plugins.call(this) : postcssOpt.plugins || []
        options = postcssOpt.options || {}
    }

    return postcssrc().then((config) => {
        if (config.plugins) {
            plugins = plugins.concat(config.plugins)
        }

        if (config.options) {
            options = Object.assign(options, config.options)
        }
        return {plugins, options}
    }).catch(() => { return {plugins, options} })
}
github axept / prejss / src / postcss-adapter / sync / parse.server.js View on Github external
const postcssrcSync = deasync(cb => {
  postcssrc()
    .then(res => cb(null, res))
    .catch(err => cb(err))
})
github youzan / vant / packages / vant-cli / src / compiler / compile-css.ts View on Github external
export async function compileCss(source: string | Buffer) {
  const config = await postcssrc({}, POSTCSS_CONFIG_FILE);
  const { css } = await postcss(config.plugins as any).process(source, {
    from: undefined
  });

  return minify(css).css;
}

postcss-load-config

Autoload Config for PostCSS

MIT
Latest version published 17 days ago

Package Health Score

89 / 100
Full package analysis