Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when trying to modify Webpack plugins #269

Closed
kylegach opened this issue May 1, 2016 · 5 comments
Closed

Error when trying to modify Webpack plugins #269

kylegach opened this issue May 1, 2016 · 5 comments

Comments

@kylegach
Copy link
Contributor

kylegach commented May 1, 2016

I copy/pasted the example code from the README into a brand-new gatsby-node.js:

var ExtractTextPlugin = require("extract-text-webpack-plugin");

exports.modifyWebpackConfig = function(config, env) {
  if(env === 'static') {
    config.removeLoader('css');
    config.loader('css', function(cfg) {
      cfg.test = /\.css$/;
      cfg.loader = ExtractTextPlugin.extract('css?minimize');
      return cfg
    })
    config.plugin('extract-css',
                  ExtractTextPlugin,
                  ["styles.css", { allChunks: true }]);
  }
}

Which outputs this error after running gatsby develop (using Gatsby 0.10.0):

/Users/Kyle/Sites/kylegach_com/node_modules/gatsby/dist/utils/develop.js:68
    var compiler = (0, _webpack2.default)(compilerConfig.resolve());
                                                        ^

TypeError: Cannot read property 'resolve' of undefined
  at /Users/Kyle/Sites/kylegach_com/node_modules/gatsby/dist/utils/develop.js:68:57
  at /Users/Kyle/Sites/kylegach_com/node_modules/gatsby/dist/utils/glob-pages.js:36:12
  at f (/Users/Kyle/Sites/kylegach_com/node_modules/once/once.js:17:25)
  at Glob.<anonymous> (/Users/Kyle/Sites/kylegach_com/node_modules/glob/glob.js:146:7)
  at emitOne (events.js:90:13)
  at Glob.emit (events.js:182:7)
  at Glob._finish (/Users/Kyle/Sites/kylegach_com/node_modules/glob/glob.js:194:8)
  at done (/Users/Kyle/Sites/kylegach_com/node_modules/glob/glob.js:179:14)
  at Glob._processGlobStar2 (/Users/Kyle/Sites/kylegach_com/node_modules/glob/glob.js:631:12)
  at /Users/Kyle/Sites/kylegach_com/node_modules/glob/glob.js:620:10
  at RES (/Users/Kyle/Sites/kylegach_com/node_modules/inflight/inflight.js:23:14)
  at f (/Users/Kyle/Sites/kylegach_com/node_modules/once/once.js:17:25)
  at lstatcb_ (/Users/Kyle/Sites/kylegach_com/node_modules/glob/glob.js:513:7)
  at RES (/Users/Kyle/Sites/kylegach_com/node_modules/inflight/inflight.js:23:14)
  at f (/Users/Kyle/Sites/kylegach_com/node_modules/once/once.js:17:25)
  at FSReqWrap.oncomplete (fs.js:82:15)

Eventually, I'm trying to change the production css loader & plugins to use both extract-text-webpack-plugin and purifycss-webpack-plugin... but I get the error before even attempting that.

Thanks for the help.

@KyleAMathews
Copy link
Contributor

Perhaps it's because you're not returning the config? That'd explain why compilerConfig is undefined... we should throw an error for this actually... adding this to #204

Also on PurifyCSS, I haven't used this but with Gatsby, wouldn't this need to be run after the pages are built? Or does the plugin know how to scan React.js components for className?

@kylegach
Copy link
Contributor Author

kylegach commented May 3, 2016

Perhaps it's because you're not returning the config? That'd explain why compilerConfig is undefined...

Oh, duh. Thanks for the help. I just submitted a PR to correct the README to work out of the box.

As best I can tell, the PurifyCSS plugin knows to scan all React “views”, but I’ve no idea how it does so. Purify itself appears to be disappointingly simple in its workings, merely searching for strings anywhere in the source instead of selectively doing so within, e.g. className attribute values. The maintainer says it has optimizations for JS files, but I’m having some issues that would indicate it’s still not working as well I hoped it might.

@KyleAMathews
Copy link
Contributor

Hmm... that is weird.

Thanks for the PR! If you're feeling up to more PRs, add an invariant to the return value of modifyWebpackConfig would save future people from being blocked by this issue.

return modifyWebpackConfig(module(config), stage)

@Necmttn
Copy link
Contributor

Necmttn commented Nov 3, 2016

@kylegach Did you able to make it work purifycss with gatsby. I have nasty off unused css.. i'm beign to lazy to clean it one by one.

@kylegach
Copy link
Contributor Author

kylegach commented Nov 3, 2016

@Necmttn — Nope. I haven’t had time to try again. If you look at my issue there, it looks like others have attempted a fix.

It’s worth noting that purifycss-webpack-plugin and gatsby worked together just fine, btw. The issue I had was in the quality of purifycss’ results with my relatively-crazy CSS classes. If you’re using a more traditional CSS architecture/naming system, e.g. BEM, you should be fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants