webpack4复制webpack插件错误:意外字符'@'

时间:2018-10-05 15:00:52

标签: javascript webpack-4

我已经解决了SO问题,似乎回答的问题仅与CSS / SASS模块规则有关。

我只是试图将文件(保留文件夹结构)从 src 复制到 public ,没有哈希等,所以我使用的是CopyWebpackPlugin-与Webpack中的相同3

const path = require('path');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');


module.exports = {
    entry: {
        app: './src/index.js'
    },
    output: {
        path: path.join(__dirname,'/public'),
        filename: 'bundle.js'
    },
    module: {
        rules: [
            {
                test: /\.js$/,
                exclude: /node_modules/,
                use: {
                    loader: 'babel-loader',
                    options: {
                        // plugins: ['transform-runtime'],
                        // presets: ['es2015','react']
                        // plugins: ['transform-class-properties']
                    }
                }
            },
            {
                test: /\.scss$/,
                use: ["style-loader","css-loader","sass-loader"]
            }
        ]
    },
    plugins: [
        new CleanWebpackPlugin(['public']),

        new HtmlWebpackPlugin({
            template: './src/index.html'
        }),

        new CopyWebpackPlugin([
        {from: 'images', to: 'images' },
            {context: 'images', from: '**/*', to: 'images' },
            {context: 'vendor', from: '**/*', to: 'vendor' },
            {context: 'data', from: '**/*', to: 'data' }
        ]),
    ]
};

有几个图像文件夹存储在src / images / **中。* 上面的CopyWebpackPlugin设置在Webpack3中工作正常,但我一直收到此错误:

  ./src/images/logos/logo-gs_transp-LT.png 1:0模块解析中的

错误   失败:意外字符'...'(1:0)您可能需要适当的字符   加载程序来处理此文件类型。

1 个答案:

答案 0 :(得分:0)

您需要添加一个加载器来处理图像文件类型。例如:

module: {
  rules: [{
   test: /\.(png|svg|jpe?g|gif|ico)$/,
   loader: 'file-loader',
  }]
}