引用css时var footerCss = require("../../css/footer.css");运行报错You may need an appropriate loader to handle this file type.

webpack.config.js配置如下


var debug = process.env.NODE_ENV !== "production";
var webpack = require('webpack');
var path = require('path');
module.exports = {
context: path.join(__dirname),
devtool: debug ? "inline-sourcemap" : null,
entry: "./src/js/index.js",
module: {
loaders: [
{
test: /\.js?$/,
exclude: /(node_modules)/,
loader: 'babel-loader',
query: {
presets: ['react', 'es2015'],
plugins: ['react-html-attrs'], //添加组件的插件配置
}
},
//下面是添加的 css 的 loader,也即是 css 模块化的配置方法,大家可以拷贝过去直接使用
{
test: /\.css$/,
loader: 'style!css-loader?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]'
},
]
},
output: {
path: __dirname,
filename: "./src/bundle.js"
},
plugins: debug ? [] : [
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin({ mangle: false, sourcemap: false }),
],
};

package.json文件已经安装了style-loader,和css-loader 模块。全局-g重新安装一遍后,webpack报错

ERROR in ./src/js/components/footer.js
Module not found: Error: Can't resolve 'style' in '/Users/mac/source/9-01'
BREAKING CHANGE: It's no longer allowed to omit the '-loader' suffix when using loaders.You need to specify 'style-loader' instead of 'style',see https://webpack.js.org/guides/migrating/#automatic-loader-module-name-extension-removed@ ./src/js/components/footer.js 25:16-47@ ./src/js/index.js

大意猜测某部分少了-loader,于是在webpack.config .js文件中style改为style-loader

loader: 'style-loader!css-loader?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]'

运行webpack成功

webpack编译出错You may need an appropriate loader to handle this file type.相关推荐

  1. Webpack執行打包:“You may need an appropriate loader to handle this file type“

    项目场景: 使用webpack對CSS文件和一JS文件進行打包 问题描述: 配置webpack.config.js完成;webpack & webpack-cli安裝完成;css-loader ...

  2. [编译记录]遇到“ld: unsupported tapi file type ‘!tapi-tbd‘ in YAML file...”

    比较长时间没使用MAC机器编译,系统更新也蛮快的,Xcode也都12了,然后简单make不能跑了.例如,想编译一份新的cmake,遇到"ld: unsupported tapi file t ...

  3. cmake编译出错:No CMAKE_CXX_COMPILER could be found.

    cmake编译出错:No CMAKE_CXX_COMPILER could be found. 错误类似: -- The CXX compiler identification is unknown- ...

  4. 由一次奇怪的编译出错想起的

    现象 最近在工作中遇到了一次奇怪的编译出错.事情是这样的,本来这个asp.net webform应用是可以编译的.但是将另外一个class library的工程加入到这个asp.net webform ...

  5. Xamarin.iOS编译出错

    Xamarin.iOS编译出错 错误信息:C:/Program Files(x86)/Reference Assemblies/Microsoft/Framework/Xamarin.iOS/v1.0 ...

  6. 编译出错libicui18n.so.58: undefined reference to `__cxa_throw_bad_array_new_length@CXXABI_1.3.8‘

    编译出错libicui18n.so.58: undefined reference to `__cxa_throw_bad_array_new_length@CXXABI_1.3.8' 环境 Ubun ...

  7. android 模块不编译错误,Android 编译出错版本匹配问题解决办法

    Android 编译出错版本匹配问题解决办法 解决问题的关键在于版本匹配, compileSdkVersion compileSdkVersion targetSdkVersion 这三个参数的整数值 ...

  8. saki4510t的UVCCamera设置匹配android7.1.1 sdk等信息后编译出错

    采用的代码来之于https://github.com/saki4510t/UVCCamera 此工程Sdk等版本信息定义 1.1 minSdkVersion 1.2 targetSdkVersion ...

  9. 杀毒软件引起的WinCE编译出错问题

    最近发现选择PB6.0的Rebuild Current BSP And Subprojects来编译整个BSP包的时候,基本都会弹出下面的编译出错信息: 图1 刚开始还以为是VS2005出问题了,就关 ...

最新文章

  1. 使用 U 盘制作 Ubuntu 系统启动盘
  2. 最小生成树之Kruskal算法
  3. nyist---组队赛(三)
  4. UWP 中的 LaunchUriAsync,使用默认浏览器或其他应用打开链接
  5. 安装Frida抓包工具
  6. python字典转dataframe_python DataFrame转dict字典过程详解
  7. BitCome比特彗星v1.82豪华版(bt下载)
  8. POJ1062昂贵的聘礼(经典) 枚举区间 +【Dijkstra】
  9. windows phone 扫描二维码
  10. 解决Xshell连接linux失败的问题
  11. 什么是CDA数据分析师认证考试?
  12. 共享服务器文件溢出,文件共享锁定数溢出
  13. 电能质量:电压暂升暂降中断
  14. 自定义 iPhone 铃声
  15. 360打开html乱码怎么办,360浏览器出现乱码怎么回事_360浏览器页面乱码如何解决-win7之家...
  16. 600度近视眼恢复方法_高度近视600度如何恢复视力?这三大办法
  17. 织梦DedeCMS搜索页面搜索结果总数调用方法
  18. fopen函数和文件权限
  19. 基于Ardupilot/PX4固件,APM/PIXhawk硬件的VTOL垂直起降固定翼软硬件参数调试(第三篇)故障保护及问题诊断
  20. python编程控制机器人_基于Python开发的微信图灵机器人

热门文章

  1. Web入门_朽木|学习笔记之第一章-数据库基本知识(1.1-1.7)
  2. MySQL 汉字提取首字母、姓名首字母全拼、姓名转拼音
  3. Windows7直接刻录ISO
  4. cocos2d-js
  5. 推荐开发工具系列之--PyF5(自动刷新)
  6. 苹果华为荣耀三家争鸣:谁在开启无边界之战?
  7. gcc编译 -I头文件目录 -L lib库目录 -l动态库文件
  8. 爬取了陈奕迅新歌《我们》10万条评论数据发现:原来,有些人只适合遇见
  9. SSM高新区产业与孵化企业管理毕业设计源码140940
  10. Android面试老生常谈的 View 事件分发机制,看这一篇就够了