javascript - webpack引入css报错cannot resolve module ‘style’?
伊谢尔伦
伊谢尔伦 2017-04-10 17:08:06
[JavaScript讨论组]

正确安装了webpack以及相关插件和依赖,
webpack.config.js配置如下:

module.exports = {
    entry: './entry.js',
    output: {
        path: __dirname, 
        filename: 'bundle.js' 
    },
    module: {
        loaders: [
            {test: /\.js$/, exclude: /node_modules/, loader: 'react-hot!babel'},
            {test: /\.css$/, loader: 'style!css'}
        ]
    }
};

entry.js引入css:

import './node_modules/semanticui/dist/style.css';

style.css里就写了一条:

body {
    color: red;
}

然后在命令行里启动一下,一切正常,css成功引入。
但是我把style.css替换成同目录下的semantic.css,修改下配置,启动后会报错

ERROR in ./entry.js
Module not found: Error: Cannot resolve module 'semantic' in /Users/zaxlct/Desktop/react-first

webpack.config.js是这么配置的 :

{test: /\.css$/, loader: 'semantic!css'}

entry.js是这么写的:

import './node_modules/semantic-ui/dist/semantic.css';

注:semantic-ui是 直接 npm install semantic下载到项目里的,个人感觉问题出在semantic上,但是不知道具体怎么解决

附上 semantic.css前几行代码:

@import url('https://fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic&subset=latin');

*,
*:before,
*:after {
  box-sizing: inherit;
}

html {
  box-sizing: border-box;
}

input[type="text"],
input[type="email"],
input[type="search"],
input[type="password"] {
  -webkit-appearance: none;
  -moz-appearance: none;
  /* mobile firefox too! */
}
伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

全部回复(1)
天蓬老师

感觉题主还不知道什么是 loader ...

{test: /\.css$/, loader: 'semantic!css'}
semantic 改回 style

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号