ember.js 将monaco编辑器集成到ember octane

093gszye  于 2022-11-05  发布在  其他
关注(0)|答案(1)|浏览(205)

我尝试将monaco code编辑器集成到我的ember octane应用程序中。目前我正在使用ESM导入样式并确认手册,我安装了webpack加载器插件并将其集成到我的ember-cli-build.js中

const EmberApp = require('ember-cli/lib/broccoli/ember-app');
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');

module.exports = function(defaults) {
  let app = new EmberApp(defaults, {
    autoImport: {
      webpack: {
        plugins: [
          new MonacoWebpackPlugin()
        ]
      }
    }
  });

  // Use `app.import` to add additional libraries to the generated
  // output files.
  //
  // If you need to use different assets in different
  // environments, specify an object as the first parameter. That
  // object's keys should be the environment name and the values
  // should be the asset to use in that environment.
  //
  // If the library that you are including contains AMD or ES6
  // modules that you would like to import into your application
  // please specify an object with the list of modules as keys
  // along with the exports of each module as its value.

  return app.toTree();
};

但在构建应用程序时,我总是收到错误消息:
模块剖析失败:意外的标记(8:0)您可能需要适当的加载程序来处理此文件类型。
还有
(node:7993)未处理的承诺拒绝警告:错误:webpack向ember-auto-import返回错误
有人能帮我,告诉我如何正确地将monaco集成到我的ember应用程序中吗?非常感谢!

qgzx9mmu

qgzx9mmu1#

我强烈建议使用ember-monaco而不是monaco-editor,除非以下条件都成立:你已经成功地使用刺绣,ember-摩纳哥是失踪的一个关键功能,是不可能添加到该软件包,你可以致力于显着的努力,设置它的手在Ember应用程序(周).
为了在Ember应用中使用Webpack插件,您还需要安装和使用Embroider。常规的ember-cli构建根本不使用Webpack,因此Webpack插件将无法工作。
如果您决定直接使用monaco-editor,您必须:

  • 使用刺绣
  • 已安装monaco-editor
  • 安装Webpack插件monaco-editor-webpack-plugin
  • 安装一个polyfill(@cardstack/requirejs-monaco-ember-polyfill),然后按照自述文件注册
  • 注册webpack插件并导入css文件

下面是一个ember-cli-build.js文件示例:

'use strict';

process.env.BROCCOLI_ENABLED_MEMOIZE = 'true';

const EmberApp = require('ember-cli/lib/broccoli/ember-app');
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');

module.exports = function(defaults) {
  let app = new EmberApp(defaults, {
    prember: {
      // we're not pre-rendering any URLs yet, but we still need prember because
      // our deployment infrastructure already expects `_empty.html` to exist
      // for handling unknown URLs.
      urls: [],
    },
  });

  app.import('node_modules/monaco-editor/dev/vs/editor/editor.main.css');

  return (function() {
    const Webpack = require('@embroider/webpack').Webpack;
    const { join } = require('path');
    const { writeFileSync } = require('fs');

    return require('@embroider/compat').compatBuild(app, Webpack, {
      staticAddonTestSupportTrees: true,
      staticAddonTrees: true,
      staticHelpers: true,
      staticComponents: true,
      onOutputPath(outputPath) {
        writeFileSync(join(__dirname, '.embroider-app-path'), outputPath, 'utf8');
      },
      packagerOptions: {
        webpackConfig: {
          plugins: [new MonacoWebpackPlugin()],
        },
      },
// ...

相关问题