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

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}),
]

解決方法:css

將webpack-build.config.js 配置改成:node

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

問題就解決了。具體緣由好像是版本的寫法問題。webpack

相關文章
相關標籤/搜索