Closed glennsl closed 6 years ago
we can do this in the build system level instead of relaxing names?
It seems it would have to involve code generation too, to "unmangle" the module names for imports and such, wouldn't it? Build system can take pages/index.re
and generate Pages__index.cm*
, but code generation would still have to emit pages/index.js
and require('../pages/index.js')
.
I guess it could be done with some post-processing by the build system.
I mean you still generate pages.js
but allowing a field to copy it, something like below
"copy" : [ [ "page" , "index"] , ["error", "404"], ["layouts", "index"]]
I'm not sure I follow. So you'd have pages/pages_index.re
(or something else that's unique), which produces a module called Pages_index
and emits js to pages/pages_index.js
. Then the "copy" config means it should copy that to pages/index.js
?
@glennsl yes, that's something I have in mind. would copy be good enough or do you need remove page_index.js
in practice?
@bobzhang It would of course result in unwanted pages being generated, and would also slow down the build process (a big part of gatsby DX is hot module replacement, and it's unfortunately already pretty slow). But none of these issues are dealbreakers I think.
A bigger concern is how the configuration would work. I don't fully understand the config example you posted above, but it looks like it's per-item, which would quickly get unmanageable and error-prone.
@glennsl: Did the problem get fixed or did you find a solution? Otherwise, why did you close this issue? I think, some kind of workaround still would be useful.
@glennsl Hi. I'm currently having the same issue with nextjs + reason. Did you find a workaround for this?
I'm working on getting gatsby to work with bucklescript+reason-react and have a small starter project up an going at https://github.com/glennsl/reasonable-gatsby-starter. I've run into some issues however, and all the major ones are related to filename restrictions, since Gatsby relies quite heavily on the file and directory structure of the project. Here are some of the issues, workarounds and possible solutions I've found:
404.js
, which is of course not a valid OCaml module name.The workaround is to rename the
.re
to something valid (error404.re
) then add a stand-alone404.js
that simply re-exportserror404
. It's messy, but it works.Is it possible to add some sort of name mangling to the module name generation?
.js
-file. Since filenames must be unique, it is not practically possible (or at least very inconvenient) to have url segments with the same name. It also causes other conflicts where special filenames are needed. In particular, it is not possible to directly have multipleindex
pages in different directories.The workaround here is the same as above, rename the reason file and add a stand-alone js-file with the correct name that re-exports the generated js of the renamed file.
Is it possible to have an option to enable the generation of module names based on the path? So we could have
pages/index.js
andlayouts/index.js
generate the module namesPages__Index
andLayouts__Index
respectively.