ant-design-pro引用css

ant-design-pro中默认只能引用less文件,引用了css文件也是无效的。所以需要在配置文件config.js中找到

 cssLoaderOptions,在 getLocalIdent中加入可以引用css文件的方法:context.resourcePath.includes('.css')
代码如下:
cssLoaderOptions: {
    modules: true,
    getLocalIdent: (context, localIdentName, localName) => {
      if (
        context.resourcePath.includes('node_modules') ||
        context.resourcePath.includes('.css') ||
        context.resourcePath.includes('ant.design.pro.less') ||
        context.resourcePath.includes('global.less')
      ) {
        return localName;
      }
      const match = context.resourcePath.match(/src(.*)/);
      if (match && match[1]) {
        const antdProPath = match[1].replace('.less', '');
        const arr = slash(antdProPath)
          .split('/')
          .map(a => a.replace(/([A-Z])/g, '-$1'))
          .map(a => a.toLowerCase());
        return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-');
      }
      return localName;
    },
  },

 

posted @ 2019-10-10 14:21  绿茶叶  阅读(2695)  评论(0编辑  收藏  举报