ES6模块和commonjs模块的区别
Posted 等风来
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ES6模块和commonjs模块的区别相关的知识,希望对你有一定的参考价值。
1. commonjs模块输出的是值的浅拷贝,ES6模块输出的是值的引用 (也就是说,cmmonjs模块输出后被改变,其他引用模块不会改变,而ES6模块会改变)
2. commonjs模块是运行时加载,而ES6模块是编译时输出接口,之所以webpack的tree-shaking只能作用于ES6模块,就是因为ES6模块在编译时就能确定依赖
!--5f39ae17-8c62-4a45-bc43-b32064c9388a:W3siYmxvY2tJZCI6IjM0NTUtMTU4ODkxODM5MTM3NSIsImJsb2NrVHlwZSI6InBhcmFncmFwaCIsInN0eWxlcyI6eyJhbGlnbiI6ImxlZnQiLCJpbmRlbnQiOjAsInRleHQtaW5kZW50IjowLCJsaW5lLWhlaWdodCI6MS43NSwiYmFjay1jb2xvciI6IiIsInBhZGRpbmciOiIifSwidHlwZSI6InBhcmFncmFwaCIsInJpY2hUZXh0Ijp7ImRhdGEiOlt7ImNoYXIiOiJDIiwic3R5bGVzIjp7ImNvbG9yIjoiIzU5NTk1OSJ9fSx7ImNoYXIiOiJvIiwic3R5bGVzIjp7ImNvbG9yIjoiIzU5NTk1OSJ9fSx7ImNoYXIiOiJtIiwic3R5bGVzIjp7ImNvbG9yIjoiIzU5NTk1OSJ9fSx7ImNoYXIiOiJtIiwic3R5bGVzIjp7ImNvbG9yIjoiIzU5NTk1OSJ9fSx7ImNoYXIiOiJvIiwic3R5bGVzIjp7ImNvbG9yIjoiIzU5NTk1OSJ9fSx7ImNoYXIiOiJuIiwic3R5bGVzIjp7ImNvbG9yIjoiIzU5NTk1OSJ9fSx7ImNoYXIiOiIuIiwic3R5bGVzIjp7ImNvbG9yIjoiIzU5NTk1OSJ9fSx7ImNoYXIiOiJqIiwic3R5bGVzIjp7ImNvbG9yIjoiIzU5NTk1OSJ9fSx7ImNoYXIiOiJzIiwic3R5bGVzIjp7ImNvbG9yIjoiIzU5NTk1OSJ9fS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GFyIjoiYiIsInN0eWxlcyI6eyJjb2xvciI6IiM1OTU5NTkifX0seyJjaGFyIjoicCIsInN0eWxlcyI6eyJjb2xvciI6IiM1OTU5NTkifX0seyJjaGFyIjoiYSIsInN0eWxlcyI6eyJjb2xvciI6IiM1OTU5NTkifX0seyJjaGFyIjoiYyIsInN0eWxlcyI6eyJjb2xvciI6IiM1OTU5NTkifX0seyJjaGFyIjoiayIsInN0eWxlcyI6eyJjb2xvciI6IiM1OTU5NTkifX0seyJjaGFyIjoiICIsInN0eWxlcyI6eyJjb2xvciI6IiM1OTU5NTkifX0seyJjaGFyIjoi55qEIiwic3R5bGVzIjp7ImNvbG9yIjoiIzU5NTk1OSJ9fSx7ImNoYXIiOiLmjIkiLCJzdHlsZXMiOnsiY29sb3IiOiIjNTk1OTU5In19LHsiY2hhciI6IumcgCIsInN0eWxlcyI6eyJjb2xvciI6IiM1OTU5NTkifX0seyJjaGFyIjoi5YqgIiwic3R5bGVzIjp7ImNvbG9yIjoiIzU5NTk1OSJ9fSx7ImNoYXIiOiLovb0iLCJzdHlsZXMiOnsiY29sb3IiOiIjNTk1OTU5In19LHsiY2hhciI6IuWuniIsInN0eWxlcyI6eyJjb2xvciI6IiM1OTU5NTkifX0seyJjaGFyIjoi546wIiwic3R5bGVzIjp7ImNvbG9yIjoiIzU5NTk1OSJ9fV0sImlzUmljaFRleHQiOnRydWUsImtlZXBMaW5lQnJlYWsiOnRydWV9LCJsZXZlbCI6MSwiaW5kZXgiOjQsImxpc3RJZCI6IjgwODAtMTU4ODg0MjU2NTE1MCIsImxpc3RUeXBlIjoidW5vcmRlcmVkIn1d-->以上是关于ES6模块和commonjs模块的区别的主要内容,如果未能解决你的问题,请参考以下文章