首页 > 解决方案 > 如何使用下一个配置修复“冲突:多个资产发射到同一个块 css 文件名”?

问题描述

我在这样的每条路线上都收到了这个警告:

Multiple assets emit different content to the same filename 
static/css/static/development/pages/_app.js.chunk.css.map

Multiple assets emit different content to the same filename 
static/css/static/development/pages/index.js.chunk.css.map

Multiple assets emit different content to the same filename 
static/css/static/development/pages/login.js.chunk.css.map

这是我的下一个配置:

const withPlugins = require('next-compose-plugins');
const withCss = require('@zeit/next-css');
const withSass = require('@zeit/next-sass');
const withImages = require('next-images');
// eslint-disable-next-line import/no-unresolved
require('dotenv').config();

if (typeof require !== 'undefined') {
  require.extensions['.css'] = () => {};
}

const nextConfig = {
  env: {
    HOST_URL: process.env.HOST_URL,
    BUILD_ENV: process.env.BUILD_ENV,
  },
  webpack: (config, { isServer }) => {
    if (isServer) {
      const antStyles = /antd\/.*?\/style\/css.*?/;
      const origExternals = [...config.externals];
      // eslint-disable-next-line no-param-reassign
      config.externals = [
        // eslint-disable-line
        (context, request, callback) => {
          // eslint-disable-line
          if (request.match(antStyles)) return callback();
          if (typeof origExternals[0] === 'function') {
            origExternals[0](context, request, callback);
          } else {
            callback();
          }
          return null;
        },
        ...(typeof origExternals[0] === 'function' ? [] : origExternals),
      ];

      config.module.rules.unshift({
        test: antStyles,
        use: 'null-loader',
      });
    }
    return config;
  },
};

module.exports = withPlugins(
  [
    [withImages],
    [withCss],
    [
      withSass,
      {
        cssModules: true,
        cssLoaderOptions: {
          localIdentName: '[path]_[local]_[hash:base64:5]',
        },
      },
    ],
  ],
  nextConfig,
);

我该如何解决?

标签: reactjswebpacknext.jsantd

解决方案


推荐阅读