在安裝了 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檔
css檔案不是Module,不像其他元件有export...
使用方式:
或: