首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用vue3 + vite + ckeditor5配置后加载程序

使用vue3 + vite + ckeditor5配置后加载程序
EN

Stack Overflow用户
提问于 2022-03-03 14:39:06
回答 1查看 1.6K关注 0票数 1

我正在将vue3项目从webpack迁移到vite。除了ckeditor,一切都进行得很顺利。在ck-编辑器中,有一个用于执行.css.svg文件transpile的配置。https://ckeditor.com/docs/ckeditor5/latest/builds/guides/integration/frameworks/vuejs-v3.html#configuring-vueconfigjs

我做了一个插件来做这个简单的过程,但它并不完美。

ckeditor.util.ts

代码语言:javascript
复制
const fileRegex = /ckeditor5-[^/\\]+[/\\]theme[/\\]icons[/\\][^/\\]+\.svg$/;
// https://vitejs.dev/guide/api-plugin.html#transforming-custom-file-types
// https://rollupjs.org/guide/en/#plugin-development
export default () => {
  return {
    name: "vite-ckeditor-svg-plugin",
    // https://rollupjs.org/guide/en/#transform
    transform(src, id) {
      if (fileRegex.test(id)) {
        // raw-loader
        src = fs.readFileSync(id, "utf8");
        const json = JSON.stringify(src)
          .replace(/\u2028/g, "\\u2028")
          .replace(/\u2029/g, "\\u2029");
        return {
          code: `export default ${json}`,
          map: { mappings: "" },
        };
      }
    },
    // https://rollupjs.org/guide/en/#generatebundle
    generateBundle(options, bundle) {
      for (const [filename, info] of Object.entries(bundle)) {
        if (fileRegex.test((info as AssetInfo).name)) {
          delete bundle[filename];
        }
      }
    },
  };
};

vite.config.js

代码语言:javascript
复制
import CkeditorUtil from "./src/utils/ckeditor.util";
// https://vitejs.dev/config/
export default defineConfig({
  ...
  plugins: [
    vue(),
    CkeditorUtil(),
  ]
  ...
})

并得到错误

代码语言:javascript
复制
Nested CSS was detected, but CSS nesting has not been configured correctly.
Please enable a CSS nesting plugin *before* Tailwind in your configuration.
See how here: https://tailwindcss.com/docs/using-with-preprocessors#nesting
    @mixin icon {
    ^

我为解决这个问题所做的一切基本上都是https://tailwindcss.com/docs/using-with-preprocessors#nesting,安装postcss-mixins不起作用,最后尝试像这样做另一个插件。

代码语言:javascript
复制
const { styles } = require( '@ckeditor/ckeditor5-dev-utils' );
const fileRegex = /ckeditor5-[^/\\]+[/\\].+\.css$/;
export default () => {
  return {
    name: "vite-postcss-svg-plugin",
    transform(src, id) {
      if (fileRegex.test(id)) {
        src = fs.readFileSync(id, "utf8");
        // try to do like this but getPostCssConfig() is working with webpack  
        // so unable to call this with vite
        // postcssOptions: styles.getPostCssConfig( {
        //                themeImporter: {
        //                    themePath: require.resolve( '@ckeditor/ckeditor5-theme-lark' ),
        //                },
        //                minify: true
        //           } )
        return {
          code: `export default ${json}`,
          map: { mappings: "" },
        };
      }
    },
  };
};

我想我错过了用于转换编辑器导入的.css文件的postcss-加载程序。什么是真正的问题,以及如何使它工作?

EN

回答 1

Stack Overflow用户

发布于 2022-03-08 10:07:36

“‘vite plugin”是简单的“原始加载器”。我用它来解决.svg

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71338959

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档