我使用 webpack 運行我的 Three.js 應用程序,在 webpack.config 文件中具有以下配置:module.exports = { entry: `${__dirname}/src/tut15.js`, output: { path: __dirname + '/dist', filename: 'index_bundle.js' }, devtool: 'inline-source-map', devServer: { contentBase: path.join(__dirname, 'dist'), compress: true, port: 9000 }, plugins: [ new HtmlWebpackPlugin() ]}包.json "scripts": { "start": "webpack-dev-server --open", "build": "webpack --config webpack.config.babel.js", "test": "echo \"Error: no test specified\" && exit 1" },使用HtmlWebpackPlugin它會為我自動生成 html。但是因為我想創建一個帶有一些新標簽的自定義 html 索引文件,所以這對我不起作用。所以我建立了這個項目npm run-script build并使用我應用的編輯手動運行 dist 文件夾中的 index.html,一切正常。如果我從 webpack.config 中刪除 HtmlWebpackPlugin 并再次構建項目然后運行:npm startlivereload 適用于我的 js 文件以及我在 distfolder 中帶有自定義標簽的新 index.html。問題:在 dist 文件夾中創建更改感覺不正確。如何直接從源代碼生成 index.html?我想這可能會解決我能夠使用自定義 index.html 運行開發服務器的所有問題或者是否也可以為構建獲得一些 livereload?在我構建項目后,它會在我的 distfolder 中生成 index.html 和 index.bundle。如果我刪除 index.bundle,該項目仍然有效。index.bundle 究竟做了什么?什么是最好的方法,或者每次我在索引文件中進行更新時都需要構建我的項目?謝謝!
使用 webpack 構建 index.html 以與開發服務器一起使用
牧羊人nacy
2023-02-17 17:28:46