lmislm / lmislm.github.io

hexo的配置
0 stars 0 forks source link

javascript/auto #7

Open lmislm opened 11 months ago

lmislm commented 11 months ago

When using the old assets loaders (i.e. file-loader/url-loader/raw-loader) along with Asset Modules in webpack 5, you might want to stop Asset Modules from processing your assets again as that would result in asset duplication. This can be done by setting the asset's module type to 'javascript/auto'.

webpack.config.js

module.exports = {
  module: {
   rules: [
      {
        test: /\.(png|jpg|gif)$/i,
        use: [
          {
            loader: 'url-loader',
            options: {
              limit: 8192,
            }
          },
        ],
       type: 'javascript/auto'
      },
   ]
  },
}

Reference:

  1. https://webpack.js.org/guides/asset-modules/