laravel webpack填坑(陆续更)

时间:2022-01-08 04:18:55
  • ie Promise支持需引入babel-polyfill, 在官方文档中js函数介绍有点少导致按babel-polyfill官方引入时找不到北
    //webpack.mix.js
    mix.js(['node_modules/babel-polyfill/lib/index.js', 'resources/assets/js/admin.js'], 'public/js/admin.js')
         //node_modules/laravel-mix/src/Api.js
    /**
    * Register the Webpack entry/output paths.
    *
    * @param {string|Array} entry
    * @param {string} output
    */
    js(entry, output) {
    Verify.js(entry, output); entry = [].concat(entry).map(file => new File(file));
    output = new File(output); Config.js.push({ entry, output }); return this;
    }
  • 使用chunk时真的不知道多个入口文件用mix怎么弄,官方文档中就是说 - 哎呀我有extract这个方法,你自己研究去吧。。。
         //node_modules/laravel-mix/src/Api.js
    /**
    * Register vendor libs that should be extracted.
    * This helps drastically with long-term caching.
    *
    * @param {Array} libs
    * @param {string} output
    */
    extract(libs, output) {
    Config.extractions.push({ libs, output }); return this;
    };
     //第二个参数可以alias
    extract(['vue'], 'public/js/app_vendor.js') //多个入口文件
    mix.js('resources/assets/js/app.js', 'public/js').extract(['vue'], 'public/js/app_vendor.js')
       .js(['node_modules/babel-polyfill/lib/index.js', 'resources/assets/js/admin.js'], 'public/js/admin.js').extract(['vue'], 'public/js/admin_vendor.js')

    laravel文档就是相当的稳,不断训练我们直面源码:)

#laravel文档写得真好

end