How to use postcss-load-config - 10 common examples

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 upash / peco / lib / index.js View on Github external
async prepare({ dev }) {
    console.log('> Building from source')
    // Load user config
    const { data, path: configPath } = await config.load(
      [
        'peco.config.yml',
        'peco.config.toml',
        'peco.config.js',
        'peco.config.json'
      ],
      this.options.baseDir
    )
    this.configPath = configPath
    await this.normalizeConfig(data)

    const postcssConfig = await require('postcss-load-config')({
      cwd: this.options.baseDir,
      argv: false
    }).catch(err => {
      if (err.message.includes('No PostCSS Config found')) {
        // Return empty options for PostCSS
        return {}
      }
      throw err
    })

    if (postcssConfig.file) {
      this.postcss = {
        config: {
          path: postcssConfig.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 preactjs / preact-cli / packages / cli / lib / lib / webpack / webpack-base-config.js View on Github external
requireRelative.resolve('preact/compat', cwd);
		compat = 'preact/compat';
	} catch (e) {}

	let babelConfig = Object.assign(
		{ babelrc: false },
		createBabelConfig(env, { browsers }),
		babelrc // intentionally overwrite our settings
	);

	let tsconfig = resolveTsconfig(cwd, isProd);

	let postcssPlugins;

	try {
		postcssPlugins = loadPostcssConfig.sync(cwd).plugins;
	} catch (error) {
		postcssPlugins = [autoprefixer({ overrideBrowserslist: browsers })];
	}

	return {
		context: src,

		resolve: {
			modules: [...nodeModules, 'node_modules'],
			extensions: [
				'.mjs',
				'.js',
				'.jsx',
				'.ts',
				'.tsx',
				'.json',
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))
})

postcss-load-config

Autoload Config for PostCSS

MIT
Latest version published 6 months ago

Package Health Score

84 / 100
Full package analysis