gpt4 book ai didi

webpack - 将 Monaco Editor 集成到 ember Octane 中

转载 作者:行者123 更新时间:2023-12-02 06:06:30 30 4
gpt4 key购买 nike

我尝试整合monaco code编辑器进入我的 ember 辛烷值应用程序。目前我正在使用 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();
};

但是在构建我的应用程序时,我总是收到错误消息:

Module parse failed: Unexpected token (8:0) You may need an appropriate loader to handle this file type.





(node:7993) UnhandledPromiseRejectionWarning: Error: webpack returned errors to ember-auto-import



谁能帮助我并告诉我如何将 monaco 正确集成到我的 ember 应用程序中?
非常感谢!

最佳答案

我强烈建议使用 ember-monaco而不是 monaco-editor,除非以下情况全部正确:您已经成功使用了 Embroider,ember-monaco 缺少一个无法添加到该包中的关键功能,您可以投入大量精力手动设置它Ember 应用程序(数周)。

为了在 Ember 应用程序中使用 Webpack 插件,您还需要安装和使用 Embroider .常规的 ember-cli 构建根本不使用 Webpack,因此 Webpack 插件将不起作用。

如果您 promise 直接使用 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()],
    },
    },
    // ...

    关于webpack - 将 Monaco Editor 集成到 ember Octane 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60112076/

    30 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com