zoukankan      html  css  js  c++  java
  • 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')
    ...
    

    使用 require.context自动加载模块

    使用: const files = require.context(directory, useSubdirectories, regExp)

    参数说明

    • directory:说明需要检索的目录
    • useSubdirectories:是否检索子目录
    • regExp: 匹配文件的正则表达式

    返回结果

    files.keys(): 符合条件的文件路径集合

    使用

    获取当前目录所有 js 文件并获取导出模块

    const files = require.context('.', true, /.js/)
    const modules = {}
    files.keys().forEach(key => {
      if (key === './index.js') {
        return
      }
      var mk = key.replace(/(^./|.js$)/g, '')
      var m = files(key)
      modules[mk] = Object.keys(m).reduce((s, e) => {
        if (e !== 'default') {
          s[e] = m[e]
        }
        return s
      }, m.default||{})
    })
    //console.log(modules)
    
  • 相关阅读:
    关于webpack的cdn配置
    谁都能听懂的Redux+Redux-Saga超级傻瓜教程
    记一个react拖动排序中的坑:key
    es6 解构写法:给变量取别名
    C++新型强制类型转换。
    C++ new、delete、namespace关键字。
    C++ 调用C语言、extern "C"、__cplusplus关键字
    C++ 重载函数
    liunx 环境下安装 Eclipse C++
    C++ 内联函数 inline关键字
  • 原文地址:https://www.cnblogs.com/morang/p/9074983.html
Copyright © 2011-2022 走看看