如何使用 Webpack 3、TypeScript 和 file-loader 加载 index.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 文件夹中的 index 文件放到 dist 文件夹中?
答案#1
你可以使用 html-webpack-plugin。
{
plugins: [
new HtmlWebpackPlugin({
template: 'src/index.html'
})
]
}
