neutrinojs / neutrino

Create and build modern JavaScript projects with zero initial configuration.
https://neutrinojs.org
Mozilla Public License 2.0
3.95k stars 213 forks source link

Use multiple presets with compile rules. #1549

Closed andresmrm closed 4 years ago

andresmrm commented 4 years ago

My package is a library with some React components. Something like:

src
├── components
│   ├── A.js
│   └── B.js
├── functions
│   ├── x.js
│   └── y.js
└── index.js

If I only use @neutrinojs/react-components, it only builds the components folder. If I only use @neutrinojs/library, it crashes complaining about React JSX syntax.

I tried to:

module.exports = {
  options: {
    root: __dirname,
  },
  use: [
    reactComponents(),
    library({
      name: "libname",
    }),
  ],
};

And got: DuplicateRuleError: @neutrinojs/compile-loader has been used twice with the same ruleId of 'compile', which would overwrite the existing configuration. If you are including this preset manually to customise rules configured by another preset, instead use that preset's own options to do so.

Tried to add index.js to react-components mains, but it ignored it and only built the components.

I investigated both presets source codes, but couldn't find how to solve this case without creating a new preset replicating most of the code in them.

So, what would be the "neutrino's way" of doing this type of customization?

edmorley commented 4 years ago

@andresmrm Hi! Sorry for the delayed reply.

One way to do this would be to use both presets but via separate builds, using: https://neutrinojs.org/usage/#generating-multiple-builds

andresmrm commented 4 years ago

Thanks for the reply! I ended up using webpack directly.