YahooArchive / strip-loader

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

Prevents build when encounters convoluted console.log #25

Open doei opened 7 years ago

doei commented 7 years ago

I'm using strip-loader on a project scaffolded with create-react-app, on which I ran npm run eject

At some point the project wouldn't build anymore, the build process never exited while exhausting all the cpu resources it could find... After trying to build previous commits to find the breaking change, I managed to have the build work fine again by removing this console.log:

        console.log( (selectedWeek === 0 ? 'first_week' : 'second_week') +
            ((startDate.week() + selectedWeek) % 2 === 1 ? "odd" : "even") );

startDate is a moment object if that helps...

Anyway my guess is that this is an issue coming from strip-loader...

Hope it helps

Vijar commented 7 years ago

If you're just stripping console.log, I'd recommend using uglifyjs loader. 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
     }
 })

Uglify js would be able to catch all kinds of convoluted invocations of console.log because it uses an ast parser. Hope this helps.

doei commented 7 years ago

Thanks for the tip, I'll try.