vue多页应用基于vue-cli2.0

实际是多个项目,多个入口在webpack打包时打包到一起

目录结构
* project
    * user
        * App.vue
        * user.index.html
        * user.main.js  // router直接在这里配置
    * goods
        * App.vue
        * goods.index.html
        * goods.main.js  // router直接在这里配置
// 配置webpack.base.config.js

module.exports = {
  entry: {  
  
    // 修改这里的入口entry
    
    "user.index": resolve('./src/project/user/user.main.js'),
    "goods.index": resolve('./src/project/goods/goods.main.js')
  },
  // 其他内容不修改
  output: {
    path: config.build.assetsRoot,
    filename: '[name].js',
    publicPath: process.env.NODE_ENV === 'production' ?
      config.build.assetsPublicPath :
      config.dev.assetsPublicPath
  },
配置 webpack.dev.conf.js

需要使用到new HtmlWebpackPlugin()这个插件
这个插件是修改生成html的

function GetHtmls () {
let files =[
    path.join(__dirname,'..','src/project/user/user.index.html'),
    path.join(__dirname,'..','src/project/goods/goods.index.html'),
]
    let plugins = [];
    let filenames = ['user.index','goods.index']
    for (let i=0;i< filenames.length;i++) {
        plugins.push(new HtmlWebpackPlugin({
            filename: filenames[i] + '.html',
            template: files[i],
            inject: true, // 是否注入对应的js
            chunks: ['manifest', 'vendor' , 'filenames[i]']  //这个配置使得每个入口index.html只引入自己的js
        }));
    }
    
    return plugins;
}


plugins: [
    new webpack.DefinePlugin({
      'process.env': require('../config/dev.env')
    }),
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NamedModulesPlugin(), // HMR shows correct file names in console on update.
    new webpack.NoEmitOnErrorsPlugin(),
    // 删除原来的此段配置
    // new HtmlWebpackPlugin({
    //  filename: 'index.html',
    //  template: 'index.html',
    //  inject: true
    // }),
    // copy custom static assets
    new CopyWebpackPlugin([
      {
        from: path.resolve(__dirname, '../static'),
        to: config.dev.assetsSubDirectory,
        ignore: ['.*']
      }
    ])
  ]    //在原来的配置最后追加上自己写的这个配置
  .concat(getHtmls())
// 配置 weback.prod.conf.js

和base同样的操作

只是
new HtmlWebpackPlugin({
  filename: filenames[i] + '.html',
  template: files[i],
  inject: true, // 是否注入对应的js
  chunks: ['manifest', 'vendor' , 'filenames[i]']    //这个配置使得每个入口index.html只引入自己的js
  minify: {
    removeComments: true,  //移除注释
    collapseWhitespace: true,   //空格合并
    removeAttributeQuotes: true   // 移除属性引号
  },
  chunksSortMode: 'dependency'
}),
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值