关于前端:webpack踩坑

webpack这些年遇到的报错
1.
这个问题是因为webpack版本不同导致的写法谬误
批改前代码:

options: {
              modules: true, // 以前的版本设置modules为true,而后其余属性和modules同级
              getLocalIdent: (context, localIdentName, localName) => {
                if (
                  context.resourcePath.includes('node_modules') ||
                  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;
              },
            },

批改后代码:

modules: {// 属性都写在modules外面

                getLocalIdent: (context, localIdentName, localName) => {
                  if (
                    context.resourcePath.includes('pages') ||
                    context.resourcePath.includes('node_modules') ||
                    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;
                },
              },

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理