Plugins: Plugin Strip is incompatible with TypeScript plugins

Created on 18 Nov 2019  ·  6Comments  ·  Source: rollup/plugins

  • Rollup Plugin Name: Plugin Strip
  • Rollup Plugin Version: 1.3.1
  • Rollup Version: 1.27.2
  • Operating System (or Browser): Windows 10
  • Node Version: 12.13.0

How Do We Reproduce?

Create a new project, install rollup, @rollup/plugin-strip, typescript and rollup-plugin-typescript2 (or rollup-plugin-typescript). Create rollup.config.js and add a minimal configuration which includes any typescript file input and the plugins above.
Such as this one:

import strip from '@rollup/plugin-strip';
import ts from 'rollup-plugin-typescript2';  // same issue with rollup-plugin-typescript

export default {
  input: 'input.ts',
  output: {
    file: 'output.bundle.js',
    format: 'cjs',
  },
  plugins: [
    ts(),
    strip(),
  ]
}

Expected Behavior

The plugin should remove debugger, console.*, assert.equal.

Actual Behavior

The plugin doesn't affect the output.

x⁶ ⋅ invalid 💩 template incomplete 🔌 plugin-strip

Most helpful comment

@FedericoCarboni

plz try this below, it's work for me

    strip({
      include: [
        '**/*.js',
        '**/*.ts',
      ],
      functions: [
        'console.*',
      ],
    }),

All 6 comments

Please consult the issue template for instructions on providing a proper reproduction.

@FedericoCarboni Can you please post a GitHub repository link that demonstrates the issue you are having? It needs to at least have:

  • input.ts file with console.log()
  • package.json containing the applicable dependencies
  • rollup.config.js file as you mention above
  • output.bundle.js file that is generated incorrectly as you state

Also, provide the exact command you are running to run rollup.

We receive a lot of these issues and having the proper reproduction steps in place helps us solve you issue more quickly. We might also be able to spot out an issue in how you have configured, if one such exists.

Thanks again!

same issue

@FedericoCarboni

plz try this below, it's work for me

    strip({
      include: [
        '**/*.js',
        '**/*.ts',
      ],
      functions: [
        'console.*',
      ],
    }),

It seems that (still ?) does not work with strip 2.0.0

  • When using default config:
  plugins: [
    ts(),
    strip(),
  ]

the output still has console.* in it (as expected since the default include does not target .ts files)

  • When explicitly targeting .ts files:
  plugins: [
    ts(),
    strip({
      include: ['**/*.ts'],
    }),
  ]

an error occurs

[!] (plugin strip) SyntaxError: Unexpected token (3:11)

as a matter of fact, the line of the error in my code is indeed a specific TS definition (it's pointing out the TS : variable type definition token):

let payload: Payload
//         ^

But I'm actually not sure the strip plugin is supposed to support TS, is it ?
If it is, I'll open a new issue with further details to reproduce

@rollup/plugin-typescript: 4.1.2
@rollup/plugin-strip: 2.0.0
rollup: 2.23.0

@sylver @FedericoCarboni

because @rollup/plugin-typescript run in buildStart life cycle (here the code),

it compile ts file at rollup first,

so it is incompatible with @rollup/plugin-strip,

means, if signale.info('xxxx') in your ts code,

no matter what plugins order, that @rollup/plugin-strip will receive code like signale_1.default.info('xxxx').

only legacy package rollup-plugin-typescript will work to me,

import typescript from 'rollup-plugin-typescript'

export default {
  ...,

  plugins: [
    typescript(),
    strip({
      include: [
        'src/**/*.(js|ts)',
      ],
      functions: [
        'signale.*',
      ],
    }),
  ],
}

Was this page helpful?
0 / 5 - 0 ratings