2

I'm looking for a way to disable chunkhash in neutrino.js when building, but didn't find any documentation about it, anyone could help?

Updated:

As in webpack, I can customize the output.filename, in neutrino.js, it seems the string "[name].[hash].bundle.js" is baked in, and there's no way to remove [hash] as far as I can see.

Sam Chen
  • 1,933
  • 16
  • 24
  • Can you clarify if you want to remove the chunk hash from the output filenames, or if you want to disable file chunking altogether? – Eli Aug 17 '17 at 13:59
  • @Eli I want to remove the chunk hash from the output filenames. – Sam Chen Aug 17 '17 at 14:29

1 Answers1

1

In your .neutrinorc.js file, you can add an additional override function to change the output filename to not include the chunk hash (using neutrino-preset-react as an example:

module.exports = {
  use: [
    'neutrino-preset-react',
    (neutrino) => {
      // the original value of filename is "[name].[chunkhash].js"
      neutrino.config.output.filename('[name].js');
    }
  ]
};

If you want to change build targets based on an environment variable:

module.exports = {
  use: ['neutrino-preset-react'],
  env: {
    NEUTRINO_TARGET: {
      desktop: {
        use: [
          (neutrino) => neutrino.config.output.filename('[name].js');
        ]
      },
      mobile: {
        use: [
          (neutrino) => neutrino.config.entry('mobile').add('index.mobile.js');
        ]
      }
    }
  }
};

Then you can run Neutrino twice with differing environments:

NEUTRINO_TARGET=desktop neutrino build
NEUTRINO_TARGET=mobile neutrino build
Eli
  • 17,397
  • 4
  • 36
  • 49
  • Wow, it did work. I have tried it with neutrino cli before, but this one didn't work: `neutrino build --use neutrino-preset-react --options.entry index.mobile.js --options.output mobile --opions.output.filename '[name].js'`. The reason I want to run it with npm scripts is I need to build both desktop and mobile version, but `.neutrinorc.js` file seems only support one target. – Sam Chen Aug 18 '17 at 02:15
  • You can differ them by an environment variable if that helps, I'll update accordingly. – Eli Aug 18 '17 at 04:19
  • Unfortunately, the `env` part doesn't work. Looks like those middleware inside `use` of the `desktop` doesn't get run. I just added a `console.log(1);` to test it, no output in the terminal. – Sam Chen Aug 18 '17 at 13:30
  • I know this is two years back but would you happen to know how to output only 1 file ? – Victor Jozwicki Oct 10 '19 at 13:59