Skip to content

Usage with Module Federation #24

@Ryaryu

Description

@Ryaryu

Hi, I'm trying to use this library in a Module Federation application, but I'm getting the error: grapesjs is not defined.

The error seems to occur here: https://github.com/Developer-Plexscape/ngx-grapesjs/blob/master/projects/ngx-grapesjs/src/lib/editor.component.ts
The declared var is not exported by webpack, and the code assumes the script will be loaded from angular.json, which the MF module doesn't loads. So when the Editor Component tries to load grapesjs, it fails since grapesjs was never defined...
I'm failing to make webpack export the script... Any tips on how to make this work?

My webpack.config.js:

const {
  shareAll,
  withModuleFederationPlugin,
  share,
} = require('@angular-architects/module-federation/webpack');
const LiveReloadPlugin = require('webpack-livereload-plugin');

module.exports = withModuleFederationPlugin({
  name: 'APP',

  exposes: {
    './Module': './src/app/exposed/exposed.module.ts',
    'grapesjs': 'grapesjs',
  },

  shared: {
    ...share({
      //...
    }),
  },
});

module.exports.plugins.push(new LiveReloadPlugin());

My angular.json:

  //...
  "build": {
    "builder": "ngx-build-plus:browser",
    "options": {
      "outputPath": "dist/remote",
      "index": "src/index.html",
      "polyfills": ["zone.js"],
      "tsConfig": "tsconfig.app.json",
      "inlineStyleLanguage": "scss",
      "assets": ["src/favicon.ico", "src/assets"],
      "styles": [
         "src/styles.scss",
         "node_modules/grapesjs/dist/css/grapes.min.css"
      ],
      "scripts": [
        "node_modules/grapesjs/dist/grapes.min.js",
        "node_modules/grapesjs-preset-webpage/dist/index.js",
        "node_modules/grapesjs-blocks-basic/dist/index.js"
      ],
  //...

My package.json:

  //...
  "dependencies": {
    "@angular/animations": "~17.2.0",
    "@angular/common": "~17.2.0",
    "@angular/compiler": "~17.2.0",
    "@angular/core": "~17.2.0",
    "@angular/forms": "~17.2.0",
    "@angular/material-moment-adapter": "^16.0.0",
    "@angular/platform-browser": "~17.2.0",
    "@angular/platform-browser-dynamic": "~17.2.0",
    "@angular/router": "~17.2.0",
    "grapesjs": "^0.21.12",
    "grapesjs-blocks-basic": "^1.0.2",
    "grapesjs-preset-webpage": "^1.0.3",
    "ngx-grapesjs": "^17.0.0",
   //...

I'm forced to use angular 17 so i picked ngx-grapesjs version that used Angular 17.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions