1. const path = require('path')
  2. const UglifyPlugin = require('uglifyjs-webpack-plugin')
  3.  
  4. module.exports = {
  5. publicPath: './', // 基本路径
  6. outputDir: 'dist', // 输出文件目录
  7. lintOnSave: false, // eslint-loader 是否在保存的时候检查
  8. // see https://github.com/vuejs/vue-cli/blob/dev/docs/webpack.md
  9. // webpack配置
  10. chainWebpack: (config) => {
  11. },
  12. configureWebpack: (config) => {
  13. if (process.env.NODE_ENV === 'production') {
  14. // 为生产环境修改配置...
  15. config.mode = 'production'
  16. // 将每个依赖包打包成单独的js文件
  17. let optimization = {
  18. runtimeChunk: 'single',
  19. splitChunks: {
  20. chunks: 'all',
  21. maxInitialRequests: Infinity,
  22. minSize: 20000,
  23. cacheGroups: {
  24. vendor: {
  25. test: /[\\/]node_modules[\\/]/,
  26. name (module) {
  27. // get the name. E.g. node_modules/packageName/not/this/part.js
  28. // or node_modules/packageName
  29. const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1]
  30. // npm package names are URL-safe, but some servers don't like @ symbols
  31. return `npm.${packageName.replace('@', '')}`
  32. }
  33. }
  34. }
  35. },
  36. minimizer: [new UglifyPlugin({
  37. uglifyOptions: {
  38. compress: {
  39. warnings: false,
  40. drop_console: true, // console
  41. drop_debugger: false,
  42. pure_funcs: ['console.log'] // 移除console
  43. }
  44. }
  45. })]
  46. }
  47. Object.assign(config, {
  48. optimization
  49. })
  50. } else {
  51. // 为开发环境修改配置...
  52. config.mode = 'development'
  53. }
  54. Object.assign(config, {
  55. // 开发生产共同配置
  56. resolve: {
  57. alias: {
  58. '@': path.resolve(__dirname, './src'),
  59. '@c': path.resolve(__dirname, './src/components'),
  60. '@p': path.resolve(__dirname, './src/pages')
  61. } // 别名配置
  62. }
  63. })
  64. },
  65. productionSourceMap: false, // 生产环境是否生成 sourceMap 文件
  66. // css相关配置
  67. css: {
  68. extract: true, // 是否使用css分离插件 ExtractTextPlugin
  69. sourceMap: false, // 开启 CSS source maps?
  70. loaderOptions: {
  71. css: {}, // 这里的选项会传递给 css-loader
  72. postcss: {} // 这里的选项会传递给 postcss-loader
  73. }, // css预设器配置项
  74. modules: false // 启用 CSS modules for all css / pre-processor files.
  75. },
  76. parallel: require('os').cpus().length > 1, // 是否为 Babel 或 TypeScript 使用 thread-loader。该选项在系统的 CPU 有多于一个内核时自动启用,仅作用于生产构建。
  77. pwa: {}, // PWA 插件相关配置 see https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-pwa
  78. // webpack-dev-server 相关配置
  79. devServer: {
  80. open: process.platform === 'darwin',
  81. host: '0.0.0.0', // 允许外部ip访问
  82. port: 2333, // 端口
  83. https: false, // 启用https
  84. overlay: {
  85. warnings: true,
  86. errors: true
  87. }, // 错误、警告在页面弹出
  88. proxy: {
  89. '/api': {
  90. target: 'http://www.baidu.com/api',
  91. changeOrigin: true, // 允许websockets跨域
  92. // ws: true,
  93. pathRewrite: {
  94. '^/api': ''
  95. }
  96. }
  97. } // 代理转发配置,用于调试环境
  98. },
  99. // 第三方插件配置
  100. pluginOptions: {}
  101. }

  

  1. module.exports = {
  2. baseUrl: process.env.NODE_ENV === 'production'
  3. ? '//your_url'
  4. : '/',
  5.  
  6. outputDir: 'dist',
  7.  
  8. assetsDir: 'static',
  9.  
  10. filenameHashing: true,
  11.  
  12. // When building in multi-pages mode, the webpack config will contain different plugins
  13. // (there will be multiple instances of html-webpack-plugin and preload-webpack-plugin).
  14. // Make sure to run vue inspect if you are trying to modify the options for those plugins.
  15. pages: {
  16. index: {
  17. // entry for the pages
  18. entry: 'src/pages/index/index.js',
  19. // the source template
  20. template: 'src/pages/index/index.html',
  21. // output as dist/index.html
  22. filename: 'index.html',
  23. // when using title option,
  24. // template title tag needs to be <title><%= htmlWebpackPlugin.options.title %></title>
  25. title: '首页',
  26. // chunks to include on this pages, by default includes
  27. // extracted common chunks and vendor chunks.
  28. chunks: ['chunk-vendors', 'chunk-common', 'index']
  29. }
  30. // when using the entry-only string format,
  31. // template is inferred to be `public/subpage.html`
  32. // and falls back to `public/index.html` if not found.
  33. // Output filename is inferred to be `subpage.html`.
  34. // subpage: ''
  35. },
  36.  
  37. // eslint-loader 是否在保存的时候检查
  38. lintOnSave: true,
  39.  
  40. // 是否使用包含运行时编译器的Vue核心的构建
  41. runtimeCompiler: false,
  42.  
  43. // 默认情况下 babel-loader 忽略其中的所有文件 node_modules
  44. transpileDependencies: [],
  45.  
  46. // 生产环境 sourceMap
  47. productionSourceMap: false,
  48.  
  49. // cors 相关 https://jakearchibald.com/2017/es-modules-in-browsers/#always-cors
  50. // corsUseCredentials: false,
  51. // webpack 配置,键值对象时会合并配置,为方法时会改写配置
  52. // https://cli.vuejs.org/guide/webpack.html#simple-configuration
  53. configureWebpack: (config) => {
  54. },
  55.  
  56. // webpack 链接 API,用于生成和修改 webapck 配置
  57. // https://github.com/mozilla-neutrino/webpack-chain
  58. chainWebpack: (config) => {
  59. // 因为是多页面,所以取消 chunks,每个页面只对应一个单独的 JS / CSS
  60. config.optimization
  61. .splitChunks({
  62. cacheGroups: {}
  63. });
  64.  
  65. // 'src/lib' 目录下为外部库文件,不参与 eslint 检测
  66. config.module
  67. .rule('eslint')
  68. .exclude
  69. .add('/Users/maybexia/Downloads/FE/community_built-in/src/lib')
  70. .end()
  71. },
  72.  
  73. // 配置高于chainWebpack中关于 css loader 的配置
  74. css: {
  75. // 是否开启支持 foo.module.css 样式
  76. modules: false,
  77.  
  78. // 是否使用 css 分离插件 ExtractTextPlugin,采用独立样式文件载入,不采用 <style> 方式内联至 html 文件中
  79. extract: true,
  80.  
  81. // 是否构建样式地图,false 将提高构建速度
  82. sourceMap: false,
  83.  
  84. // css预设器配置项
  85. loaderOptions: {
  86. css: {
  87. // options here will be passed to css-loader
  88. },
  89.  
  90. postcss: {
  91. // options here will be passed to postcss-loader
  92. }
  93. }
  94. },
  95.  
  96. // All options for webpack-dev-server are supported
  97. // https://webpack.js.org/configuration/dev-server/
  98. devServer: {
  99. open: true,
  100.  
  101. host: '127.0.0.1',
  102.  
  103. port: 3000,
  104.  
  105. https: false,
  106.  
  107. hotOnly: false,
  108.  
  109. proxy: null,
  110.  
  111. before: app => {
  112. }
  113. },
  114. // 构建时开启多进程处理 babel 编译
  115. parallel: require('os').cpus().length > 1,
  116.  
  117. // https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-pwa
  118. pwa: {},
  119.  
  120. // 第三方插件配置
  121. pluginOptions: {}
  122. };

  

  1. module.exports = {
  2. // 部署应用时的基本 URL
  3. baseUrl: process.env.NODE_ENV === 'production' ? '192.168.60.110:8080' : '192.168.60.110:8080',
  4. // build时构建文件的目录 构建时传入 --no-clean 可关闭该行为
  5. outputDir: 'dist',
  6. // build时放置生成的静态资源 (js、css、img、fonts) 的 (相对于 outputDir 的) 目录
  7. assetsDir: '',
  8. // 指定生成的 index.html 的输出路径 (相对于 outputDir)。也可以是一个绝对路径。
  9. indexPath: 'index.html',
  10. // 默认在生成的静态资源文件名中包含hash以控制缓存
  11. filenameHashing: true,
  12. // 构建多页面应用,页面的配置
  13. pages: {
  14. index: {
  15. // page 的入口
  16. entry: 'src/index/main.js',
  17. // 模板来源
  18. template: 'public/index.html',
  19. // 在 dist/index.html 的输出
  20. filename: 'index.html',
  21. // 当使用 title 选项时,template 中的 title 标签需要是 <title><%= htmlWebpackPlugin.options.title %></title>
  22. title: 'Index Page',
  23. // 在这个页面中包含的块,默认情况下会包含
  24. // 提取出来的通用 chunk 和 vendor chunk。
  25. chunks: ['chunk-vendors', 'chunk-common', 'index']
  26. },
  27. // 当使用只有入口的字符串格式时,模板会被推导为 `public/subpage.html`,并且如果找不到的话,就回退到 `public/index.html`。
  28. // 输出文件名会被推导为 `subpage.html`。
  29. subpage: 'src/subpage/main.js'
  30. },
  31. // 是否在开发环境下通过 eslint-loader 在每次保存时 lint 代码 (在生产构建时禁用 eslint-loader)
  32. lintOnSave: process.env.NODE_ENV !== 'production',
  33. // 是否使用包含运行时编译器的 Vue 构建版本
  34. runtimeCompiler: false,
  35. // Babel 显式转译列表
  36. transpileDependencies: [],
  37. // 如果你不需要生产环境的 source map,可以将其设置为 false 以加速生产环境构建
  38. productionSourceMap: true,
  39. // 设置生成的 HTML 中 <link rel="stylesheet"> 和 <script> 标签的 crossorigin 属性(注:仅影响构建时注入的标签)
  40.  
  41. crossorigin: '',
  42. // 在生成的 HTML 中的 <link rel="stylesheet"> 和 <script> 标签上启用 Subresource Integrity (SRI)
  43. integrity: false,
  44. // 如果这个值是一个对象,则会通过 webpack-merge 合并到最终的配置中
  45. // 如果你需要基于环境有条件地配置行为,或者想要直接修改配置,那就换成一个函数 (该函数会在环境变量被设置之后懒执行)。该方法的第一个参数会收到已经解析好的配置。在函数内,你可以直接修改配置,或者返回一个将会被合并的对象
  46. configureWebpack: {},
  47. // 对内部的 webpack 配置(比如修改、增加Loader选项)(链式操作)
  48. chainWebpack: () => { },
  49. // css的处理
  50. css: {
  51. // 当为true时,css文件名可省略 module 默认为 false
  52. modules: true,
  53. // 是否将组件中的 CSS 提取至一个独立的 CSS 文件中,当作为一个库构建时,你也可以将其设置为 false 免得用户自己导入 CSS
  54. // 默认生产环境下是 true,开发环境下是 false
  55. extract: false,
  56. // 是否为 CSS 开启 source map。设置为 true 之后可能会影响构建的性能
  57. sourceMap: false,
  58. //向 CSS 相关的 loader 传递选项(支持 css-loader postcss-loader sass-loader less-loader stylus-loader)
  59. loaderOptions: { css: {}, less: {} }
  60. },
  61. // 所有 webpack-dev-server 的选项都支持
  62. devServer: {},
  63. // 是否为 Babel 或 TypeScript 使用 thread-loader
  64. parallel: require('os').cpus().length > 1,
  65. // 向 PWA 插件传递选项
  66. pwa: {},
  67. // 可以用来传递任何第三方插件选项
  68. pluginOptions: {}
  69. }

  

