webpack.config.js
const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: {
"index": "./src/js/index.ts",
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: "./js/[name].js"
},
plugins: [
new MiniCssExtractPlugin({
filename: './css/[name].css',
}),
new HtmlWebpackPlugin({
filename: "index.html",
template: "./src/index.html",
chunks: ["index"]
}),
],
module: {
rules: [
... 这里有配置scss img 等等
// {
// test: /\.(html)$/,
// use: 'raw-loader'
// }
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
mode: "production",
devServer: {
contentBase: path.join(__dirname, 'dist'),
compress: true,
port: 9000
}
};
index.html
<body>
<%= require('raw-loader!./base/header.html')%>
<%= require('html-loader!./base/header.html')%>
</body>
直接输出
[object Module] [object Module]
不知道 require
在引入这个base/header.html
发生了什么,为什么会输出[object Module],不管我有没有配置.html 使用 raw-loader
它都是同样的错误。请大神指点下,我是哪里配置错了,或者理解错了!!!谢谢!
package.json
webpack.config.js
html
非常感谢_usw 的回答 弄出来了就ok!!!