Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use #240

Open
linonetwo opened this issue Jul 10, 2023 · 1 comment
Open

How to use #240

linonetwo opened this issue Jul 10, 2023 · 1 comment

Comments

@linonetwo
Copy link

Add these to webpack rules, install noflo-component-loader coffee-loader fbp-loader

{
    test: /noflo(\\+|\/)lib(\\+|\/)loader(\\+|\/)register.js$/,
    use: [
      {
        loader: 'noflo-component-loader',
        options: {
          // Only include components used by this graph
          // Set to NULL if you want all installed components
          graph: null,
          // Whether to include the original component sources
          // in the build
          debug: true,
          baseDir: __dirname,
          manifest: {
            runtimes: ['noflo'],
            discover: true,
            recursive: true,
          },
          runtimes: [
            'noflo',
            'noflo-browser',
          ],
        },
      },
    ],
  },
  {
    test: /\.coffee$/,
    // load noflo-interaction standard lib, which provide some component in this format
    use: ['coffee-loader'],
  },
  {
    test: /\.fbp$/,
    // load noflo-strings standard lib, which provide some component in this format
    use: ['fbp-loader'],
  },

This shows how this loader use fbp-manifest package, don't forget the recursive: true, otherwise you will get nothing.

// try.mjs
import fbpManifest from 'fbp-manifest';
import path from 'path';
import { fileURLToPath } from 'url';

const __filename = fileURLToPath(import.meta.url);

const __dirname = path.dirname(__filename);

const baseDir = path.resolve(__dirname, '../');

const components = await fbpManifest.load.load(baseDir, {
  runtimes: ['noflo'],
  discover: true,
  recursive: true,
});
// DEBUG: console components
console.log(`components`, components.modules[3]);
linonetwo added a commit to tiddly-gittly/TidGi-Desktop that referenced this issue Jul 10, 2023
@linonetwo
Copy link
Author

See commit above ↑ all installed noflo packages will be detected by fbp-manifest, and packaged to noflo/lib/loader/register as test: /noflo(\\+|\/)lib(\\+|\/)loader(\\+|\/)register.js$/, matched.

You can use packaged std lib by

import { ComponentLoader } from 'noflo';

const loader = new ComponentLoader('');
const componentList = await loader.listComponents();

or

import components from 'noflo/lib/loader/register';
console.log(`components`, components.getSource(loader, 'flow/All', console.log));

图片

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant