Closed Xing-He closed 2 years ago
I have dug into the "codemirror", and found that it doesn't support SSR. However, I am still confused with the css compile issue.
I am now trying to use the dynamic import import('codemirror-editor-vue3')
to solve this problem. but how can i define CodeMirror's language? as i can't get the CodeMirror object !
As you said, Codemirror itself does not support SSR, and I have not intended to do this.
As for the dynamic introduction you said, I don't understand it, it is best to provide Demo.
As we can see, I couldn't use CodeMirror on SSR. and couldn't import the codemirror with static import
as below:
import CodeMirror from 'codemirror';
Instead, dynamic import
import('codemirror').then((CodeMirror)=>{ CodeMirror.doSomething() })
Hope I made it clear.
The parent component:
<template>
<button @click="visible = !visible">show modal</button>
<codemirrorDemo v-if="visible" />
</template>
<script lang="ts" setup>
import codemirrorDemo from "./codemirrorDemo.vue";
const visible = ref(false);
</script>
Child components(codemirrorDemo.vue
):
<template>
<Codemirror v-model:value="code" :options="cmOptions" border :height="200" />
</template>
<script lang="ts">
import { ref } from "vue";
import "codemirror/mode/javascript/javascript.js";
const res = await import("codemirror-editor-vue3");
export default defineComponent({
components: {
Codemirror: res.default,
},
setup() {
const code = ref(`const obj = {
name: "peter",
age: 18
};
`);
const cmOptions = {
mode: "javascript", // 语言模式
lineNumbers: true, // 显示行号
smartIndent: true, // 智能缩进
indentUnit: 2, // 智能缩进单位为4个空格长度
foldGutter: true, // 启用行槽中的代码折叠
styleActiveLine: true, // 显示选中行的样式
};
return {
code,
cmOptions,
};
},
});
</script>
Hi there, I just got an problem with SSR
Maybe it's an error of "package conditional exports" because the module invoked "*.umd.js" on the node environment and would not compile "CSS" files
After changing the source file " package.json" exports field, Anther error occurred as below,
And this navigator error must be accessed for the 'navigator' object on Node.js
BTW, I use the 'vite' for compilation