首页 > 解决方案 > 通过 webpack 在 head 中添加 jquery 作为单独的文件

问题描述

有没有办法将 node_modules 中的脚本(例如 jquery)作为单独的文件添加到带有 webpack 的 <head> 标记中?这是我使用 HtmlWebpackPlugin 生成模板的部分,所以我想将脚本注入所有人

    let templates = fs.readdirSync('src/templates').filter(file => (path.extname(file) === '.html'))
    templates.map(page => {
        webpackConfiguration.plugins.push(new HtmlWebPackPlugin({
          template: 'src/templates/' + page,
          filename: page,
          hash: true
        }))
    })

我知道之前在 webpack 配置中有一个名为 headerScripts 的选项,但这似乎不起作用。

标签: jquerywebpack

解决方案


推荐阅读