国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

詳解如何使用 vue-cli 開發(fā)多頁應(yīng)用

2024-05-06 15:23:32
字體:
供稿:網(wǎng)友

本文介紹了如何使用 vue-cli 開發(fā)多頁應(yīng)用,分享給大家,具體如下:

修改的webpack配置文件

全局配置

修改 webpack.base.conf.js

打開 ~/build/webpack.base.conf.js ,找到entry,添加多入口

entry: {  app: './src/main.js',  app2: './src/main2.js',  app3: './src/main3.js',},

運行、編譯的時候每一個入口都會對應(yīng)一個Chunk

run dev 開發(fā)環(huán)境

修改 webpack.dev.conf.js

打開 ~/build/webpack.dev.conf.js ,在plugins下找到new HtmlWebpackPlugin,在其后面添加對應(yīng)的多頁,并為每個頁面添加Chunk配置

chunks: ['app']中的app對應(yīng)的是webpack.base.conf.js中entry設(shè)置的入口文件

plugins:[  // https://github.com/ampedandwired/html-webpack-plugin  // 多頁:index.html → app.js  new HtmlWebpackPlugin({   filename: 'index.html',//生成的html   template: 'index.html',//來源html   inject: true,//是否開啟注入   chunks: ['app']//需要引入的Chunk,不配置就會引入所有頁面的資源  }),  // 多頁:index2.html → app2.js  new HtmlWebpackPlugin({   filename: 'index2.html',//生成的html   template: 'index2.html',//來源html   inject: true,//是否開啟注入   chunks: ['app2']//需要引入的Chunk,不配置就會引入所有頁面的資源  }),  // 多頁:index3.html → app3.js  new HtmlWebpackPlugin({   filename: 'index3.html',//生成的html   template: 'index3.html',//來源html   inject: true,//是否開啟注入   chunks: ['app3']//需要引入的Chunk,不配置就會引入所有頁面的資源  })]

run build 編譯

修改 config/index.js

打開~/config/index.js,找到build下的index: path.resolve(__dirname, '../dist/index.html'),在其后添加多頁

build: {  index: path.resolve(__dirname, '../dist/index.html'),  index2: path.resolve(__dirname, '../dist/index2.html'),  index3: path.resolve(__dirname, '../dist/index3.html'),},

修改 webpack.prod.conf.js

打開~/build/webpack.prod.conf.js,在plugins下找到new HtmlWebpackPlugin,在其后面添加對應(yīng)的多頁,并為每個頁面添加Chunk配置

HtmlWebpackPlugin 中的 filename 引用的是 config/index.js 中對應(yīng)的 build

plugins: [  // 多頁:index.html → app.js  new HtmlWebpackPlugin({    filename: config.build.index,    template: 'index.html',    inject: true,    minify: {      removeComments: true,      collapseWhitespace: true,      removeAttributeQuotes: true      // more options:      // https://github.com/kangax/html-minifier#options-quick-reference    },    // necessary to consistently work with multiple chunks via CommonsChunkPlugin    chunksSortMode: 'dependency',    chunks: ['manifest','vendor','app']//需要引入的Chunk,不配置就會引入所有頁面的資源  }),  // 多頁:index2.html → app2.js  new HtmlWebpackPlugin({    filename: config.build.index2,    template: 'index2.html',    inject: true,    minify: {      removeComments: true,      collapseWhitespace: true,      removeAttributeQuotes: true    },    chunksSortMode: 'dependency',    chunks: ['manifest','vendor','app2']//需要引入的Chunk,不配置就會引入所有頁面的資源  }),  // 多頁:index3.html → app3.js  new HtmlWebpackPlugin({    filename: config.build.index3,    template: 'index3.html',    inject: true,    minify: {      removeComments: true,      collapseWhitespace: true,      removeAttributeQuotes: true    },    chunksSortMode: 'dependency',    chunks: ['manifest','vendor','app3']//需要引入的Chunk,不配置就會引入所有頁面的資源  }),]            
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 中山市| 景东| 丰顺县| 隆林| 富蕴县| 竹山县| 横峰县| 梁河县| 南宫市| 屯昌县| 定州市| 海林市| 佛学| 将乐县| 竹山县| 玉屏| 伊吾县| 文登市| 南通市| 大埔区| 新津县| 沂源县| 遵化市| 祁门县| 襄汾县| 河西区| 冷水江市| 山阴县| 贵阳市| 高平市| 灵石县| 阳城县| 呼伦贝尔市| 化德县| 禹城市| 杭州市| 岑溪市| 扎鲁特旗| 芜湖市| 潼关县| 苗栗市|