为何popup.html中需要引用这些JS文件的Webpack配置?
P粉727531237
P粉727531237 2023-09-05 17:15:09
0
1
406
<p>我只想在<code>popup.html</code>中引用<code>popup.js</code>。然而,<code>content.js</code>和<code>background.js</code>也被引用在<code>popup.html</code>中。为什么会发生这种情况,我该如何修复?</p> <pre class="brush:js;toolbar:false;">const path = require('path') const HtmlWebpackPlugin = require('html-webpack-plugin') const CopyPlugin = require('copy-webpack-plugin') module.exports = { entry: { popup: './src/popup.tsx', content: './src/content.tsx', background: './src/background.ts', }, output: { filename: '[name].js', path: path.resolve(__dirname, 'dist') }, module: { rules: [{ test: /\.ts(x)?$/, use: 'ts-loader', exclude: /node_modules/ }] }, plugins: [ new HtmlWebpackPlugin({ template: './src/popup.html', filename: 'popup.html' }), new CopyPlugin({ patterns: [ { from: "public" } ] }) ] } </pre> <pre class="brush:html;toolbar:false;"><!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width,initial-scale=1"> <title>Document</title> <script defer="defer" src="popup.js"></script> <script defer="defer" src="content.js"></script> <script defer="defer" src="background.js"></script> </head> <body> <div id="react-target"></div> </body> </html> </pre> <p>为什么会这样,如何修复?</p>
P粉727531237
P粉727531237

全部回复(1)
P粉724737511

嗯,这很简单:

plugins: [
  new HtmlWebpackPlugin({
    chunks: ['content']
  })
]
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!