vue.config.js基础配置的更多相关文章

  1. vue.config.js常用配置

    使用vue-cli3.0搭建项目比之前更简洁,没有了build和config文件夹. vue-cli3的一些服务配置都迁移到CLI Service里面了,对于一些基础配置和一些扩展配置需要在根目录新建 ...

  2. vue-cli3的vue.config.js文件配置,生成dist文件

    //vue.config.jsonconst path = require('path'); // const vConsolePlugin = require('vconsole-webpack-p ...

  3. vue.config.js初始化配置

    let path = require('path')function resolve (dir) { return path.join(__dirname, dir)} module.exports ...

  4. 【vue-cli 3.0】 vue.config.js配置 - 路径别名

    如何配置vue-cli 3中vue.config.js的路径别名? 前段时间更新电脑重装了一下vue-cli,发现了vue-cli已经更新到3.0版.用来搭建项目后发现简化了很多,而且配置文件现在可以 ...

  5. vue3.0 vue.config.js 配置实战

    今天讲述一下vue-config.js配置,我们前面搭建好脚手架会发现,这个对比2.x版本少了很多东西,没有build的配置,也没有webpack的配置,那么问题来了,我们如何去开发我们的项目呢,比如 ...

  6. vue cli3.3 以上版本配置vue.config.js

    // vue.config.js 配置说明//官方vue.config.js 参考文档 https://cli.vuejs.org/zh/config/#css-loaderoptions// 这里只 ...

  7. vue.config.js配置前端代理

    // vue.config.js 配置说明 //官方vue.config.js 参考文档 https://cli.vuejs.org/zh/config/#css-loaderoptions // 这 ...

  8. Vue-cli3 项目配置 Vue.config.js( 代替vue-cli2 build config)

    Vue-cli3 搭建的项目 界面相对之前较为简洁 之前的build和config文件夹不见了,那么应该如何配置 如webpack等的配那 只需要在项目的根目录下新建 vue.config.js 文件 ...

  9. vue cli 中关于vue.config.js中chainWebpack的配置

    Vue CLI  的官方文档上写:调整webpack配置最简单的方式就是在vue.config.js中的configureWebpack选项提供一个对象. Vue CLI 内部的 webpack 配置 ...

