代码镜像主题在Web包中不起作用

时间:2018-05-06 04:56:51

标签: typescript webpack codemirror webpack-style-loader

实际上,在我的项目中,我需要使用代码镜像在突出显示的版本中显示代码片段。但我面临一些问题。请检查以下信息。

技术背景:打字稿,网络包。

包装Json:

 "devDependencies": {
    "css-loader": "^0.28.11",
    "style-loader": "^0.21.0"
  }

Web Pack配置文件

module: {
rules: [
    {
        test: /\.css$/,
        use: [
            require.resolve('style-loader'),
            {
                loader: require.resolve('css-loader'),
                options: {
                    importLoaders: 1,
                    url: false
                },
            }
        ],
    },
]

},

实际上,加载了css文件,但未应用代码镜像

The html code is converted but not theme applied

参见检查员模式

See the themes are not applied

我犯了什么错误。

在我的index.ts文件中,我导入代码镜像,如下所示

import * as CodeMirror from 'codemirror';

import 'codemirror/mode/javascript/javascript';
import 'codemirror/mode/css/css.js';

import './codemirror.css';
import  './gruvbox-dark.css';

然后在功能模块中,我使用代码镜像插件传输了代码片段,如下所示。

myCodeMirror = CodeMirror(html element, {
            value: code-snippet content,
            lineNumbers: false,
            mode: 'text/html'
        });

2 个答案:

答案 0 :(得分:0)

首先,要使用模式text/html,您应该导入codemirror/mode/xml/xml

然后,在codemirror配置中,添加theme字段以启用导入的主题。

theme: 'gruvbox-dark'

答案 1 :(得分:0)

最后,我找到了解决方案,

为了使用模式:' text / html'在代码镜像中,我需要从node-modules导入以下文件。

import' codemirror / mode / htmlmixed / htmlmixed.js&#39 ;;