Include node_modules babel Transformation

Hi there,
first of all, i started to use bud + sage 10 and they are fantastic!!
I’m trying to add in babel tranformation code from node_modules like this

app.build.items['babel'].mergeOptions(
    {
      include: 'node_modules',
    },
    app,
  );

But not work, and babel stop to transform code of all project so, I tried to use an hook like this solution, but nothing works.

My configuration is default with bud 5.3.2 and sage 10-beta-3 (i changed only tailwind with bootstrap)

Thank you.

1 Like

I would do it like this:

      app.build.rules.js
        .setExclude(undefined)
        .setInclude([app.path('src'), app.path('project', 'node_modules')]);

bud.build.items maps loaders to options. bud.build.rules is what you want here – the include/exclude paths are defined in regards to webpack rules, not loaders.

The include value(s) must be absolute paths to work in webpack. Your attempt wouldn’t work because 'node_modules' isn’t an absolute path.

app.path will provide you absolute paths or you can resolve them with node.

There is a PR open that will improve this API:

2 Likes

Awesome!!
It’s work.
Thank you

2 Likes

@filpiro We released 5.4.0 and it removes excludes from all of the rules included in core.

The above fix should work without calling setExcludes:

app.build.rules.js.setInclude([
  app.path('src'), 
  app.path('project', 'node_modules'),
]);
2 Likes