鍍金池/ 問答/HTML/ 使用webpack時(shí) 如何讓某段代碼不編譯

使用webpack時(shí) 如何讓某段代碼不編譯

使用webpack時(shí) 如何讓某段代碼不編譯

回答
編輯回答
薄荷糖

我的理解,webpack如果什么loader、plugin都不加的話,webpack 不會更改代碼中除 import 和 export 語句以外的部分,就是es6也需要有babel-loader之類的來處理。所以你說的某段代碼應(yīng)該是說loader的處理希望對某個模塊的某一部分進(jìn)行排除的話,這個應(yīng)該需要自己來寫loader才行,一般通用的loader的都是以模塊為最小單元處理,

剛看了下了評論,題主再問使用uglifyjs-webpack-plugin這個插件的問題;可以看看compress-options參數(shù);

drop_console (default: false) -- Pass true to discard calls to console.* functions. If you wish to drop a specific function call such as console.info and/or retain side effects from function arguments after dropping the function call then use pure_funcs instead.

pure_funcs (default: null) -- You can pass an array of names and UglifyJS will assume that those functions do not produce side effects. DANGER: will not check if the name is redefined in scope. An example case here, for instance var q = Math.floor(a/b). If variable q is not used elsewhere, UglifyJS will drop it, but will still keep the Math.floor(a/b), not knowing what it does. You can pass pure_funcs: [ 'Math.floor' ] to let it know that this function won't produce any side effect, in which case the whole statement would get discarded. The current implementation adds some overhead (compression will be slower).

可以知道,其實(shí)pure_funcs提供了使用者來保持書寫的代碼不被改動的功能,題主可以具體實(shí)驗(yàn)下。

2017年12月27日 19:46