Webpack会自动在body标签的末尾插入transformable.js。我想在<script src="transformable.js"></script>之后有一个脚本。我如何才能做到这一点?
这是我的结构:

我希望这样做,即首先加载transformable.js,然后使用脚本标记:

这是我的webpack配置:
import path from "path"
import HtmlWebpackPlugin from "html-webpack-plugin"
export default {
entry: "./src/index.ts",
module: {
rules: [
{
test: /\.tsx?$/,
loader: "babel-loader"
}
]
},
plugins: [
new HtmlWebpackPlugin({
template: "./src/index.html"
})
],
output: {
path: path.resolve(__dirname, "dist"),
filename: "transformable.js",
sourceMapFilename: "[name].js.map"
},
devtool: "source-map"
}发布于 2020-11-29 16:46:25
HTMLWebpackPlugin是一个注入脚本和样式标签的工具,你可以禁用这个行为,并使用内置的标签来定位你想要的标签。
<!DOCTYPE html>
<html>
<head>
<%= htmlWebpackPlugin.tags.headTags %>
<title>Custom insertion example</title>
</head>
<body>
All scripts are placed here:
<%= htmlWebpackPlugin.tags.bodyTags %>
<script>console.log("Executed after all other scripts")</script>
</body>
</html>// webpack.config.js
module.exports = {
context: __dirname,
entry: './example.js',
output: {
path: path.join(__dirname, 'dist/webpack-' + webpackMajorVersion),
publicPath: '',
filename: 'bundle.js'
},
plugins: [
new HtmlWebpackPlugin({
template: 'index.html',
inject: false, // <--- this disables the default injection
})
]
};https://stackoverflow.com/questions/65049193
复制相似问题