Webpack-dev-server 不使用 HtmlWebpackPlugin 選項中的模板
我確定我錯過了一些簡單的東西,但我看不到它......我正在使用一個 HtmlWebPlugin 實例,每個頁面/入口點都有一個模板。當我使用 webpack-dev-server 只有第一個實例實際上尊重模板中的內容時,其余的只使用簡單的 html 和 meta 標簽將文件寫入磁盤,無論是通過將 WriteFilePlugin 與開發服務器一起使用,還是通過簡單地在沒有開發服務器的情況下構建文件,都可以正確使用模板。我很難過。預期: about.html/index.html 這是我使用 write-file-webpack-plugin 和運行'webpack --config webpack.config.js'. Index.html 是相同的。<!DOCTYPE html><html><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>About</title></head><body> <p>About</p></body></html>Webpack-dev-server 的實際輸出:(查看頁面源代碼)<!DOCTYPE html><html> <head> <meta charset="utf-8"/> </head> <body> <script type="text/javascript" charset="utf-8" src="/about.js"></script> </body></html>配置:webpack.config.jsconst HtmlWebpackPlugin = require('html-webpack-plugin');const WriteFilePlugin = require('write-file-webpack-plugin');const path = require('path');module.exports = { entry: { index: './src/js/index.js', about: './src/js/about.js' }, output: { path: path.resolve(__dirname, 'dist'), filename: '[name].js' }, module: { rules: [ { test: /\.css$/, use: ['style-loader', 'css-loader'] }, { test: /\.html$/, use: 'html-loader' } ] }, devServer: { openPage: 'about' }, plugins: [ new WriteFilePlugin(), new HtmlWebpackPlugin({ filename: 'index.html', template: 'src/index.ejs', chunks: ['index'] }), new HtmlWebpackPlugin({ filename: 'about.html', template: 'src/about.ejs', chunks: ['about'] }), ]};我看不出有什么明顯的錯誤,但是我是多頁面和 webpack 的新手
查看完整描述