egoist / rollup-plugin-postcss

Seamless integration between Rollup and PostCSS.
MIT License
673 stars 212 forks source link

Generate single css file for multiple js bundles(esm, umd, cjs) #166

Open cpmotion opened 5 years ago

cpmotion commented 5 years ago

Current rollup.config.js looks as such:

import postcss from 'rollup-plugin-postcss';
import replace from 'rollup-plugin-replace';
import babel from 'rollup-plugin-babel';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import { terser } from 'rollup-plugin-terser';
import mqpacker from 'css-mqpacker';
import pkg from './package.json';

const isProd = process.env.NODE_ENV !== 'production';

export default {
  input: './src/index.js',
  output: [
    {
      file: pkg.main,
      format: 'cjs'
    },
    {
      file: pkg.module,
      format: 'esm'
    },
    {
      file: pkg.browser,
      format: 'umd',
      name: pkg.name
    }
  ],
  external: Object.keys(pkg.dependencies),
  watch: {
    include: './src/**',
    chokidar: {
      ignoreInitial: true,
      awaitWriteFinish: {
        stabilityThreshold: 100,
        pollInterval: 10
      }
    }
  },
  interop: false,
  plugins: [
    postcss({
      extract: true,
      sourceMap: true,
      plugins: [mqpacker()]
    }),
    replace({
      'process.env.NODE_ENV': JSON.stringify('production')
    }),
    resolve(),
    babel({
      exclude: 'node_modules/**'
    }),
    commonjs(),
    isProd && terser()
  ]
};

Works fine but I get separate css and css.map files for each module type. I just want the JS files and a single css/css.map file. Possible??

lahickey commented 5 years ago

Set your extract parameter to a filename relative to the rollup.config.js file and it should export a single file. E.g.

postcss({
      extract: 'dist/pkg.css',
      sourceMap: true,
      plugins: [mqpacker()]
    }),
zhangwei900808 commented 4 years ago
import React, { Component } from "react";
import { Button } from "antd";
**import "styles/demo.pcss";**

class Demo extends Component {
  render() {
    return (
      <div className="demo-container">
        <div className="demo-wrapper">this is my demo wrapper</div>
        <Button type="primary">this is demo component</Button>
      </div>
    );
  }
}

export default Demo;

image

the path is wrong , I missed something?

designbyadrian commented 1 year ago

Set your extract parameter to a filename relative to the rollup.config.js file and it should export a single file. E.g.

No, this will create a folder named "dist" for every bundle.

andriirak commented 4 months ago

any updates?