gpt4 book ai didi

webpack - HtmlWebpackPlugin 不输出任何内容

转载 作者:行者123 更新时间:2023-12-02 16:14:39 25 4
gpt4 key购买 nike

HtmlWebpackPlugin 不会向 webpack 输出目录输出任何内容:我有这样的设置:

var config = {
context: __dirname + '/client',
entry: {
main: [
"./app.js"
]
},
output: {
path: __dirname + "./public",
filename: "dist.js"
},
devtool: "source-map",
module: {
loaders: [
{
test: /\.js?$/,
loader: 'babel-loader',
include: [
path.resolve(__dirname, 'client'),
],
exclude: /node_modules/

},
{
test: /\.less$/,
loader: "style!css!less"
},
{
test: /\.css/,
loader: "style!css"
}
]
},
resolve: {
// you can now require('file') instead of require('file.js')
extensions: ['', '.js', '.json']
},
plugins: [
new HtmlWebpackPlugin({
title: 'Webpack demo'
})
]
}

但是没有向公众输出index.html 文件。

我刚刚收到此消息:

      Asset       Size  Chunks             Chunk Names
dist.js 530 kB 0 [emitted] main
dist.js.map 638 kB 0 [emitted] main
index.html 181 bytes [emitted]
[0] multi main 28 bytes {0} [built]
+ 130 hidden modules
Child html-webpack-plugin for "index.html":
+ 3 hidden modules

最佳答案

HtmlWebpackPlugin 简化了 HTML 文件的创建来为您的 webpack 包提供服务。这对于在 filename 中包含 hash 的 webpack bundle 特别有用,该哈希值会更改每个编译。您可以让插件为您生成 HTML 文件,使用 lodash 模板提供您自己的模板,或者使用您自己的加载器

wbpack.config.js

const HtmlWebpackPlugin = require('html-webpack-plugin');
const path=require('path');

var webpackConfig = {
entry: './src/index.js',
output: {
path:path.resolve(__dirname,'dist'),
filename: 'index_bundle.js'
},
plugins: [new HtmlWebpackPlugin()]
};

module.exports = webpackConfig;

输出:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Webpack App</title>
</head>
<body>
<script type="text/javascript" src="index_bundle.js"></script></body>
</html>

你也可以像这样进行定制 configuration

new HtmlWebpackPlugin({
title:'sample text',
filename:'sample.index'
)

关于webpack - HtmlWebpackPlugin 不输出任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39003326/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com