2

我尝试通过和 Webpack 3加载我的index.html文件。file-loader

我的webpack.config.ts样子是这样的:

import * as webpack from 'webpack';

const config: webpack.Configuration = {
    entry: "./src/app.tsx",
    output: {
        filename: "bundle.js",
        path: __dirname + "/dist"
    },

    devtool: "source-map",

    resolve: {
        extensions: [".webpack.js", ".web.js", ".ts", ".tsx", ".js", ".html"]
    },

    module: {
        rules: [
            {
                test: /\.tsx?$/,
                loader: "awesome-typescript-loader"
            }, {
                test: /\.html$/,
                loader: "file-loader"
            }
        ]
    }
};

export default config;

不幸的是,它不会将我src/index.html的文件加载到dist文件夹中。我究竟做错了什么?如何从文件夹中获取索引文件到src文件dist夹?

4

1 回答 1

2

您可以使用html-webpack-plugin.

{
  plugins: [
    new HtmlWebpackPlugin({
      template: 'src/index.html'
    })
  ]
}
于 2017-07-05T18:51:32.560 回答