javascript - react imports css files and prompts Cannot find module "../../css/style.css"
滿天的星座
滿天的星座 2017-05-19 10:09:09
0
1
1589

After installing style-loader and css-loader, when introducing the css file into the component, it reports that the module cannot be found. The configuration file of webpack is as follows:
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" }

Introduce the css file as follows:
var footerCss = require("../../css/style.css");
export default class ComponentFooter extends React.Component{
render(){

console.log(footerCss);

The error message is as follows:

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

Note: There is a footer.css file under src/css

滿天的星座
滿天的星座

reply all (1)
给我你的怀抱

The css file is not a Module, unlike other components that have export...

How to use:

import "../../css/style.css" 

or:

import styles from "../../css/style.css" 

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!