staven630 / vue-cli4-config

vue-cli4配置vue.config.js持续更新

Home Page:https://staven630.github.io/vue-cli4-config/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

关于构建时去除多余css的问题

xl-wolf opened this issue · comments

作者好!按照所给的配置报错class Extractor必须要用new关键字调用
然而new 这个Extractor类之后依旧构建失败,报错t不是函数 这个本人就一头雾水了!希望作者帮忙赐教解决一下

找了一點線索 https://gist.github.com/josephan/45569c48ee4867237e89417aed283103
大概是因為purgecss-webpack-plugin從v1升上了v2的問題....

把這段

          extractors: [
            {
              extractor: class Extractor {
                static extract(content) {
                  const validSection = content.replace(
                    /<style([\s\S]*?)<\/style>+/gim,
                    ""
                  );
                  return (
                    validSection.match(/[A-Za-z0-9-_/:]*[A-Za-z0-9-_/]+/g) || []
                  );
                }
              },
              extensions: ["html", "vue"]
            }
          ],

改為

            extractors: [
              {
                extractor: (content) => {
                  const validSection = content.replace(/<style([\s\S]*?)<\/style>+/gim, "");
                  return validSection.match(/[A-Za-z0-9-_/:]*[A-Za-z0-9-_/]+/g) || [];
                },
                extensions: ["html", "vue"],
              },
            ],

就可以了