YahooArchive / strip-loader

Webpack loader to strip arbitrary functions out of your production code.
Other
282 stars 14 forks source link

webpack 2 - console statements not getting removed #24

Open prajaktagharpure opened 7 years ago

prajaktagharpure commented 7 years ago

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"] } };

Vijar commented 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
     }
 })
sainiabhi commented 7 years ago

Can anyone tell why @prajaktagharpure code is not working? I'm facing the same issue.

tangshuang commented 7 years ago

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.

malaymatwankar commented 6 years ago

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: