UNPKG

2.58 kBJavaScriptView Raw
1"use strict";exports.__esModule=!0;var tslib_1=require("tslib"),LarkLogger_1=require("@kemao/lark/Server/Log/LarkLogger/LarkLogger"),Path=require("path"),webpack=require("webpack"),BrowserBase_1=require("../Core/BrowserBase"),logger=new LarkLogger_1.LarkLogger("VendorPack"),VendorPack=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.type="Browser",e.vendorList=[],e.outDir="./build/Browser",e.production=!1,e.packageTools=null,e.versionType="none",e.version=null,e}return tslib_1.__extends(e,t),e.prototype.setProduciton=function(e){this.production=e},e.prototype.setVersionType=function(e){this.versionType=e},e.prototype.setOutDir=function(e){this.outDir=e},e.prototype.getOutDir=function(){return""===this.version.getVersion()?this.outDir:this.outDir+"/"+this.version.getVersion()},e.prototype.getVendorList=function(){return this.vendorList},e.prototype.hasVendor=function(){return 0<this.vendorList.length},e.prototype.setVendorList=function(e){this.vendorList=e,logger.log("setVendorList",e)},e.prototype.build=function(){return tslib_1.__awaiter(this,void 0,void 0,function(){return tslib_1.__generator(this,function(e){switch(e.label){case 0:return 0<this.vendorList.length?[4,this.pack()]:[3,2];case 1:e.sent(),e.label=2;case 2:return[2]}})})},e.prototype.getVendorJSON=function(){return Path.resolve(this.getOutDir()+"/vendor.json")},e.prototype.pack=function(){return tslib_1.__awaiter(this,void 0,void 0,function(){var t,r,o,n,i,s;return tslib_1.__generator(this,function(e){switch(e.label){case 0:return t=("lark__"+this.type+"__vendor").toUpperCase(),r={entry:{},module:{rules:[]},mode:this.production?"production":"development",devtool:this.production?"none":"source-map",output:{filename:"vendor.js?[hash]",library:t,path:Path.resolve(this.getOutDir())},plugins:[]},o=JSON.stringify("development"),!0===this.production&&(o=JSON.stringify("production")),n={"process.env":{NODE_ENV:o}},r.plugins.push(new webpack.DefinePlugin(n)),r.entry[t]=this.vendorList,r.plugins.push(new webpack.DllPlugin({context:Path.resolve("./build/"+this.type),name:t,path:this.getVendorJSON()})),[4,this.webpack(r)];case 1:return(i=e.sent()).hasErrors()?(s=i.toJson(),s.errors.forEach(function(e){logger.error(e)})):logger.log("pack.end"),[2]}})})},e.prototype.webpack=function(t){return tslib_1.__awaiter(this,void 0,Promise,function(){return tslib_1.__generator(this,function(e){return[2,new Promise(function(r,o){webpack(t).run(function(e,t){null===e?r(t):o({error:e,stats:t})})})]})})},e}(BrowserBase_1.BrowserBase);exports.VendorPack=VendorPack;
\No newline at end of file