Search code examples
typescriptwebpackwebpack-file-loaderwebpack-3

How to load an index.html file with Webpack 3, Typescript and file-loader?


I try to load my index.html file via the file-loader and Webpack 3.

My webpack.config.tslooks like this:

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;

Unfortunately it doesn't load my src/index.html file to the dist folder. What am I doing wrong? How can I get the index file from the src folder to the dist folder?


Solution

  • You can use html-webpack-plugin.

    {
      plugins: [
        new HtmlWebpackPlugin({
          template: 'src/index.html'
        })
      ]
    }