Open prajaktagharpure opened 7 years ago
You can use uglifyjs's drop_console
option. Here is what that would look like in a webpack plugin:
new webpack.optimize.UglifyJsPlugin({
compress: {
drop_console: true
}
})
Can anyone tell why @prajaktagharpure code is not working? I'm facing the same issue.
Do you use babel-loader? Look into your bundle code, console.log
has been tansformed to be (e = console).log
. This is why drop_console not working. And I do not know how to fix this waiting for someone to provide a resolution.
I added this to rules array instead of loaders array
{
test: /\.js$/,
loader: WebpackStrip.loader('console.log','myDebugFunction')
}
and this worked for me. I am not sure as to why it worked in rules and not in loaders as I am new to webpack, so I can not provide a reason to it. :open_mouth:
I am trying to remove simple console statements for the production build and its not working with webpack 2 I suppose. Here is my webpack config file production
var WebpackStrip = require("strip-loader"); module.exports = { entry: "index.js", output: { filename: "bundle.min.js" }, watch: true, module: { loaders: [ { test: /\.js$/, exclude: /node_modules/, loader: "babel-loader" }, { test: [/\.js$/, /\.es6$/], exclude: /node_modules/, loader: WebpackStrip.loader('console.log') } ] }, resolve: { extensions: [".js"] } };