NPM in Fuse 1.6

Lots of great changes in Fuse 1.6!

First thing I’ve noticed is uno build now runs npm install if it finds package.json file in project folder.

I hoped that means we can now NPM modules straight away in ES6 code (as clearly there’s transpilation going on), but looks that’s not the case - unless I am missing some trick?

Is having webpack/rollup necessary to use modules from NPM?

Good question, like to know that too.

Hi! That unfortunately does not mean we support using NPM modules directly in Fuse. You can use something like webpack, or perhaps give nfuse a shot. Please also note that a lot of packages depend on being run in a browser/node.js environment, and will not necessarily work with Fuse.

OK, no worries - I already had some success with webpack, so that’s not a major deal, but there’s one more question in that case!

uno build automatically runs npm install as a part of build process, but is there anything else it could run automatically, or do I have to hook into post-install somehow to execute webpack build?

Uno does unfortunately not support build scripts yet, but NPM does :slight_smile: You can add a postinstall script to your package.json that will be run after every npm install, like this:

{
    "scripts": {
        "postinstall": "<your script here>"
    }
}

Yeah, that what I was talking about! What I was missing though is that NPM can does that w/o any extra trickery - thanks!

Apparently there’s more to it!

Once I added webpack setup in a TodoExample project (Fuse 1.6 demo), created functions.js file containing exported functions that make use of NPM modules (all vetted and adapted for Fuse - had it working in 1.5), I am now getting the following output when running uno build:

Uno 1.6.0 (build 6434) macOS 10.13 x86_64 40f9a34
Copyright © 2015-2018 Fusetools

Configuring
ERROR: node_modules/fsevents/node_modules/mkdirp/bin/cmd.js: 'return' outside of function (13:4)
  11 | if (argv.help) {
  12 |     fs.createReadStream(__dirname + '/usage.txt').pipe(process.stdout);
> 13 |     return;
     |     ^
  14 | }
  15 |
  16 | var paths = argv._.slice();
(...)

Now, I have no idea where these are coming from - none of the modules I am importing in my functions.js are using fsevents or any other module mentioned in output log (there’s mkdirp, user-home and webpack included). It looks like Babel transpiller launched by uno build tries to touch everything that’s in my node_modules folder?

Apparently this is easily solved by adding node_modules to exclude list in your .unoproj file

@Maciek Szczesniak - this seems really cool. Would it be possible for you to provide a starter project with this set up on something like github? I am not very familiar with Webpack, but I’d love to be able to just ‘npm install --save’ js libraries into my fuse project (compatible ones of course).