在安装了 style-loader 和 css-loader后,在component里面引入css文件,报无法找到模块。webpack的配置文件如下:
context: __dirname+'/src',
entry:"./js/index.js",
module:{
loaders:[{
test:/\.js?$/,
exclude:/(node_modules)/,
loader: "babel-loader",
query:{
presets:['react','es2015'],
plugins:['react-html-attrs'],
}
},
{
//test:/\.css$/,
//loader:'style!css-loader?modules&importLoaders=1&localIdentName=[name]__[local]__[hash:base64:5]'
test: /\.css$/,
loader: 'style-loader!css-loader'
}]
},
output:{
path:__dirname+"/src/",
filename:"bundle.js"
}
引入css文件如下:
var footerCss = require("../../css/style.css");
export default class ComponentFooter extends React.Component{
render(){
console.log(footerCss);
报错提示如下:
Uncaught Error: Cannot find module "../../css/style.css"
at webpackMissingModule (bundle.js:9979)
at Object.defineProperty.value (bundle.js:9979)
at __webpack_require__ (bundle.js:20)
at Object.ARIADOMPropertyConfig.Properties.aria-current (bundle.js:10178)
at __webpack_require__ (bundle.js:20)
at module.exports (bundle.js:66)
at bundle.js:69
注:src/css下面有footer.css文件
给我你的怀抱2017-05-19 10:11:09
css文件不是Module,不像其他组件有export...
使用方式:
import "../../css/style.css"
<p className="XXX"></p>
或:
import styles from "../../css/style.css"
<p className={styles.XXX}></p>