指定webpack输出文件位置及文件名。

  1. module.exports = {
  2. entry: {
  3. ...
  4. },
  5. output: {
  6. filename: '[name].js',
  7. path: __dirname + '/dist',
  8. asyncChunks: true, // 创建按需加载的chunk
  9. clean: true, // 生成文件之前清空output目录,也可传入对象
  10. }
  11. }

对CDN的引入

  1. module.exports = {
  2. output: {
  3. path: '/cdn/assets/[fullhash]', // fullhash在compilation时被替换
  4. publicPath: 'https://cdn.example.com/assets/[fullhash]'
  5. }
  6. }

:::info publicpath指定按需加载或外部引用的资源,相对路径会相对于html页面解析 :::

动态配置public

在entry配置 __webpack_public_path__变量一边runtime时动态设置