vue+webpack实现vue项目多入口

需求:项目中需要在一个vue项目中实现多个入口

一般的vue项目入口文件是html.html,但是若是想要实现多入口文件,就需要通过webpack进行配置。实现过程如下:(以添加newEntry为例)
1.在项目根路径下添加newEntry.html文件,id=newEntry
2.在src文件下添加newEntry.js和NewEntry,vue文件,在newEntry.js引入NewEntry,vue文件。

new Vue({
        el: '#newEntry',
        router,
        store,
        render: h => h(NewEntry)
    }
)

3.配置开发环境webpack
打开build - webpack.base.conf.js文件,在entry中添加一条新的入口

    oneConnect: ["babel-polyfill", "./src/newEntry.js"],

打开build - webpack.dev.conf.js文件,在plugins中添加一条

    new HtmlWebpackPlugin({
      filename: 'newEntry.html',
      template: 'newEntry.html',
      inject: true,
      favicon: resolve('favicon.ico'),
      chunks:['newEntry'],
    }),

4.配置生产环境webpack
打开config - index.js文件,在build中添加

     newEntry: path.resolve(__dirname, '../dist/newEntry.html'),
      注意:dist为build中assetsRoot的文件名

打开build - webpack.prod.conf.js文件,在plugins中添加一条

    new HtmlWebpackPlugin({
      filename: config.build.newEntry,
      template: 'newEntry.html',
      inject: true,
      favicon: resolve('favicon.ico'),
      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:['newEntry']
    }),
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值