index.js 371 B

123456789101112
  1. console.log('index.js加载')
  2. // import {mul} from './test'
  3. //懒加载 点击按钮时再加载test.js 不会重复加载
  4. document.getElementById("btn").onclick = function(){
  5. //分割代码 webpackPrefetch:true 预加载:提前加载js文件
  6. import(/* webpackChunkName: 'test',webpackPrefetch: true */'./test').then(({mul})=>{
  7. console.log(mul(3,5))
  8. })
  9. }