Shenglian / -WORK_TIP

工作上小技巧
4 stars 1 forks source link

[vue-cli] default setting #148

Open Shenglian opened 5 years ago

Shenglian commented 5 years ago
module.exports = {
  // 基本路徑
  baseUrl: '/',
  // 輸出文件目錄
  outputDir: 'dist',
  // eslint-loader 是否在保存的時候檢查
  lintOnSave: true,
  // use the full build with in-browser compiler?
  // https://vuejs.org/v2/guide/installation.html#Runtime-Compiler-vs-Runtime-only
  compiler: false,
  // webpack配置
  // see https://github.com/vuejs/vue-cli/blob/dev/docs/webpack.md
  chainWebpack: () => {},
  configureWebpack: () => {},
  // vue-loader 配置項
  // https://vue-loader.vuejs.org/en/options.html
  vueLoader: {},
  // 生產環境是否生成 sourceMap 文件
  productionSourceMap: true,
  // css相關配置
  css: {
    // 是否使用css分離插件 ExtractTextPlugin
    extract: true,
    // 開啟 CSS source maps?
    sourceMap: false,
    // css預設器配置項
    loaderOptions: {},
    // 啟用 CSS modules for all css / pre-processor files.
    modules: false
  },
  // use thread-loader for babel & TS in production build
  // enabled by default if the machine has more than 1 cores
  parallel: require('os').cpus().length > 1,
  // 是否啟用dll
  // See https://github.com/vuejs/vue-cli/blob/dev/docs/cli-service.md#dll-mode
  dll: false,
  // PWA 插件相關配置
  // see https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-pwa
  pwa: {},
  // webpack-dev-server 相關配置
  devServer: {
    open: process.platform === 'darwin',
    host: '0.0.0.0',
    port: 8080,
    https: false,
    hotOnly: false,
    proxy: null, // 設置代理
    before: app => {}
  },
  // 第三方插件配置
  pluginOptions: {
    // ...
  }
}
Shenglian commented 5 years ago

Proxy


# string
module.exports = {
devServer: {
proxy: '<url>'
}
}

Object

module.exports = { devServer: { proxy: { '/api': { target: '', ws: true, changeOrigin: true }, '/foo': { target: '' } } } }

Shenglian commented 5 years ago

啟用dll

  • 啟用dll後,我們的動態庫文件每次打包生成的vendor的[chunkhash]值就會一樣,其值可以是true/false,也可以製定特定的代码库
    
    module.exports = {
    dll: true
    }

module.exports = { dll: [ 'dep-a', 'dep-b/some/nested/file.js' ] }

Shenglian commented 5 years ago

靜態資源路徑

  • 相對路徑
Shenglian commented 5 years ago

webpack 配置修改

  • 對模塊處理配置
    module.exports = {
    chainWebpack: config => {
    config.module
    .rule('js')
    .include
    .add(/some-module-to-transpile/)  // 要处理的模块
    }
    }
  • 修改webpack Loader配置
    module.exports = {
    chainWebpack: config => {
    config.module
    .rule('scss')
    .use('sass-loader')
    .tap(options =>
    merge(options, {
    includePaths: [path.resolve(__dirname, 'node_modules')],
    })
    )
    }
    }

    修改webpack Plugin配置

    module.exports = {
    chainWebpack: config => {
    config
    .plugin('html')
    .tap(args => {
    return [/* new args to pass to html-webpack-plugin's constructor */]
    })
    }
    }