create-guten-block icon indicating copy to clipboard operation
create-guten-block copied to clipboard

Add webpack aliases for Gutenberg components

Open Shelob9 opened this issue 6 years ago • 7 comments

It would be great to import components from WordPress with @wp alias, like @youknowriad does here: https://github.com/youknowriad/gcf/blob/master/scripts/blocks/components/field/index.js#L2

Relevant lines in his webpack: https://github.com/youknowriad/gcf/blob/master/webpack.config.js#L41-L46

Shelob9 avatar Feb 08 '18 18:02 Shelob9

@ahmadawais I can't figure out what file I would modify to change the webpack config and package.json that is generated. Can you link me to that or show me where to look please? If you could point me in the right direction, I could do a PR.

Shelob9 avatar Feb 08 '18 18:02 Shelob9

@Shelob9 this is where you should be looking at https://github.com/ahmadawais/create-guten-block/tree/master/packages/cgb-scripts/config

But I am not entirely sure why it's being done like this while we should have all that as packages. Also, how would it work with Gutenberg plugin that only has built plugin and not dev files?

ahmadawais avatar Feb 08 '18 19:02 ahmadawais

Maybe I can ask @youknowriad to weigh in on this?

ahmadawais avatar Feb 08 '18 19:02 ahmadawais

You're right, at some point we may provide some of these modules as npm packages but If you import them as packages, each plugin will have its own version as opposed to using the aliased global variable. So I think using the globals is the way to go for most of these packages (not sure about components yet)

youknowriad avatar Feb 08 '18 20:02 youknowriad

@youknowriad If I am not wrong then we cannot use something like this while creating GutenBlocks?

import { withInstanceId } from "@wordpress/components";

Where is "@wordpress/components" coming from if we are not using the dev version of Gutenberg?

ahmadawais avatar Feb 08 '18 21:02 ahmadawais

@ahmadawais If you configure Webpack to make @wordpress/components point to the wp.components global like I did in GCF, you could do it.

youknowriad avatar Feb 08 '18 22:02 youknowriad

Can we have a "src" directory alias like VueCLI has "@"?

theharshin avatar Feb 19 '19 07:02 theharshin