Vue-cli项目搭建—进阶

本文详细介绍如何在Vue项目中设置多个入口,包括创建额外的HTML、Vue组件和路由文件,以及修改webpack配置来支持多入口打包,适用于需要分离不同设备或场景页面的项目。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一. 项目多入口

1. 创建第二个入口的文件

与第一个入口的一样

-- index_mobile.html
    src
	    -- App_mobile.vue
	    -- main_mobile.vue (代码里面修改引用的文件名)
	    router
	    	  -- index_mobile.js

2. 修改配置文件

(1) 修改 build/webpack.base.conf.js

module.exports = {
  entry: {
    ...,
    mobile: ["babel-polyfill", "./src/main_mobile.js"] //新增
  },

(2) 修改 build/webpack.dev.conf.js

const devWebpackConfig = merge(baseWebpackConfig, {
	...
	plugins: [
		...
		new HtmlWebpackPlugin({  
	      ...
	      chunks: ['app'] //修改
	    }),
		new HtmlWebpackPlugin({  //新增
	      filename: 'index_mobile.html',
	      template: 'index_mobile.html',
	      inject: true,
	      chunks: ['mobile']
	    })

(3) 修改 build/webpack.prod.conf.js

const webpackConfig = merge(baseWebpackConfig, {
	...
	plugins: [
		...
		new HtmlWebpackPlugin({
	      ...
	      chunks: ['manifest', 'vendor', 'app'] //修改
	    }),
	    new HtmlWebpackPlugin({   //新增
	      filename: process.env.NODE_ENV === 'testing'
	        ? 'index_mobile.html'
	        : config.build.mobile,
	      template: 'index_mobile.html',
	      inject: true,
	      minify: {
	        removeComments: true,
	        collapseWhitespace: true,
	        removeAttributeQuotes: true
	      },
	      chunksSortMode: 'dependency',
	      chunks: ['manifest', 'vendor', 'mobile']
	    })

(4) 修改 config/index.js

module.exports = {
   ...
   build: {
    ...
    mobile: path.resolve(__dirname, '../dist/index_mobile.html'), //新增
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值