create-guten-block
create-guten-block copied to clipboard
Add webpack aliases for Gutenberg components
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
@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 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?
Maybe I can ask @youknowriad to weigh in on this?
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 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 If you configure Webpack to make @wordpress/components
point to the wp.components
global like I did in GCF, you could do it.
Can we have a "src" directory alias like VueCLI has "@"?