vue 实践记录

打包后使用相对路径

build/webpack.prod.conf.js 的 output 节点添加配置:publicPath: './'

打包时使用shell复制文件

在入口 build/build.js 中使用.

  1. 引入 shelljs库 require('shelljs/global')
  2. 使用示例:cp('-R', 'favicon.ico', config.build.assetsRoot)

不同环境使用不同模式加载路由( vue 开发环境不适用懒加载)

router目录结构

  • _import_production.js 代码
    module.exports = file => () => import('@/views/' + file + '.vue')

  • _import_testing.js 代码
    module.exports = file => () => import('@/views/' + file + '.vue')

  • _import_development.js 代码
    module.exports = file => require('@/views/' + file + '.vue').default

  • 路由中使用

    const _import = require('./_import_' + process.env.NODE_ENV)
    ...
        component: _import('dashboard/index')
    ...

猜你喜欢

转载自www.cnblogs.com/morang/p/9074983.html