Maison  >  Questions et réponses  >  le corps du texte

javascript - 如何在webpack项目中引入第三方类库?

相似问题:https://segmentfault.com/q/10...

比如现在我要创建一个jQuery项目,我通过

npm install jquery

将jquery安装在本地。
现在我在配置文件中配置了一个HtmlWebpackPlugin自动生成一个html页面,可以将打包好的js文件直接引入到html页面中,非常方便。
现在我希望, 可以将jquery直接通过script自动添加到这个自动生成的html页面中,而不需要打包,能否实现呢?

PHP中文网PHP中文网2727 Il y a quelques jours242

répondre à tous(2)je répondrai

  • PHP中文网

    PHP中文网2017-04-11 13:00:52

    文档里不写了吗,你可以基于一个模板生成html
    https://github.com/ampedandwi...

    plugins: [
      new HtmlWebpackPlugin({
        title: 'Custom template',
        template: 'my-index.ejs', // Load a custom template (ejs by default see the FAQ for details)
      })
    ]
    <!DOCTYPE html>
    <html>
      <head>
        <meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
        <title><%= htmlWebpackPlugin.options.title %></title>
      </head>
      <body>
      </body>
    </html>

    在模版里直接通过script标签把jquery引入进来

    répondre
    0
  • 迷茫

    迷茫2017-04-11 13:00:52

    entry: {
        page: 'path/to/page.js',
        jquery: 'node_modules/jquery/dist/jquery.min.js'
    }
    new HtmlWebpackPlugin({
        filename: 'index.html',
        template: 'index.html',
        inject: true,
        chunks: ['jquery', 'page'] // 按照先后顺序插入script标签
      })

    répondre
    0
  • Annulerrépondre