webpack-contrib / purifycss-webpack

UNMAINTAINED, use https://github.com/FullHuman/purgecss-webpack-plugin
MIT License
772 stars 37 forks source link

V2.0.3 paths per entry fails. #67

Closed beckend closed 7 years ago

beckend commented 7 years ago
paths: {
          desktop: glob.sync(`${PATH_SRC_DESKTOP}/**/*`),
          mobile: glob.sync(`${PATH_SRC_MOBILE}/**/*`),
        },

Error:

/Users/linken/Coding/project/node_modules/purifycss-webpack-plugin/index.js:33
        var files = self.paths.reduce(function(results, p) {
                               ^
TypeError: self.paths.reduce is not a function
    at Compiler.<anonymous> (/Users/linken/Coding/project/node_modules/purifycss-webpack-plugin/index.js:33:32)
    at Compiler.applyPlugins (/Users/linken/Coding/project/node_modules/tapable/lib/Tapable.js:61:14)
    at Compiler.newCompilation (/Users/linken/Coding/project/node_modules/webpack/lib/Compiler.js:430:7)
    at /Users/linken/Coding/project/node_modules/webpack/lib/Compiler.js:464:26
    at Compiler.applyPluginsAsyncSeries (/Users/linken/Coding/project/node_modules/tapable/lib/Tapable.js:131:46)
    at Compiler.compile (/Users/linken/Coding/project/node_modules/webpack/lib/Compiler.js:459:7)
    at /Users/linken/Coding/project/node_modules/webpack/lib/Compiler.js:220:10
    at Compiler.readRecords (/Users/linken/Coding/project/node_modules/webpack/lib/Compiler.js:369:10)
    at /Users/linken/Coding/project/node_modules/webpack/lib/Compiler.js:217:9
    at next (/Users/linken/Coding/project/node_modules/tapable/lib/Tapable.js:138:11)
    at Compiler.compiler.plugin (/Users/linken/Coding/project/node_modules/webpack/lib/CachePlugin.js:35:59)
    at Compiler.applyPluginsAsyncSeries (/Users/linken/Coding/project/node_modules/tapable/lib/Tapable.js:142:13)
    at /Users/linken/Coding/project/node_modules/webpack/lib/Compiler.js:214:8
    at next (/Users/linken/Coding/project/node_modules/tapable/lib/Tapable.js:138:11)
    at Compiler.compiler.plugin (/Users/linken/Coding/project/node_modules/webpack/lib/node/NodeEnvironmentPlugin.js:21:4)
    at Compiler.applyPluginsAsyncSeries (/Users/linken/Coding/project/node_modules/tapable/lib/Tapable.js:142:13)
    at Compiler.run (/Users/linken/Coding/project/node_modules/webpack/lib/Compiler.js:211:7)
    at processOptions (/Users/linken/Coding/project/node_modules/webpack/bin/webpack.js:358:12)
    at Object.<anonymous> (/Users/linken/Coding/project/node_modules/webpack/bin/webpack.js:362:1)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.runMain (module.js:605:10)
    at run (bootstrap_node.js:420:7)
    at startup (bootstrap_node.js:139:9)
    at bootstrap_node.js:535:3
bebraw commented 7 years ago

@beckend Hi, the GitHub readme represents the next version. You have to look up the instructions from npm. I'm still waiting a reply from npm as I need release rights and @IngwiePhoenix isn't being responsive either.

bebraw commented 7 years ago

@beckend The new version is out. Please give that a go.

beckend commented 7 years ago

Get different error using exact same thing in my first comment:

TypeError: Path must be a string. Received undefined
    at assertPath (path.js:7:11)
    at Object.extname (path.js:1431:5)
    at /Users/linken/project/node_modules/purifycss-webpack/dist/search.js:26:36
    at Array.map (native)
    at Object.searchFiles [as files] (/Users/linken/project/node_modules/purifycss-webpack/dist/se
arch.js:23:31)
    at /Users/linken/project/node_modules/purifycss-webpack/dist/index.js:53:77
    at Array.forEach (native)
    at /Users/linken/project/node_modules/purifycss-webpack/dist/index.js:49:28
    at Array.forEach (native)
    at Compilation.<anonymous> (/Users/linken/project/node_modules/purifycss-webpack/dist/index.js
:34:30)
    at next (/Users/linken/project/node_modules/tapable/lib/Tapable.js:140:14)
    at ExtractTextPlugin.<anonymous> (/Users/linken/project/node_modules/extract-text-webpack-plug
in/index.js:316:4)
    at Compilation.applyPluginsAsyncSeries (/Users/linken/project/node_modules/tapable/lib/Tapable
.js:142:13)
    at sealPart2 (/Users/linken/project/node_modules/webpack/lib/Compilation.js:597:9)
    at next (/Users/linken/project/node_modules/tapable/lib/Tapable.js:138:11)
    at Compilation.<anonymous> (/Users/linken/project/node_modules/webpack/lib/ProgressPlugin.js:1
10:5)
    at next (/Users/linken/project/node_modules/tapable/lib/Tapable.js:140:14)
    at ExtractTextPlugin.<anonymous> (/Users/linken/project/node_modules/extract-text-webpack-plug
in/index.js:292:5)
    at /Users/linken/project/node_modules/extract-text-webpack-plugin/node_modules/async/dist/asyn
c.js:356:16
    at iteratorCallback (/Users/linken/project/node_modules/extract-text-webpack-plugin/node_modul
es/async/dist/async.js:936:13)
    at /Users/linken/project/node_modules/extract-text-webpack-plugin/node_modules/async/dist/asyn
c.js:840:16
    at /Users/linken/project/node_modules/extract-text-webpack-plugin/index.js:276:6
    at /Users/linken/project/node_modules/extract-text-webpack-plugin/node_modules/async/dist/asyn
c.js:356:16
    at iteratorCallback (/Users/linken/project/node_modules/extract-text-webpack-plugin/node_modul
es/async/dist/async.js:936:13)
    at /Users/linken/project/node_modules/extract-text-webpack-plugin/node_modules/async/dist/asyn
c.js:840:16
    at /Users/linken/project/node_modules/extract-text-webpack-plugin/index.js:273:13
    at /Users/linken/project/node_modules/extract-text-webpack-plugin/node_modules/async/dist/asyn
c.js:3025:16
    at eachOfArrayLike (/Users/linken/project/node_modules/extract-text-webpack-plugin/node_module
s/async/dist/async.js:941:9)
    at eachOf (/Users/linken/project/node_modules/extract-text-webpack-plugin/node_modules/async/d
ist/async.js:991:5)
    at Object.eachLimit (/Users/linken/project/node_modules/extract-text-webpack-plugin/node_modul
es/async/dist/async.js:3089:3)
bebraw commented 7 years ago

@beckend Can you set up a small GitHub repository showing the error? That will allow me to patch it the right way. Some little assumption is wrong in the code.

beckend commented 7 years ago

Will do in the weekend when i'm off, the current plugin was tested on a huge project.

bebraw commented 7 years ago

Ok, cool.

I added stricter validation yesterday so that should catch possible configuration related problems.

beckend commented 7 years ago

I found this in the schema:

    paths: {
      type: ['array', 'object'],
      items: {
        type: 'string'
      }
    },

Are you saying the item property in the object can only be string? I mean it's going to be an array of strings in my case.

beckend commented 7 years ago

these are the options I logged in the plugin before validation:

{
    "extensions": [
        ".html",
        ".pug"
    ],
    "paths": {
        "desktop": "dasdas",
        "mobile": "dsadas"
    },
    "purifyOptions": {
        "info": true,
        "minify": true,
        "rejected": false
    }
}

Then it fails with:

    throw new Error(validation.error);
          ^
Error: data should NOT have additional properties
beckend commented 7 years ago

With the above and reading the schema, it passes validation if I change "extensions" to "fileExtensions" since you updated the plugin.

bebraw commented 7 years ago

Ok. Check out the fileExtensions and moduleExtensions properties. extensions was removed as it was unclear.

bebraw commented 7 years ago

Yup. The split was on purpose. I can change the naming as fileExtensions feels too vague.

beckend commented 7 years ago

Ok I tried to replicate on a smal repo, wasn't successful. So I temp open my repo which is a skeleton boilerplate at https://bitbucket.org/linken/webpack-boiler-ts branch is purify-css-1

Instructions to get it running:

  1. npm -g i yarn gulp-cli
  2. yarn - to install deps
  3. NODE_ENV='production' gulp clean:build build:web And I get some really weird error.

Please let me know if you decide to clone it, so I can close it later.

beckend commented 7 years ago

webpack configs are in internals/webpack

bebraw commented 7 years ago

@beckend Hi, I got it running. After I hit build as instructed, it gets stuck on 92% chunk asset optimization while taking all my CPU (new quad core). Is that to be expected? Note that I'm running Node 6, not 7.

What kind of error are you getting? Can you simplify the project somehow while still retaining it?

bebraw commented 7 years ago

Nm. The error is above (TypeError: Path must be a string. Received undefined). Still, it would be fun to get this running so I can debug and fix. Most likely it's missing some check against webpack in some very specific case. šŸ‘

I could likely fix this blind (extra filter), but I'll wait for a simplified project so it's easier to see what's really going on.

bebraw commented 7 years ago

You can likely simplify

        fileExtensions: [
          '.css',
          '.html',
          '.less',
          '.pug',
          '.sass',
          '.scss',
          '.styl',
        ],

to include only styling files (so just css, sass etc.). That might help a notch. I actually renamed that field to styleExtensions to communicate the meaning better.

beckend commented 7 years ago

When I debugged last time, I hit this line which yields undefined, thus the error you saw. https://github.com/webpack-contrib/purifycss-webpack/blob/master/src/search.js#L18

bebraw commented 7 years ago

Yup. It's that path.extname(file). What if we added a check against file and bailed if it's not there? I think I'll add just that.

bebraw commented 7 years ago

I included the check in 0.3.1 as it definitely doesn't hurt. Feel free to close this issue once you can verify this has fixed the problem.

beckend commented 7 years ago

Progress, it now hits the next thing: https://github.com/webpack-contrib/purifycss-webpack/blob/master/src/index.js#L41

TypeError: (paths[chunkName] || paths).concat is not a function
beckend commented 7 years ago

Basically it's the same problem as the search one, where paths[chunkName] is undefined.

bebraw commented 7 years ago

@beckend I see the problem. Your uglify config has desktop, but your entries are named like entry-desktop. Because of that mismatch, it crashes right there.

I think I'll add extra validation against that case so it's possible to detect early on.

beckend commented 7 years ago

I think you hit the nail with that! This should also mean that the search function thing you worked on should be reverted, and should throw an error there instead. It now works.

bebraw commented 7 years ago

The search check is fine. It doesn't hurt to avoid runtime errors. šŸ‘

I'll close this issue after I have that other check in place.

beckend commented 7 years ago

Alright thanks, I have another issue where the purified build does not look like the unpurified build. Will open another thread when I'm done with my confirmation. I'll leave this one for you.