webpack 4路径问题与图像和js文件

时间:2018-03-27 11:10:38

标签: webpack webpack-file-loader

我正在使用webpack 4,由于某种原因,我无法将.js文件放入名为/ js /的文件夹中,我的图像文件不会进入图像文件夹。这是我的webpack配置文件。理想情况下,看到图像保留源名称和路径名称会很棒。这是我的配置文件

    const HtmlWebPackPlugin = require("html-webpack-plugin");
    const path = require('path');

    module.exports = {

    entry: [
        './src/index.js'
    ],
    output: {
        path: path.resolve(__dirname, "public"), // string
        publicPath: 'js/',
        filename: "desktop.js"
    },

    module: {
        rules: [
        {
            test: /\.js$/,
            exclude: /node_modules/,
            use: {
            loader: "babel-loader?presets[]=es2015"
            }
        },

        {
            test: /\.(gif|png|jpe?g|svg)$/i,
            use: [
            'file-loader',
            {
                loader: 'image-webpack-loader',
                options: {
                name: '[path][name].[hash].[ext]',
                publicPath: '[path][name]',
                bypassOnDebug: true,
                },
            },
            ],
        },



        {
            test: /\.css$/,
            use: [ 'style-loader', 'css-loader' ]
        },



        {
            test: /\.html$/,
            use: [
            {
                loader: "html-loader",
                options: { minimize: false }
            }
            ]
        }
        ]
    },
    plugins: [
        new HtmlWebPackPlugin({
        template: "./src/index.html",
        filename: "./index.html"
        })
    ]
    };

0 个答案:

没有答案