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

Solution for using with FuseBox #7

Closed
hollowcat opened this issue Jun 15, 2019 · 1 comment
Closed

Solution for using with FuseBox #7

hollowcat opened this issue Jun 15, 2019 · 1 comment

Comments

@hollowcat
Copy link

Hello.
It appears that Asyngular loads wsEngine dynamically with a computed require:

[86] let wsEngine = typeof opts.wsEngine === 'string' ? require(opts.wsEngine) : opts.wsEngine;

This causes two problems with the FuseBox bundler. First, it cannot detect that it needs to bundle the ws package, which thus needs to be added to imports. Second, its runtime api then cannot resolve:
https://fuse-box.org/docs/production-builds/quantum-configuration#computed-statement-resolution

Here is how to fix it.

Inside the template produced by Asyngular, remove everything express (as FuseBox provides its own dev server) and add the explicit import:

require('ws'); // otherwise fuse-box won't see that it is used and bundle it

Inside the FuseBox script, apply the api patch:

fuse.js
...

const fuse =  FuseBox.init({
  homeDir : ".",
  output : "dist/$name.js",
  target : "server@esnext",
  useTypescriptCompiler : true,
  plugins: [
    JSONPlugin(),
    QuantumPlugin({
      bakeApiIntoBundle: "server",
      target: "server",
      /*--- begin patch ---*/
      api: core => {
        core.solveComputed("asyngular-server/server.js", {
          mapping: "^ws/index.js",
          fn: (statement, core) => { statement.setExpression(" 'ws/index.js' ") }
        });
        //core.solveComputed("express/lib/view.js", ...);
      }
      /*--- end patch ---*/
    })
  ]
});

fuse
  .bundle("server")
  .instructions("> server/server.js")
  .completed(proc => proc.start());

fuse.run();

fuse.dev({
  root: "dist",
  fallback: "index.html"
});

express/lib/view.js was another file that caused trouble, should be fixable by analogy if you need express.

Perhaps this issue could be addressed to work readily by avoiding the dynamic require.

@jondubois
Copy link
Member

Dynamic require is a very useful and commonly used feature. I think this is likely a problem with FuseBox and not with this project.

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

2 participants