Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't work with rollup >= 1.27.0 #79

Closed
targumon opened this issue Dec 5, 2019 · 6 comments
Closed

Doesn't work with rollup >= 1.27.0 #79

targumon opened this issue Dec 5, 2019 · 6 comments

Comments

@targumon
Copy link

targumon commented Dec 5, 2019

  • Rollup Plugin Name: replace
  • Rollup Plugin Version: 2.2.1
  • Rollup Version: 1.27.8
  • Operating System (or Browser): MacOS
  • Node Version: 10.15.3

How Do We Reproduce?

Created a clean project: npm i -y, followed by npm i -d rollup @rollup/plugin-replace, created a small js file with just console.log in it, using the exact rollup.config.js file described under 'Usage' in https://github.com/rollup/plugins/tree/master/packages/replace

Expected Behavior

string replaced in the output

Actual Behavior

string not replaced in the output
warning in terminal: (!) The "transform" hook used by the output plugin replace is a build time hook and will not be run for that plugin. Either this plugin cannot be used as an output plugin, or it should have an option to configure it as an output plugin.

I suspect the problem is related to rollup/rollup#3218
and so I'm guessing it's the documentation of the plugin that needs to be fixed, not the plugin itself.

@lukastaegert
Copy link
Member

lukastaegert commented Dec 5, 2019

Are you sure you placed the plugins option in the correct place? This error can only occur if it is placed inside the output object. In the documentation you linked, it is placed outside the output object.

@lukastaegert
Copy link
Member

Though it might make sense to be able to use this plugin as an output plugin, it is not supported and also would not really make sense as then it would not benefit from tree-shaking.

@shellscape
Copy link
Collaborator

@targumon as the issue template mentions, we need a minimal reproduction to triage this. Without that, there's not much we can do.

Issues without minimal reproductions will be closed! Please provide one by:

  1. Using the REPL at https://rollupjs.org/repl/, or
  2. Work to isolate the problem and provide the exact steps in this issue, or
  3. Provide a minimal repository link (Read https://git.io/fNzHA for instructions).
    These may take more time to triage than the other options.

@targumon
Copy link
Author

targumon commented Dec 8, 2019

Oh, I feel so stupid. I'm not even sure now where did I copy my bad rollup.config.js from (with plugins inside output instead of adjacent to it).

Thanks and my apologies for the trouble!

@targumon targumon closed this as completed Dec 8, 2019
@targumon
Copy link
Author

targumon commented Dec 8, 2019

Found the source of my mistake: before realizing I also need the replace plugin, the first one I used was terser, which is an output plugin... So my initial config had plugins inside output and I naturally thought that that's the place for all plugins.

TL;DR (for whoever gets here from search engines):
There are "regular" plugins and there are output plugins, so your rollup.config.js may contain the plugins option more than once:

export default {
  input: 'index.js',
  output: {
    dir: 'dist',
    format: 'iife', // amd cjs system esm iife umd
    plugins: [
      terser()
    ]
  },
  plugins: [
    replace({'process.env.NODE_ENV': JSON.stringify('production')})
  ]
}

More details here: https://rollupjs.org/guide/en/#using-output-plugins

@marcofugaro
Copy link

I also have this warning when using the replace plugin as an output plugin like this

export default {
  input: 'index.js',
  output: {
    dir: 'dist',
    format: 'iife', // amd cjs system esm iife umd
    plugins: [
      replace({'process.env.NODE_ENV': JSON.stringify('production')}),
      terser(),
    ]
  }
}

In my case, I actually need it on the output bundle and it is allowed since #55. So why there is that warning?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants