如何使用webpack将更多的html文件与更多的.js文件一起使用?

时间:2019-07-18 15:49:36

标签: javascript webpack

我需要创建以下内容:加载页面应该是带有login.js文件的login.html,然后是带有bundle.js的index.html。我该如何设置webpack来做到这一点? 目前,我有此配置:

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

module.exports = {
     entry: ['babel-polyfill', './src/js/index.js'],
    output: {
        path: path.resolve(__dirname, 'dist'),
        filename: 'js/bundle.js'
    },
    devServer: {
        contentBase: './dist'
    },
    plugins: [
        new HtmlWebpackPlugin({
            filename: 'index.html',
            template: './src/index.html'
        }),
        new HtmlWebpackPlugin({
            filename: "login.html",
            template: "./src/login.html"
        }),
        new webpack.ProvidePlugin({
            $: "jquery",
            jQuery: "jquery"
          })
    ],
    module: {
        rules: [
            {
                test: /\.js$/,
                exclude: /node_modules/,
                use: {
                    loader: 'babel-loader'
                }
            }
        ]
    }
};

0 个答案:

没有答案