filpiro
February 20, 2022, 10:42pm
1
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:
roots:main
← roots:rule-only-include
opened 12:02AM - 21 Feb 22 UTC
## Overview
In regards to `config.module.rules` (`RuleSetItem`).
- remove… s all use of `excludes`, opting instead for `includes` only
- `includes` now specified as an `Array` of `String` or `RegExp` values
This sets us up nicely to provide a facade developers can use to specify directories to resolve source modules from (by default it is restricted to the bud `src` path).
The API already supports this with either a callback (preferred so you can use `bud.path` and other dynamic utils rather than just plunking in strings):
```ts
bud.build.rules.js.setIncludes((bud) => [/* ...paths */])
```
or an array of values: (no problem for an end user to directly set paths like this):
```ts
bud.build.rules.js.setIncludes([/* ...paths */])
```
But eventually we want some sort of function to wrap that API, since it's a little "in the weeds". Maybe something like:
```ts
bud.resolveFrom([/* ...paths */])
bud.resolveFrom(() => [/* ...paths */])
bud.resolveFrom([/* ...paths */], [/* optional -- specify rules to apply to */])
```
refers: none
closes: none
## Type of change
- MINOR: feature
This PR includes breaking changes to the following core packages:
- Technically, this breaks the typings if a user is specifying includes as a string.
- But, it will still technically work as an array or a string.
- Webpack accepts either a string or an array. Going forward, Bud always assuming it is supplied as an array.
This PR includes breaking changes to the follow extensions:
- none
## Dependencies
<!--
- [@roots/bud]: [package]@[version]
-->
### Adds
- none
### Removes
- none
2 Likes
filpiro
February 22, 2022, 8:36pm
3
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