Skip to content
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

fix: dynamic rich text rendering #5580

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions src/components/Contentful/DynamicRichText.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ export default {
KvContentfulImg: defineAsyncComponent(() => import('@kiva/kv-components/vue/KvContentfulImg')),
ButtonWrapper: defineAsyncComponent(() => import('#src/components/Contentful/ButtonWrapper')),
},
props: {
},
};
},
elementClasses() {
Expand All @@ -52,16 +50,7 @@ export default {
}
},
render() {
return h(
'div', /* Wrap output in a div since Vue templates must have 1 root element */
[
h(this.dynamicComponent, {
class: this.elementClasses,
props: {
},
})
]
);
return h(this.dynamicComponent, { class: this.elementClasses });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to blend in props here or is that automatic?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should just work

}
};
</script>
171 changes: 90 additions & 81 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,95 +27,104 @@ const imagesRegex = /images\/.+\.(png|jpe?g|gif|webp|avif|svg|ico)/;
const mediaRegex = /media\/.+\.(mp4|webm|ogg|mp3|wav|flac|aac)/;

// https://vitejs.dev/config/
export default defineConfig({
assetsInclude: [
'**/*.bin',
'**/*.wasm',
],
// Force all assets/vite calls through /static in dev mode, compiled mode is covered by the build config below
base: isProd ? '/' : '/static/',
// Use /static for all assets in prod mode
build: {
assetsDir: 'static',
assetsInlineLimit: (filePath, content) => {
const size = content.length;
if (fontsRegex.test(filePath) || mediaRegex.test(filePath)) {
return size <= 10000;
}
if (imagesRegex.test(filePath)) {
return size <= 1; // could be 10000 but we'd need to exclude apple-touch-icons
}
// vite default
return size <= 4096;
},
},
css: {
postcss: {
plugins: isProd ? [
autoprefixer,
cssnano,
tailwindcss,
] : [
tailwindcss,
],
export default defineConfig(({ isSsrBuild, mode }) => {
return {
assetsInclude: [
'**/*.bin',
'**/*.wasm',
],
// Force all assets/vite calls through /static in dev mode, compiled mode is covered by the build config below
base: isProd ? '/' : '/static/',
// Use /static for all assets in prod mode
build: {
assetsDir: 'static',
assetsInlineLimit: (filePath, content) => {
const size = content.length;
if (fontsRegex.test(filePath) || mediaRegex.test(filePath)) {
return size <= 10000;
}
if (imagesRegex.test(filePath)) {
return size <= 1; // could be 10000 but we'd need to exclude apple-touch-icons
}
// vite default
return size <= 4096;
},
},
preprocessorOptions: {
scss: {
css: {
postcss: {
plugins: isProd ? [
autoprefixer,
cssnano,
tailwindcss,
] : [
tailwindcss,
],
},
preprocessorOptions: {
scss: {
// Suppress deprecation warnings from node modules
quietDeps: true,
quietDeps: true,
},
},
},
},
define: {
UI_COMMIT: JSON.stringify(gitRevisionPlugin.commithash()),
UI_BRANCH: JSON.stringify(gitRevisionPlugin.branch()),
UI_TAG: JSON.stringify(gitRevisionPlugin.version()),
},
plugins: [
vue({
template: {
compilerOptions: {
compatConfig: {
MODE: 3,
define: {
UI_COMMIT: JSON.stringify(gitRevisionPlugin.commithash()),
UI_BRANCH: JSON.stringify(gitRevisionPlugin.branch()),
UI_TAG: JSON.stringify(gitRevisionPlugin.version()),
},
plugins: [
vue({
template: {
compilerOptions: {
compatConfig: {
MODE: 3,
},
},
},
}),
// load .graphql and .gql files
graphQLLoader(),
// load svg files as vue components
svgLoader({
svgoConfig: {
plugins: [
{ name: 'removeTitle', active: false },
],
},
}),
// svg icon sprite sheet
svgStore({
dirs: ['src/assets/icons/sprite'],
symbolId: 'icon-[name]',
optimizeOptions: {
floatPrecision: 3,
},
}),
],
resolve: {
alias: {
// alias src directory
'#src': resolve('src'),
// alias promise module to handle timesync calling require('promise')
promise: resolve('build/promise.js'),
// this alias is required for the rendering of src/components/Contentful/DynamicRichText.vue
// it should only be used on the client build in production
// eslint-disable-next-line max-len
...(isSsrBuild === false && mode === 'production' && { vue: path.resolve(__dirname, 'node_modules', 'vue', 'dist', 'vue.esm-bundler.js') })
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main change in this PR.
We have to use 'vue' as the alias target, and the 'vue.esm-bundler.js' build. And we can only have this alias for the client side production build.

},
}),
// load .graphql and .gql files
graphQLLoader(),
// load svg files as vue components
svgLoader({
svgoConfig: {
plugins: [
{ name: 'removeTitle', active: false },
],
},
}),
// svg icon sprite sheet
svgStore({
dirs: ['src/assets/icons/sprite'],
symbolId: 'icon-[name]',
optimizeOptions: {
floatPrecision: 3,
},
}),
],
resolve: {
alias: {
// alias src directory
'#src': resolve('src'),
// alias promise module to handle timesync calling require('promise')
promise: resolve('build/promise.js'),
// required for src/components/Contentful/DynamicRichText.vue
vue$: 'vue/dist/vue.esm-browser.js',
extensions: ['.mjs', '.js', '.mts', '.ts', '.jsx', '.tsx', '.json', '.vue'],
},
extensions: ['.mjs', '.js', '.mts', '.ts', '.jsx', '.tsx', '.json', '.vue'],
},
server: {
hmr: {
server: {
hmr: {
// Use a different client port to allow Caddy to reverse proxy with SSL cert
clientPort: 24679,
port: 24678,
clientPort: 24679,
port: 24678,
},
},
optimizeDeps: {
include: [
'vue',
],
},
},
};
});
Loading