Docz: v2: Plugin can't modify webpack config

Created on 2 Sep 2019  路  16Comments  路  Source: doczjs/docz

Please reference to following code, the first param of onCreateWebpackConfig hook is an immutable object.

https://github.com/doczjs/docz/blob/c72c57574142334846e7aad63ad3e72d07f9ddca/core/gatsby-theme-docz/lib/onCreateWebpackConfig.js#L31

bug v2

Most helpful comment

@hvsy, yep replaced actions with params now to match docs.

@nikitpatel24 this looks like a separate problem, params are passed down correctly for onCreateBabelConfig. Could you open another issue to pin down your problem ?

All 16 comments

I'm sorry I'm not sure I understand the issue.

Are you looking to modify docz's webpack config in a project ?

I'm experiencing the same issue.

At the root of my project i've added a custom gatsby-node.js file:

const path = require('path');
exports.onCreateWebpackConfig = ({  actions }) => {
  actions.setWebpackConfig({
    resolve: {
      alias: {
         theme: path.resolve(__dirname, '../src/lib/theme'),
      },
    },
  });
};

However, when I run yarn docz:dev my components are not able to resolve theme.

I've tried several variations of this command, with no success. Either I'm doing something wrong or docz just isn't able to resolve this configuration.

Was going to come here to report this, but then spotted this issue, so it looks like indeed there's a bug.

Help appreciated, thanks!

Thanks @josebrito for clearing that up.

Looking into it :+1:

Is the project a Gatsby app ?

@rakannimer in my case, no. Docz is the only package dependent on Gatsby.

Should be fixed in 2.0.0-rc.28

Please give it a try and let me know

Hey @hvsy

You're right you can't modify the config object directly, to modify the webpack config you can use actions.setWebpackConfig

Example :

exports.onCreateWebpackConfig = ({
 stage, getConfig, rules, loaders, actions
}) => {
  actions.setWebpackConfig({
    module: {
      rules: [
        {
          test: 'my-css',
          use: [loaders.style(), loaders.css()]
        },
      ],
    },
  });
}

More info can be found here : https://www.docz.site/docs/creating-plugins

Does that address your issue ? Or am I missing something ?

@rakannimer

please check following code
https://github.com/doczjs/docz/blob/2f29e1d4a18854bd32618960c97a697df13a85d7/core/gatsby-theme-docz/lib/onCreateWebpackConfig.js#L31

the first parameter is not "actions" but "config"

Ok understood 馃槄!

I will add an argument to avoid breaking v2 plugins replace config with params to match the documentation.

No need to add additional argument.
because the current "config" object is immutable. existing v2 plugins hasn't a working.

Changed 66546a4 in 2.0.0-rc.32

it is working well now.

but the document inconsistent with code.

Also onCreateBabelConfig does not seem to work.

exports.onCreateBabelConfig = ({ actions }) => { actions.setBabelPlugin({ name: '@babel/plugin-proposal-decorators', options: { legacy: true }, }); };

@hvsy, yep replaced actions with params now to match docs.

@nikitpatel24 this looks like a separate problem, params are passed down correctly for onCreateBabelConfig. Could you open another issue to pin down your problem ?

Hi, sorry for the lack of updates, just wanted to confirm that issue is fixed. Thanks!

Was this page helpful?
0 / 5 - 0 ratings