reactjs - Bundling Sass modules in React Component Package with Rollup - Stack Overflow

I'm working on packaging up a React component. I'm used to using CSS modules with sass (EG li

I'm working on packaging up a React component. I'm used to using CSS modules with sass (EG like Next.js).

-src
--components
---HelloWorld
----index.js
----hello-world.module.scss

HelloWorld

import React from 'react'
import styles from './hello-world.module.scss'

const HelloWorld = () => {
  return(
    <div className={styles.hello}>Hello World</div>
  )
}

export default HelloWorld

hello-world.module.scss

.hello {
  font-size: 2rem;
}

rollup.config.js

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 sass from 'rollup-plugin-sass';
import pkg from './package.json' assert { type: 'json' };


export default {
  input: 'src/index.jsx',
  output: [
    { file: pkg.main, format: 'cjs' },
    { file: pkg.module, format: 'esm' },
  ],
  plugins: [
    babel({
      babelHelpers: 'bundled',
      exclude: 'node_modules/**',
      presets: ['@babel/preset-env', '@babel/preset-react']
    }),
    sass(),
    resolve(),
    commonjs(),
    terser(),
  ],
  external: Object.keys(pkg.peerDependencies),
};

Given the above code, it successfully 'rolls up' but the output of styles.css is

.hello {
  font-size: 2rem;
}

My desired output would be something like:

.HelloWorld-hello {
  font-size: 2rem;
}

to prevent any collisions. I just don't even seem to know the right terms to google.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744386971a4571713.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信