随机推荐

  1. IE浏览器URL中的查询条件中包含中文时报404的解决办法

    情况是比如我输入如下URL到IE浏览器: http://localhost:8090/RPT_TYSH_JL_ZD_DETAIL.html?pageIndex=1&year=2018& ...

  2. golang web框架设计6:上下文设计

    context,翻译为上下文,为什么要设计这个结构?就是把http的请求和响应,以及参数结合在一起,便于集中处理信息,以后框架的扩展等.好多框架比如gin,都是有这个上下文结构. context结构为 ...

  3. ubuntu下删除带锁文件夹

    1.终端下,cd 到要删带锁文件夹所在目录 2.输入 + 带锁文件夹名称 输入用户密码,解锁成功 3.现在该文件可以进行移动或者删除

  4. Bootstrap 控制台示例

    1.打开https://getbootstrap.com/docs/4.3/examples/ 2.选择Dashboard 3.右键查看源代码,另存为 4.通过源代码界面下载JS和CSS 5.修改绝对 ...

  5. CMake速记

    目录 CMake速记 我的demo 外部构建 基础语法 常用指令 环境变量 一些变量 参考文档 title: CMake速记 date: 2019/11/18 19:17:40 toc: true - ...

  6. 跨域跨域跨域,从此say goodbye

    跨域这个问题每个开发者都会遇到,只是时间先后而已,你不搞清楚它他就像狗皮膏药一样粘着你,在你求职生涯中不停的遇到,然后你每次都要做这个功课,终于有一天这个名词已经让我忍无可忍了,下定决心必须搞定它,要 ...

  7. 幻数浅析(Magic Number)

    在源代码编写中,有这么一种情况:编码者在写源代码的时候,使用了一个数字,比如0x2123,0.021f等,他当时是明白这个数字的意思的,但是别的程序员看他的代码,可能很难理解,甚至,过了一段时间,代码 ...

  8. nginx 开启gzip压缩

    Nginx开启Gzip压缩功能, 可以使网站的css.js .xml.html 文件在传输时进行压缩,提高访问速度,!  Web网站上的图片,视频等其它多媒体文件以及大文件,因为压缩效果不好,所以对于 ...

  9. 【转帖】Linux上搭建Samba,实现windows与Linux文件数据同步

    Linux上搭建Samba,实现windows与Linux文件数据同步 2018年06月09日 :: m_nanle_xiaobudiu 阅读数 15812更多 分类专栏: Linux Samba 版 ...

  10. Spring实例化Bean三种方法:构造器、静态工厂、实例工厂

    Spring中Bean相当于java中的类,可以通过xml文件对bean进行配置和管理. 一.Bean的实例化: 构造器实例化.静态工厂实例化.实例工厂方式实例化. 目录: 构造器实例化: xml配置 ...