欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

webpack多入口打包示例代碼

 更新時(shí)間:2023年12月27日 10:20:39   作者:海上彼尚  
這篇文章主要介紹了webpack多入口打包的相關(guān)資料,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧

webpack多入口打包

首先得確定用webpack構(gòu)建的應(yīng)用,再然后后就是確定目錄。

這兩個(gè)js文件分別對(duì)應(yīng)兩個(gè)html文件,在 html中需要分別引入對(duì)應(yīng)的js文件。處理html中引入的問(wèn)題可以使用 html-webpack-plugin 這個(gè)插件。

配置:

module.exports = {
    entry: {
        index: path.resolve(__dirname, "./src/index.js"),
        map: path.resolve(__dirname, "./src/map.js"),
    },
    plugins: {
        new HtmlWebpackPlugin({
            template: path.resolve(__dirname, "./public/index.html"),
            filename: "index.html",
        }),
        new HtmlWebpackPlugin({
            template: path.resolve(__dirname, "./public/map.html"),
            filename: "map.html",
        }),
    }
}

webpack:打包示例-打包多入口

入口

entry: {
    // 前臺(tái)
    index: './public/assets/js/index',  //打包入口項(xiàng)
    list: './public/assets/js/list',
    search: './public/assets/js/search',
    detail: './public/assets/js/detail',
    jquery: './public/assets/vendors/jquery/jquery.min.js',
    // 后臺(tái)
  },

出口

  output: {
    path: path.join(__dirname, './dist'),
    filename: '[name].bundle.js',  //多入口寫(xiě)法--打包出同名文件
  },

對(duì)應(yīng)的插件

plugins: [
    //后臺(tái)
    //前臺(tái)
    new Webpack.ProvidePlugin({
      $: 'jquery'  //全局暴露的第三方庫(kù)      .不寫(xiě)內(nèi)置模塊的話,報(bào)$ is not defined
    }),
    new HtmlWebpackPlugin({
      filename: 'index.html',
      template: path.join(__dirname, './public/index.html'),
      chunks: ['index']          //多入口寫(xiě)法--按需導(dǎo)入
    }),
    new HtmlWebpackPlugin({
      filename: 'list.html',
      template: path.join(__dirname, './public/list.html'),
      chunks: ['list']
    }),
    new HtmlWebpackPlugin({
      filename: 'search.html',
      template: path.join(__dirname, './public/search.html'),
      chunks: ['search']
    }),
    new HtmlWebpackPlugin({
      filename: 'detail.html',
      template: path.join(__dirname, './public/detail.html'),
      chunks: ['detail']
    })
  ],

完整截圖

在這里插入圖片描述

在這里插入圖片描述

到此這篇關(guān)于webpack多入口打包的文章就介紹到這了,更多相關(guān)webpack多入口打包內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論