rollup-plugin-esbuild
rollup-plugin-esbuild copied to clipboard
`define` not work like @rollup/plugin-replace
I try to build my plugin, this is original rollup config of plugins
configs.push({
// ignore
plugins: [
replace({
preventAssignment: true,
values: {
__DEV__:
format === 'esm'
? `(process.env.NODE_ENV !== 'production')`
: 'false',
},
}),
typescript({
clean: true,
}),
resolve(),
commonjs(),
format !== 'esm' &&
terser({
output: { comments: false },
compress: {
drop_console: true,
},
}),
],
});
Then try to use rollup-plugin-esbuild
to replace @rollup/plugin-replace
and rollup-plugin-typescript2
, like below
configs.push({
// ignore
plugins: [
esbuild({
minify: process.env.NODE_ENV === 'production',
define: {
__DEV__:
format === 'esm'
? '"(process.env.NODE_ENV !== \'production\')"'
: 'false',
},
}),
resolve(),
commonjs(),
format !== 'esm' &&
terser({
output: { comments: false },
compress: {
drop_console: true,
},
}),
],
});
My expected result is that when format === 'esm'
, __DEV__
is replaced with process.env.NODE_ENV !== 'production'
, for example:
// input
const foo = __DEV__ ? 'is development' : 'is production'
// output
const foo = process.env.NODE_ENV !== 'production' ? 'is development' : 'is production'
But current, I got below
// input
const foo = __DEV__ ? 'is development' : 'is production'
// output
const foo = 'is development'
I'm not sure how to set it up correctly, is there something I'm doing wrong?
i have the same problem
me too
same too
See https://github.com/evanw/esbuild/issues/630#issuecomment-752689237
However, You can still use @rollup/plugin-replace
in rollup plugins.