webpack 3.8 使用 extract-text-webpack-plugin 3.0 抽取css失敗:You may need an appropriate loader to handle this file type.


webpack 3.8.1 使用 extract-text-webpack-plugin 3.0.2 抽取css時失敗,報錯:

ERROR in ./src/static/style/localTime.css
 Module parse failed: Unexpected token (1:0)
 You may need an appropriate loader to handle this file type.
 | .localTimeBox {
 | color: red;
 | }
 @ ./node_modules/style-loader!./src/static/style/localTime.css 4:14-42


webpack-build.config.js 配置為:
module: {
    loaders: [
        {
           test: /\.css$/,
           loader: ExtractTextPlugin.extract('style-loader', 'style-loader!css-loader', {publicPath: '../'})
        }
     ]
},
plugins: [
    new ExtractTextPlugin('css/bundle.min.css', {allChunks: true}),
]

解決方法:

將webpack-build.config.js 配置改為:

module: {
    loaders: [
       {
          test: /\.css$/,
          loader: ExtractTextPlugin.extract({
              fallback: 'style-loader',
              use: ['css-loader'],
              publicPath: '../'
          })
       }
    ]
},
plugins: [
    new ExtractTextPlugin('css/bundle.min.css', {allChunks: true}),
]
 

問題就解決了。具體原因好像是版本的寫法問題。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM