最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

RollupJs, PostCSS, SCSS Modules, Bootstrap being created in Styles.css at end of file, overriding css - Stack Overflow

programmeradmin1浏览0评论

I am using Rollup, PostCSS, Bootstap, Sass and React to bundle a component that relies on Bootstrap css.

I write my component files but the output of Rollup has the following:

My Rollup Config is:

import dotenv from 'rollup-plugin-dotenv'
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 path from 'path';
import alias from '@rollup/plugin-alias';
import postcss from 'rollup-plugin-postcss';
import pkg from './package.json' assert { type: 'json' };
import autoprefixer from 'autoprefixer';
import json from '@rollup/plugin-json';

const __dirname = path.resolve();

export default {
  input: 'src/index.js',
  output: [
    { dir: pkg.module, format: 'esm' },
  ],
  globals: {
    'react-bootstrap': 'ReactBootstrap'
  },
  onwarn(warning, warn) {
    if (warning.code === 'MODULE_LEVEL_DIRECTIVE') {
      return
    }
    warn(warning)
  },
  plugins: [
    dotenv(),
    json(),
    alias({
      entries: [
        { find: '@', replacement: path.resolve(__dirname, 'src') },
      ],
    }),
    resolve(),
    babel({
      babelHelpers: 'bundled',
      exclude: 'node_modules/**',
      presets: ['@babel/preset-env', '@babel/preset-react']
    }),
    postcss({
      plugins: [autoprefixer()],
      autoModules: true,
      extract: 'styles.css',
    }),
    commonjs(),
    terser(),
  ],
  external: Object.keys(pkg.peerDependencies),
};

The compiled css output is

/* My CSS Rules */
.h1 {
  font-size: 20rem;
}

/* All The Bootstrap CSS*/
.h1 {
  font-size: 1rem;
}

Since the score is equal, any overrides or variables I am setting in my custom scss modules is overridden by the default bootstrap styles.

What magic config words do I need to do to put Bootstrap at the top of my styles.css file when it is compiled?

EG

/* All The Bootstrap CSS*/
.h1 {
  font-size: 1rem;
}

/* My CSS Rules */
.h1 {
  font-size: 20rem;
}

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论