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
Field type build tool #993
Conversation
Controller: '@keystone-alpha/fields/types/Text/views/Controller', | ||
Field: path.join(__dirname, './views/Field/Field'), | ||
Filter: '@keystone-alpha/fields/types/Text/views/Filter', | ||
Controller: Text.views.Controller, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really interesting, if it works 😍
I really like what this does to the Keystone field package structure. Can you share what it would look like (in terms of file structure, screenshot or comment here would do) for the main Also, do you think this changes anything for other views (e.g. for custom pages in the Admin UI)? There aren't any chances to the fields-loader, which we've talked about extending, just double-checking that's a separate thing. Thoughts unrelated to the API:
|
It shouldn't change anything about that.
Having the server side parts of field types behind a build step is what enables 👇 is an explanation of how importView will work which might answer any other questions you might have. We have a file like this, import { importView } from '@keystone-alpha/build-field-types';
export let Wysiwyg = {
...otherStuff
views: {
...otherViewsStuff
Field: importView('./views/Field'),
},
}; It goes through a babel plugin which turns it into this export let Wysiwyg = {
...otherStuff
views: {
...otherViewsStuff
Field: ___KS_BUILD_SYSTEM_INTERNAL___importView(import('./views/Field')),
},
}; Rollup does its thing and we have this for CommonJS builds. (and a different thing for ESM but I'm going to ignore that for this explanation) It's going to be written to the dist folder. exports.Wysiwyg = {
...otherStuff
views: {
...otherViewsStuff
Field: ___KS_BUILD_SYSTEM_INTERNAL___importView(Promise.resolve(require('./chunk-hash'))),
},
}; We then transform it with another babel plugin into this const _join = require('path').join
exports.Wysiwyg = {
...otherStuff
views: {
...otherViewsStuff
Field: _join(__dirname, './chunk-hash'),
},
}; And rollup will write the ESM and CJS versions of that chunk to |
❤️ it @mitchellhamilton |
'last 2 firefox versions', | ||
'last 2 safari versions', | ||
'last 2 edge versions', | ||
], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to call out this change in case anyone has any concerns. From #214 it seems like we're okay with not supporting IE 11.
The reason I did this isn't really for smaller bundles but that's a nice benefit, I did this is because there's a bug in Babel which means Babel compiled classes can't extend native classes. (babel/babel#9367)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To the future! 🚀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
if (isHerokuEnv) return; | ||
return require('preconstruct').aliases.webpack(path.join(__dirname, '..', '..', '..')); | ||
} catch (e) {} | ||
})(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -27,17 +30,17 @@ class CloudinaryBlock extends Block { | |||
auxList = createAuxList(auxListKey, { | |||
fields: { | |||
// We perform the requires here to avoid circular dependencies |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// We perform the requires here to avoid circular dependencies |
This is a continuation of things discussed in #927.
The tool is essentially a fork of preconstruct, there's a bunch of stuff I'm going to rip out though that this tool won't need so I wouldn't recommend reviewing the implementation of this right now.
Something that I would like to hear thoughts on is the API, I've converted
@keystone-alpha/fields-wysiwyg-tinymce
and it works. Below is essentially the most important part of the API, to import views, you callimportView
which you import from@keystone-alpha/build-field-types
https://github.com/keystonejs/keystone-5/blob/7eddd38ca4de25aca4f6754e99670e3ccb1c86ce/packages/fields-wysiwyg-tinymce/src/index.js#L1-L20
TODO