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(),
]
}
The plugin should remove debugger, console.*, assert.equal.
The plugin doesn't affect the output.
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 dependenciesrollup.config.js file as you mention aboveoutput.bundle.js file that is generated incorrectly as you stateAlso, 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
plugins: [
ts(),
strip(),
]
the output still has console.* in it (as expected since the default include does not target .ts files)
.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.*',
],
}),
],
}
Most helpful comment
@FedericoCarboni
plz try this below, it's work for me