使用jquery的时候build有问题
haue opened this issue · 5 comments
haue commented
import $ from "jquery";
console.log(1)
上面的代码,在dev下是正常的,控制台输出1
但是build后的代码什么也没有
JesseZhao1990 commented
@haue webpack在production模式会优化代码,压缩、去掉console等,具体的信息查阅webpack文档:https://webpack.js.org/configuration/mode/#mode-production
如果实在不想让其去掉console,或者是只去掉console.log, 保留console.info 等,都可以灵活配置,详细的文档: https://webpack.js.org/plugins/terser-webpack-plugin/#root
最佳实践是生产环境不需要在控制台乱输出内容,可能会带来内存泄露等问题。
JesseZhao1990 commented
haue commented
可能我上面举的例子不太恰当,不能用console.log,但是换做alert('xxxx'),alert语句也是不会执行,很奇怪。
把
import $ from "jquery";
去掉就可以。当然前提我install了jquery,你在引入jquery的时候就没有问题吗?
haue commented
什么原因?
JesseZhao1990 commented
@haue 已修复