如何使用 Webpack 3、Typescript 和文件加载器加载索引.html文件?



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

我的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文件夹?

您可以使用html-webpack-plugin.

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

最新更新