react-server icon indicating copy to clipboard operation
react-server copied to clipboard

组件中import的样式文件服务器渲染时什么处理?

Open Shijiuwei opened this issue 8 years ago • 1 comments

Shijiuwei avatar Apr 25 '16 15:04 Shijiuwei

你是指cssModules吗? 这个需要在webpack里增加一项配置:

var sassLoader = 'style!css?sourceMap!sass?sourceMap&sourceMapContents' +
  '&includePaths[]=' + encodeURIComponent(path.resolve(__dirname, "./src/styles")) +
  '&includePaths[]=' + encodeURIComponent(path.resolve(__dirname, "./node_modules/xxx/src/styles"));
...
{
  test: /\.scss$/,
  include: [
    path.resolve(__dirname, 'src/styles'),
    fs.realpathSync('./node_modules/xxx/src/styles'),
  ],
  loader: sassLoader
}

然后你js里就只需要这样引用即可: import styles from './MyComponents.scss';

huqingliang avatar Apr 29 '16 02:04 huqingliang