日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

webpack 多页面 html,webpack打包多页应用,如何处理不同html页面(通过a标签)之间的跳转?...

發布時間:2025/3/19 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 webpack 多页面 html,webpack打包多页应用,如何处理不同html页面(通过a标签)之间的跳转?... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

想試著用

webpack

打包多頁(多個html文件)應用,不同html之間(利用a標簽)跳轉只和項目文件結構路徑相關,但是打包后發現頁面之間跳轉都是

404

了!

源碼地址:

https://gitee.com/qingyun1029/webpack-for-multiple-page-demo

使用方式:

克隆項目到本地

git clone git@gitee.com:qingyun1029/webpack-for-multiple-page-demo.git

安裝依賴模塊

npm install

打包代碼

npm run build

問題重現:打包后,打開

dist/index.html

,點擊頁面上的鏈接,無法跳轉到

about

頁面;反之亦然!

分析:

頁面之間的跳轉路徑唯一相關的是項目文件路徑結構,但是通過

webpack

打包后,輸出的路徑肯定和源碼中寫的路徑不一樣的(通常源碼頁面放在

src

文件夾下面,但是打包后肯定不希望有這層路徑吧!),所以我該怎么處理這一層關系呢?

期望:

通過

webpack

打包后的文件路徑能夠比較靈活的自定義;

頁面之間能夠正常跳轉;

webpack

配置如下:

'use strict'

const webpack = require('webpack')

const path = require('path')

const HtmlWebpackPlugin = require('html-webpack-plugin')

module.exports = {

mode: 'production',

entry: {

home: './src/pages/home/index.js',

about: './src/pages/about/index.js',

},

output: {

path: path.resolve(__dirname, './dist'),

filename: '[name].[chunkhash].js',

},

resolve: {

extensions: ['.js', '.json'],

},

module: {

},

plugins: [

new HtmlWebpackPlugin({

chunks: ['home'],

filename: 'home.html',

template: 'src/pages/home/html/index.html',

inject: true,

minify: {

removeComments: true,

collapseWhitespace: true,

},

}),

new HtmlWebpackPlugin({

chunks: ['about'],

filename: 'about.html',

template: 'src/pages/about/html/index.html',

inject: true,

minify: {

removeComments: true,

collapseWhitespace: true,

},

}),

],

}

總結

以上是生活随笔為你收集整理的webpack 多页面 html,webpack打包多页应用,如何处理不同html页面(通过a标签)之间的跳转?...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。