React-css-modules:无法识别styleName

时间:2016-07-04 12:29:29

标签: css reactjs react-css-modules

我对react-css-modules有问题。我无法找到我受styleName约束的类。它们不会在渲染的html中显示为类。

以下是代码:

webpack

module: { loaders: [ ... { test: /\.css$/, loaders: [ require.resolve('style-loader'), require.resolve('css-loader') + '?sourceMap&modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]' ] }, ... ] } 配置:

17:03:19.088683 IP 10.168.245.2.35050 > 54.76.101.68.80: Flags [S],
seq 1295390892, win 27400, options [mss 1370,sackOK, TS val 23947380
ecr 0,nop,wscale 7], length 0

17:03:19.106395 IP 54.76.101.68.80 > 10.168.245.2.35050: Flags [S.],
seq 403807014, ack 1295390893, win 26847, options [mss 1460,sackOK,
TS val 192703377 ecr 23947380,nop,wscale 7], length 0

17:03:19.106436 IP 10.168.245.2.35050 > 54.76.101.68.80: Flags [.],
ack 1, win 215, options [nop,nop,TS val 23947398 ecr 192703377],
length 0

17:03:19.106615 IP 10.168.245.2.35050 > 54.76.101.68.80: Flags [P.],
seq 1:147, ack 1, win 215, options [nop,nop,TS val 23947398
ecr 192703377], length 146: HTTP: GET /20 HTTP/1.1

17:03:19.122771 IP 54.76.101.68.80 > 10.168.245.2.35050: Flags [.],
ack 147, win 219, options [nop,nop,TS val 192703381 ecr 23947398],
length 0
(*)
17:03:19.152665 IP 54.76.101.68.80 > 10.168.245.2.35050: Flags [.],
seq 13581:14939, ack 147, win 219, options [nop,nop,TS val 192703389
ecr 23947398], length 1358: HTTP

17:03:19.152691 IP 10.168.245.2.35050 > 54.76.101.68.80: Flags [.],
ack 1, win 236, options [nop,nop,TS val 23947444
ecr 192703381,nop,nop,sack 1 {13581:14939}], length 0

17:03:19.384706 IP 54.76.101.68.80 > 10.168.245.2.35050: Flags [.],
seq 1:1359, ack 147, win 219, options [nop,nop,TS val 192703447
ecr 23947444], length 1358: HTTP: HTTP/1.1 200 OK

17:03:19.384738 IP 10.168.245.2.35050 > 54.76.101.68.80: Flags [.],
ack 1359, win 257, options [nop,nop,TS val 23947676
ecr 192703447,nop,nop,sack 1 {13581:14939}], length 0

17:03:19.616700 IP 54.76.101.68.80 > 10.168.245.2.35050: Flags [.],
seq 1359:2717, ack 147, win 219, options [nop,nop,TS val 192703505
ecr 23947676], length 1358: HTTP

17:03:19.616735 IP 10.168.245.2.35050 > 54.76.101.68.80: Flags [.],
ack 2717, win 278, options [nop,nop,TS val 23947908
ecr 192703505,nop,nop,sack 1 {13581:14939}], length 0

17:03:19.633035 IP 54.76.101.68.80 > 10.168.245.2.35050: Flags [P.],
seq 14939:16297, ack 147, win 219, options [nop,nop,TS val 192703509
ecr 23947908], length 1358: HTTP

17:03:19.633066 IP 10.168.245.2.35050 > 54.76.101.68.80: Flags [.],
ack 2717, win 299, options [nop,nop,TS val 23947925
ecr 192703505,nop,nop,sack 1 {13581:16297}], length 0

17:03:19.633036 IP 54.76.101.68.80 > 10.168.245.2.35050: Flags [.],
seq 16297:17655, ack 147, win 219, options [nop,nop,TS val 192703509
ecr 23947908], length 1358: HTTP

17:03:19.633073 IP 10.168.245.2.35050 > 54.76.101.68.80: Flags [.],
ack 2717, win 321, options [nop,nop,TS val 23947925
ecr 192703505,nop,nop,sack 1 {13581:17655}], length 0

[...]

那么这里有什么问题?

1 个答案:

答案 0 :(得分:0)

如果有帮助,这是webpack config中的我的加载器数组:

loaders: [
            'style?sourceMap',
            'css?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]'
          ]

也许在styleLoader中使用的sourceMap而不是css加载器与它有任何关系。

此外,您可以尝试避免使用注释@CSSModules(styles)并使用正常方式,例如export default CSSModules(ListItem, styles)查看注释是否存在问题。

除此之外,我看不出有什么不对。