每日一篇,Vue 第一篇 "基础篇"

986 阅读2分钟

暂时作为测试的

前言

1 chainWebpack 链式操作

config.plugin 插件

use 使用插件

// config.plugin(name)
// 具名插件

// 具名插件html, 默认使用htmlWebpackPlugin
// 无需use
config.plugin('html')

// 具名插件povide,使用webpack.ProvidePlugin
// args必须为数组,options需要使用数组包裹
plugin('povide')
  .use(webpack.ProvidePlugin, [options])

tap 更改参数

// htmlWebpackPlugin
config.plugin('html').tap(args => {
  // 新增CDN资源引入
  // 在index.htm中动态引入link和script
  args[0].CDN = CDNSources
  
  // 必须返回args
  return args
})

// ProvidePlugin
plugin('povide')
  .use(webpack.ProvidePlugin, [{
    _: 'lodash'
  }])
  .tap(args => {
    console.log('povide', args)
    return args
  })

use 使用插件

// config.plugin(name)
// 具名插件

// 具名插件html, 默认使用htmlWebpackPlugin
// 无需use
config.plugin('html')

// 具名插件povide,使用webpack.ProvidePlugin
// args必须为数组,options需要使用数组包裹
plugin('povide')
  .use(webpack.ProvidePlugin, [options])

tap 更改参数

// htmlWebpackPlugin
config.plugin('html').tap(args => {
  // 新增CDN资源引入
  // 在index.htm中动态引入link和script
  args[0].CDN = CDNSources
  
  // 必须返回args
  return args
})

// ProvidePlugin
plugin('povide')
  .use(webpack.ProvidePlugin, [{
    _: 'lodash'
  }])
  .tap(args => {
    console.log('povide', args)
    return args
  })

use 使用插件

// config.plugin(name)
// 具名插件

// 具名插件html, 默认使用htmlWebpackPlugin
// 无需use
config.plugin('html')

// 具名插件povide,使用webpack.ProvidePlugin
// args必须为数组,options需要使用数组包裹
plugin('povide')
  .use(webpack.ProvidePlugin, [options])

tap 更改参数

// htmlWebpackPlugin
config.plugin('html').tap(args => {
  // 新增CDN资源引入
  // 在index.htm中动态引入link和script
  args[0].CDN = CDNSources
  
  // 必须返回args
  return args
})

// ProvidePlugin
plugin('povide')
  .use(webpack.ProvidePlugin, [{
    _: 'lodash'
  }])
  .tap(args => {
    console.log('povide', args)
    return args
  })

use 使用插件

// config.plugin(name)
// 具名插件

// 具名插件html, 默认使用htmlWebpackPlugin
// 无需use
config.plugin('html')

// 具名插件povide,使用webpack.ProvidePlugin
// args必须为数组,options需要使用数组包裹
plugin('povide')
  .use(webpack.ProvidePlugin, [options])

tap 更改参数

// htmlWebpackPlugin
config.plugin('html').tap(args => {
  // 新增CDN资源引入
  // 在index.htm中动态引入link和script
  args[0].CDN = CDNSources
  
  // 必须返回args
  return args
})

// ProvidePlugin
plugin('povide')
  .use(webpack.ProvidePlugin, [{
    _: 'lodash'
  }])
  .tap(args => {
    console.log('povide', args)
    return args
  })

use 使用插件

// config.plugin(name)
// 具名插件

// 具名插件html, 默认使用htmlWebpackPlugin
// 无需use
config.plugin('html')

// 具名插件povide,使用webpack.ProvidePlugin
// args必须为数组,options需要使用数组包裹
plugin('povide')
  .use(webpack.ProvidePlugin, [options])

tap 更改参数

// htmlWebpackPlugin
config.plugin('html').tap(args => {
  // 新增CDN资源引入
  // 在index.htm中动态引入link和script
  args[0].CDN = CDNSources
  
  // 必须返回args
  return args
})

// ProvidePlugin
plugin('povide')
  .use(webpack.ProvidePlugin, [{
    _: 'lodash'
  }])
  .tap(args => {
    console.log('povide', args)
    return args
  })

use 使用插件

// config.plugin(name)
// 具名插件

// 具名插件html, 默认使用htmlWebpackPlugin
// 无需use
config.plugin('html')

// 具名插件povide,使用webpack.ProvidePlugin
// args必须为数组,options需要使用数组包裹
plugin('povide')
  .use(webpack.ProvidePlugin, [options])

tap 更改参数

// htmlWebpackPlugin
config.plugin('html').tap(args => {
  // 新增CDN资源引入
  // 在index.htm中动态引入link和script
  args[0].CDN = CDNSources
  
  // 必须返回args
  return args
})

// ProvidePlugin
plugin('povide')
  .use(webpack.ProvidePlugin, [{
    _: 'lodash'
  }])
  .tap(args => {
    console.log('povide', args)
    return args
  })