@doracli/webpack 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +7 -0
- package/lib/cjs/index.js +1 -0
- package/lib/esm/index.js +1 -0
- package/lib/preset/html/dev-preset.html +24 -0
- package/lib/type/index.d.ts +123 -0
- package/package.json +63 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020-2029 zhangzhiguo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
package/lib/cjs/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("webpack"),r=require("@dorabag/file-pro"),t=require("@doracli/helper"),n=require("@doracli/preset-babel"),o=require("path"),i=require("mini-css-extract-plugin"),s=require("terser-webpack-plugin"),a=require("html-webpack-plugin"),u=require("webpack-bundle-analyzer"),c=require("webpackbar"),l=require("webpack-dev-server"),p=require("@dorabag/open-browser"),f=require("@cclr/lang"),d="undefined"!=typeof document?document.currentScript:null;function m(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=Array(r);t<r;t++)n[t]=e[t];return n}function h(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}function g(e,r,t){return r&&function(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,C(n.key),n)}}(e.prototype,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function v(e,r,t){return(r=C(r))in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function b(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable})),t.push.apply(t,n)}return t}function y(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?b(Object(t),!0).forEach(function(r){v(e,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):b(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})}return e}function x(e,r){if(null==e)return{};var t,n,o=function(e,r){if(null==e)return{};var t={};for(var n in e)if({}.hasOwnProperty.call(e,n)){if(-1!==r.indexOf(n))continue;t[n]=e[n]}return t}(e,r);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)t=i[n],-1===r.indexOf(t)&&{}.propertyIsEnumerable.call(e,t)&&(o[t]=e[t])}return o}function w(e){return function(e){if(Array.isArray(e))return m(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,r){if(e){if("string"==typeof e)return m(e,r);var t={}.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?m(e,r):void 0}}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function C(e){var r=function(e,r){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,r);if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(e)}(e,"string");return"symbol"==typeof r?r:r+""}var R=["port"],P=["index","src/index"],j=[".ts",".js",".tsx",".jsx"],O=["index.html","public/index.html"],k=r.getDirname({url:"undefined"==typeof document?require("url").pathToFileURL(__filename).href:d&&"SCRIPT"===d.tagName.toUpperCase()&&d.src||new URL("index.js",document.baseURI).href}),S=r.getPackageRoot(k),U=o.join(S,"node_modules"),q=o.join(S,"lib/preset/html/dev-preset.html"),L=function(){return y({babelrc:!1,configFile:!1,compact:!1,cwd:r.getNodeModulesDir(k)},n.reactBabelPreset())},T=r.requireResolve("undefined"==typeof document?require("url").pathToFileURL(__filename).href:d&&"SCRIPT"===d.tagName.toUpperCase()&&d.src||new URL("index.js",document.baseURI).href,"css-loader"),A=r.requireResolve("undefined"==typeof document?require("url").pathToFileURL(__filename).href:d&&"SCRIPT"===d.tagName.toUpperCase()&&d.src||new URL("index.js",document.baseURI).href,"postcss-loader"),D=r.requireResolve("undefined"==typeof document?require("url").pathToFileURL(__filename).href:d&&"SCRIPT"===d.tagName.toUpperCase()&&d.src||new URL("index.js",document.baseURI).href,"style-loader"),I=r.requireResolve("undefined"==typeof document?require("url").pathToFileURL(__filename).href:d&&"SCRIPT"===d.tagName.toUpperCase()&&d.src||new URL("index.js",document.baseURI).href,"babel-loader"),_=r.requireResolve("undefined"==typeof document?require("url").pathToFileURL(__filename).href:d&&"SCRIPT"===d.tagName.toUpperCase()&&d.src||new URL("index.js",document.baseURI).href,"less-loader"),E=r.requireResolve("undefined"==typeof document?require("url").pathToFileURL(__filename).href:d&&"SCRIPT"===d.tagName.toUpperCase()&&d.src||new URL("index.js",document.baseURI).href,"sass-loader"),z=r.requireResolve("undefined"==typeof document?require("url").pathToFileURL(__filename).href:d&&"SCRIPT"===d.tagName.toUpperCase()&&d.src||new URL("index.js",document.baseURI).href,"postcss-preset-env"),F=function(e,r){var t=e.action,n=(r||{}).postcssPluginExtra,o=[T,{loader:A,options:{postcssOptions:{plugins:[[z]].concat(w(n||[]))}}}];return"server"===t?o.unshift({loader:D}):o.unshift({loader:i.loader}),o},N=["path","filename"],$=["minimize","template"],B=function(e){var r=e.minimize,t=e.template,n=x(e,$);return new a(y({title:"webpack5-react-ts",filename:"index.html",template:t||q,inject:!0,hash:!0,cache:!1,minify:!!r&&{removeAttributeQuotes:!0,collapseWhitespace:!0,removeComments:!0,minifyJS:!0,minifyCSS:!0}},n))};var W=function(){return g(function e(r){h(this,e),v(this,"workRootDir",void 0),this.workRootDir=r},[{key:"apply",value:function(e){var r=this;e.hooks.beforeRun.tapPromise("TsconfigPlugin",function(e){return new Promise(function(n,i){var s,a=function(){try{return n()}catch(e){return i(e)}},u=function(e){try{return t.cLog.error("init","error","自动注入 tsconfig.json 失败"),a()}catch(e){return i(e)}};try{return function(e){var r=[],t=function(e){if(e)if("string"==typeof e)r.push(e);else if(Array.isArray(e))e.forEach(t);else if("object"==typeof e){var n=e;n.import?t(n.import):Object.values(n).forEach(t)}};return t(e),r}(null!==(s=e.options&&e.options.entry)&&void 0!==s?s:{}).some(function(e){return/\.(ts|tsx)$/.test(o.extname(String(e)))})?Promise.resolve(t.insertTsconfig(r.workRootDir)).then(function(e){try{return a()}catch(e){return u()}},u):n()}catch(e){u()}})})}}])}(),M=function(e){return new W(e.workRootDir)},H=e.ProgressPlugin,J=function(){return g(function e(t){h(this,e),v(this,"configCtx",void 0),v(this,"webpackConfig",{}),v(this,"devServerConfig",{}),v(this,"envParams",{action:"build",workRootDir:r.getCwd()}),this.configCtx=t},[{key:"updateEnvParams",value:function(e){this.envParams=y(y({},this.envParams),e)}},{key:"updateWebpackConfig",value:function(e){this.webpackConfig=y(y({},this.webpackConfig),e)}},{key:"updateDevServerConfig",value:function(e){this.devServerConfig=y(y({},this.devServerConfig),e)}},{key:"getDoraConfig",value:function(){return this.configCtx.getDoraConfig()}},{key:"geTDoraConfigWebpack",value:function(){return this.configCtx.getDoraConfig().webpackConfig||{}}}])}(),Q={host:"127.0.0.1",open:!0,setupExitSignals:!0,compress:!1,hot:!0,historyApiFallback:!0,static:[{directory:r.resolveCwd("./public")},{directory:r.resolveCwd("./dist")}],headers:{"Access-Control-Allow-Origin":"*"},port:"8082"},G=["static","headers"],K=function(){for(var e={static:[],headers:{}},r=arguments.length,t=new Array(r),n=0;n<r;n++)t[n]=arguments[n];return t.forEach(function(r){var t,n=r.static,o=r.headers,i=x(r,G);f.isArray(e.static)&&f.isArray(n)&&(t=e.static).push.apply(t,w(n));o&&(e.headers=y(y({},e.headers),o)),Object.assign(e,i)}),e};exports.Ctx=J,exports.babelLoader=I,exports.build=function(r){return new Promise(function(t,n){try{e(r,function(e,r){t({err:e,stats:r})})}catch(e){n(e)}})},exports.createCompiler=function(r){return e(r)},exports.cssLoader=T,exports.getBabelConfig=L,exports.getCssBaseLoader=F,exports.getDevServer=function(e){var t=e.port,n=x(e,R);return y(y({host:"127.0.0.1",open:!1,setupExitSignals:!0,compress:!1,hot:!0,historyApiFallback:!0,static:[{directory:r.resolveCwd("./public")},{directory:r.resolveCwd("./dist")}],headers:{"Access-Control-Allow-Origin":"*"}},n),{},{port:t||"7777"})},exports.getDevtool=function(e,r){return r||("server"===e.action?"eval-cheap-module-source-map":"source-map")},exports.getEntry=function(e,n){if(n)return n;var o=e.workRootDir,i=P.reduce(function(e,r){return j.forEach(function(t){e.push("./"+r+t)}),e},[]),s=r.lookupFile(i,o);return s||(t.cLog.warn("dora-wr","getEntry","需要有一个入口文件 index 或者 src/index"),process.exit()),s},exports.getExternals=function(e){return e||[]},exports.getHtmlWebpackPlugin=B,exports.getMode=function(e,r){return r||("server"===e.action?"development":"production")},exports.getOptimization=function(e){var r=e.minimize;return r?{minimize:r,minimizer:[new s({extractComments:!1})]}:{minimize:!1}},exports.getOutput=function(e,r){var t=e.workRootDir,n=r||{},i=n.path,s=n.filename,a=x(n,N);return y({filename:s||"js/[name].[contenthash].js",path:i&&o.isAbsolute(i)?i:o.join(t,i||"dist"),clean:!0,publicPath:"/"},a)},exports.getReactModulePreset=function(e,r){var t=F(e,r),n=L();return{rules:[{oneOf:[{test:/\.(js|mjs|jsx|ts|tsx)$/,resolve:{fullySpecified:!1},use:[{loader:I,options:n}]},{test:/\.css$/,use:w(t)},{test:/\.less$/,use:[].concat(w(t),[_])},{test:/\.s[ac]ss$/,use:[].concat(w(t),[E])},{test:/\.(jpe?g|png|gif|svg)$/i,type:"asset",generator:{filename:"img/[name]_[hash:8][ext]"},parser:{dataUrlCondition:{maxSize:8192}}},{test:/\.(otf|eot|woff2?|ttf|svg)$/i,type:"asset",generator:{filename:"icon/[name]_[hash:8][ext]"},parser:{dataUrlCondition:{maxSize:2048}}}]}]}},exports.getReactPluginsPreset=function(e,n){var o=e.action,s="server"===o,a=n.WebpackBundleAnalyzerOptions,l=n.HtmlWebpackPluginOptions,p=n.minimize,f=r.lookupFile(O);f||t.cLog.warn("init","not_found","未找到 html 入口文件,将使用预设配置");var d=[M(e)];return s||d.push(new H({activeModules:!1,entries:!0,modules:!0,modulesCount:5e3,profile:!1,dependencies:!0,dependenciesCount:1e4,percentBy:"entries"})),"lib"!==o&&d.push(B(y({minimize:p,template:f||void 0},l))),s||d.push(new c,new i({filename:"css/main.[contenthash].css"})),a&&d.push(new u.BundleAnalyzerPlugin(a)),d.filter(Boolean)},exports.getResolve=function(e){return y({extensions:[".ts",".tsx",".js",".jsx"]},e)},exports.getResolveLoader=function(){return{modules:[U],extensions:[".js",".json"],mainFields:["loader","main"]}},exports.getTsconfigPlugin=M,exports.lessLoader=_,exports.mergeServerConfig=K,exports.postcssLoader=A,exports.postcssPresetEnv=z,exports.sassLoader=E,exports.service=function(e,r){return new Promise(function(t,n){var o,i,s,a,u;return o=K(Q,e),i=o.open,s=o.port,a=o.host,u=new l(K(y(y({},o),{},{open:!1})),r),Promise.resolve(u.start()).then(function(e){try{return i&&p("http://".concat(a,":").concat(s)),t()}catch(e){return n(e)}},n)})},exports.styleLoader=D;
|
package/lib/esm/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"webpack";import{resolveCwd as t,lookupFile as r,getDirname as n,getPackageRoot as o,getNodeModulesDir as i,requireResolve as a,getCwd as s}from"@dorabag/file-pro";import{cLog as c,insertTsconfig as u}from"@doracli/helper";import{reactBabelPreset as l}from"@doracli/preset-babel";import f,{join as p,isAbsolute as m}from"path";import h from"mini-css-extract-plugin";import d from"terser-webpack-plugin";import v from"html-webpack-plugin";import b from"webpack-bundle-analyzer";import y from"webpackbar";import g from"webpack-dev-server";import w from"@dorabag/open-browser";import{isArray as j}from"@cclr/lang";var O=function(t){return new Promise(function(r,n){try{e(t,function(e,t){r({err:e,stats:t})})}catch(e){n(e)}})};function x(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function k(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function P(e,t,r){return t&&function(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,z(n.key),n)}}(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e}function C(e,t,r){return(t=z(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function S(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function A(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?S(Object(r),!0).forEach(function(t){C(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):S(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function D(e,t){if(null==e)return{};var r,n,o=function(e,t){if(null==e)return{};var r={};for(var n in e)if({}.hasOwnProperty.call(e,n)){if(-1!==t.indexOf(n))continue;r[n]=e[n]}return r}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)r=i[n],-1===t.indexOf(r)&&{}.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}function E(e){return function(e){if(Array.isArray(e))return x(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(e){if("string"==typeof e)return x(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?x(e,t):void 0}}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function z(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t);if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}var R=["port"],$=function(e){var r=e.port,n=D(e,R);return A(A({host:"127.0.0.1",open:!1,setupExitSignals:!0,compress:!1,hot:!0,historyApiFallback:!0,static:[{directory:t("./public")},{directory:t("./dist")}],headers:{"Access-Control-Allow-Origin":"*"}},n),{},{port:r||"7777"})},T=function(e,t){return t||("server"===e.action?"eval-cheap-module-source-map":"source-map")},W=["index","src/index"],B=[".ts",".js",".tsx",".jsx"],F=["index.html","public/index.html"],I=function(e,t){if(t)return t;var n=e.workRootDir,o=W.reduce(function(e,t){return B.forEach(function(r){e.push("./"+t+r)}),e},[]),i=r(o,n);return i||(c.warn("dora-wr","getEntry","需要有一个入口文件 index 或者 src/index"),process.exit()),i},_=function(e){return e||[]},U=function(e,t){return t||("server"===e.action?"development":"production")},M=n(import.meta),H=o(M),J=p(H,"node_modules"),N=p(H,"lib/preset/html/dev-preset.html"),Q=function(){return A({babelrc:!1,configFile:!1,compact:!1,cwd:i(M)},l())},q=a(import.meta.url,"css-loader"),G=a(import.meta.url,"postcss-loader"),K=a(import.meta.url,"style-loader"),L=a(import.meta.url,"babel-loader"),V=a(import.meta.url,"less-loader"),X=a(import.meta.url,"sass-loader"),Y=a(import.meta.url,"postcss-preset-env"),Z=function(e,t){var r=e.action,n=(t||{}).postcssPluginExtra,o=[q,{loader:G,options:{postcssOptions:{plugins:[[Y]].concat(E(n||[]))}}}];return"server"===r?o.unshift({loader:K}):o.unshift({loader:h.loader}),o},ee=function(e,t){var r=Z(e,t),n=Q();return{rules:[{oneOf:[{test:/\.(js|mjs|jsx|ts|tsx)$/,resolve:{fullySpecified:!1},use:[{loader:L,options:n}]},{test:/\.css$/,use:E(r)},{test:/\.less$/,use:[].concat(E(r),[V])},{test:/\.s[ac]ss$/,use:[].concat(E(r),[X])},{test:/\.(jpe?g|png|gif|svg)$/i,type:"asset",generator:{filename:"img/[name]_[hash:8][ext]"},parser:{dataUrlCondition:{maxSize:8192}}},{test:/\.(otf|eot|woff2?|ttf|svg)$/i,type:"asset",generator:{filename:"icon/[name]_[hash:8][ext]"},parser:{dataUrlCondition:{maxSize:2048}}}]}]}},te=function(e){var t=e.minimize;return t?{minimize:t,minimizer:[new d({extractComments:!1})]}:{minimize:!1}},re=["path","filename"],ne=function(e,t){var r=e.workRootDir,n=t||{},o=n.path,i=n.filename,a=D(n,re);return A({filename:i||"js/[name].[contenthash].js",path:o&&m(o)?o:p(r,o||"dist"),clean:!0,publicPath:"/"},a)},oe=["minimize","template"],ie=function(e){var t=e.minimize,r=e.template,n=D(e,oe);return new v(A({title:"webpack5-react-ts",filename:"index.html",template:r||N,inject:!0,hash:!0,cache:!1,minify:!!t&&{removeAttributeQuotes:!0,collapseWhitespace:!0,removeComments:!0,minifyJS:!0,minifyCSS:!0}},n))};var ae=function(){return P(function e(t){k(this,e),C(this,"workRootDir",void 0),this.workRootDir=t},[{key:"apply",value:function(e){var t=this;e.hooks.beforeRun.tapPromise("TsconfigPlugin",function(e){return new Promise(function(r,n){var o,i=function(){try{return r()}catch(e){return n(e)}},a=function(e){try{return c.error("init","error","自动注入 tsconfig.json 失败"),i()}catch(e){return n(e)}};try{return function(e){var t=[],r=function(e){if(e)if("string"==typeof e)t.push(e);else if(Array.isArray(e))e.forEach(r);else if("object"==typeof e){var n=e;n.import?r(n.import):Object.values(n).forEach(r)}};return r(e),t}(null!==(o=e.options&&e.options.entry)&&void 0!==o?o:{}).some(function(e){return/\.(ts|tsx)$/.test(f.extname(String(e)))})?Promise.resolve(u(t.workRootDir)).then(function(e){try{return i()}catch(e){return a()}},a):r()}catch(e){a()}})})}}])}(),se=function(e){return new ae(e.workRootDir)},ce=e.ProgressPlugin,ue=function(e,t){var n=e.action,o="server"===n,i=t.WebpackBundleAnalyzerOptions,a=t.HtmlWebpackPluginOptions,s=t.minimize,u=r(F);u||c.warn("init","not_found","未找到 html 入口文件,将使用预设配置");var l=[se(e)];return o||l.push(new ce({activeModules:!1,entries:!0,modules:!0,modulesCount:5e3,profile:!1,dependencies:!0,dependenciesCount:1e4,percentBy:"entries"})),"lib"!==n&&l.push(ie(A({minimize:s,template:u||void 0},a))),o||l.push(new y,new h({filename:"css/main.[contenthash].css"})),i&&l.push(new b.BundleAnalyzerPlugin(i)),l.filter(Boolean)},le=function(e){return A({extensions:[".ts",".tsx",".js",".jsx"]},e)},fe=function(){return{modules:[J],extensions:[".js",".json"],mainFields:["loader","main"]}},pe=function(t){return e(t)},me=function(){return P(function e(t){k(this,e),C(this,"configCtx",void 0),C(this,"webpackConfig",{}),C(this,"devServerConfig",{}),C(this,"envParams",{action:"build",workRootDir:s()}),this.configCtx=t},[{key:"updateEnvParams",value:function(e){this.envParams=A(A({},this.envParams),e)}},{key:"updateWebpackConfig",value:function(e){this.webpackConfig=A(A({},this.webpackConfig),e)}},{key:"updateDevServerConfig",value:function(e){this.devServerConfig=A(A({},this.devServerConfig),e)}},{key:"getDoraConfig",value:function(){return this.configCtx.getDoraConfig()}},{key:"geTDoraConfigWebpack",value:function(){return this.configCtx.getDoraConfig().webpackConfig||{}}}])}(),he={host:"127.0.0.1",open:!0,setupExitSignals:!0,compress:!1,hot:!0,historyApiFallback:!0,static:[{directory:t("./public")},{directory:t("./dist")}],headers:{"Access-Control-Allow-Origin":"*"},port:"8082"},de=["static","headers"],ve=function(){for(var e={static:[],headers:{}},t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];return r.forEach(function(t){var r,n=t.static,o=t.headers,i=D(t,de);j(e.static)&&j(n)&&(r=e.static).push.apply(r,E(n));o&&(e.headers=A(A({},e.headers),o)),Object.assign(e,i)}),e},be=function(e,t){return new Promise(function(r,n){var o,i,a,s,c;return o=ve(he,e),i=o.open,a=o.port,s=o.host,c=new g(ve(A(A({},o),{},{open:!1})),t),Promise.resolve(c.start()).then(function(e){try{return i&&w("http://".concat(s,":").concat(a)),r()}catch(e){return n(e)}},n)})};export{me as Ctx,L as babelLoader,O as build,pe as createCompiler,q as cssLoader,Q as getBabelConfig,Z as getCssBaseLoader,$ as getDevServer,T as getDevtool,I as getEntry,_ as getExternals,ie as getHtmlWebpackPlugin,U as getMode,te as getOptimization,ne as getOutput,ee as getReactModulePreset,ue as getReactPluginsPreset,le as getResolve,fe as getResolveLoader,se as getTsconfigPlugin,V as lessLoader,ve as mergeServerConfig,G as postcssLoader,Y as postcssPresetEnv,X as sassLoader,be as service,K as styleLoader};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="zh-CN">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
+
<title>cclr</title>
|
|
8
|
+
<!-- 引入样式 -->
|
|
9
|
+
<% for (var i in htmlWebpackPlugin.options.headBeforeStyle) { %>
|
|
10
|
+
<link
|
|
11
|
+
href="<%= htmlWebpackPlugin.options.headBeforeStyle[i] %>"
|
|
12
|
+
rel="stylesheet"
|
|
13
|
+
/>
|
|
14
|
+
<% } %>
|
|
15
|
+
|
|
16
|
+
<!-- 引入js -->
|
|
17
|
+
<% for (var i in htmlWebpackPlugin.options.headAfterScript) { %>
|
|
18
|
+
<script src="<%= htmlWebpackPlugin.options.headAfterScript[i] %>"></script>
|
|
19
|
+
<% } %>
|
|
20
|
+
</head>
|
|
21
|
+
<body>
|
|
22
|
+
<div id="main">welcome use cclr !!</div>
|
|
23
|
+
</body>
|
|
24
|
+
</html>
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import * as webpack from 'webpack';
|
|
2
|
+
import webpack__default, { Configuration, Stats, Compiler } from 'webpack';
|
|
3
|
+
import { Configuration as Configuration$1 } from 'webpack-dev-server';
|
|
4
|
+
import * as _doracli_type from '@doracli/type';
|
|
5
|
+
import { TModule as TModule$1 } from '@doracli/type';
|
|
6
|
+
import { TAny } from '@cclr/lang';
|
|
7
|
+
import HtmlWebpackPlugin from 'html-webpack-plugin';
|
|
8
|
+
import { ConfigCtx } from '@doracli/helper';
|
|
9
|
+
|
|
10
|
+
declare const build: (options: Configuration) => Promise<{
|
|
11
|
+
err?: Error | null;
|
|
12
|
+
stats?: Stats;
|
|
13
|
+
}>;
|
|
14
|
+
|
|
15
|
+
declare const getDevServer: (serviceConfig: Configuration$1) => Configuration$1;
|
|
16
|
+
|
|
17
|
+
type TAction = 'build' | 'server' | 'lib';
|
|
18
|
+
type TEnvParams = {
|
|
19
|
+
action: TAction;
|
|
20
|
+
workRootDir: string;
|
|
21
|
+
format?: TModule$1;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
type TMode = Configuration['mode'];
|
|
25
|
+
type TEntry = Configuration['entry'];
|
|
26
|
+
type TOutput = Configuration['output'];
|
|
27
|
+
type TDevtool = Configuration['devtool'];
|
|
28
|
+
type TExternals = Configuration['externals'];
|
|
29
|
+
type TExperiments = Configuration['experiments'];
|
|
30
|
+
type TResolve = Configuration['resolve'];
|
|
31
|
+
type TResolveLoader = Configuration['resolveLoader'];
|
|
32
|
+
type TModule = Configuration['module'];
|
|
33
|
+
type TPlugins = Configuration['plugins'];
|
|
34
|
+
type TOptimization = Configuration['optimization'];
|
|
35
|
+
|
|
36
|
+
declare const getDevtool: (envParams: TEnvParams, devtoolConfig?: TDevtool) => TDevtool;
|
|
37
|
+
|
|
38
|
+
declare const getEntry: (params: TEnvParams, input?: string) => TEntry;
|
|
39
|
+
|
|
40
|
+
declare const getExternals: (externals: TExternals) => TExternals;
|
|
41
|
+
|
|
42
|
+
declare const getMode: (envParams: TEnvParams, modeConfig?: TMode) => TMode;
|
|
43
|
+
|
|
44
|
+
declare const getBabelConfig: () => TAny;
|
|
45
|
+
|
|
46
|
+
declare const getCssBaseLoader: (envParams: TEnvParams, options?: {
|
|
47
|
+
postcssPluginExtra?: TAny[];
|
|
48
|
+
}) => any[];
|
|
49
|
+
|
|
50
|
+
declare const cssLoader: string;
|
|
51
|
+
declare const postcssLoader: string;
|
|
52
|
+
declare const styleLoader: string;
|
|
53
|
+
declare const babelLoader: string;
|
|
54
|
+
declare const lessLoader: string;
|
|
55
|
+
declare const sassLoader: string;
|
|
56
|
+
declare const postcssPresetEnv: string;
|
|
57
|
+
|
|
58
|
+
declare const getReactModulePreset: (envParams: TEnvParams, options?: {
|
|
59
|
+
postcssPluginExtra?: TAny[];
|
|
60
|
+
}) => webpack.ModuleOptions;
|
|
61
|
+
|
|
62
|
+
declare const getOptimization: (params: {
|
|
63
|
+
minimize: boolean;
|
|
64
|
+
}) => TOptimization;
|
|
65
|
+
|
|
66
|
+
declare const getOutput: (envParams: TEnvParams, output?: TOutput) => TOutput;
|
|
67
|
+
|
|
68
|
+
declare const getHtmlWebpackPlugin: (params: HtmlWebpackPlugin.Options) => HtmlWebpackPlugin;
|
|
69
|
+
|
|
70
|
+
declare class TsconfigPlugin {
|
|
71
|
+
private workRootDir;
|
|
72
|
+
constructor(workRootDir: string);
|
|
73
|
+
apply(compiler: Compiler): void;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
declare const getTsconfigPlugin: (envParams: TEnvParams) => TsconfigPlugin;
|
|
77
|
+
|
|
78
|
+
declare const getReactPluginsPreset: (envParams: TEnvParams, options: {
|
|
79
|
+
minimize?: boolean;
|
|
80
|
+
WebpackBundleAnalyzerOptions?: TAny;
|
|
81
|
+
HtmlWebpackPluginOptions?: HtmlWebpackPlugin.Options;
|
|
82
|
+
}) => TPlugins;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* 获取webpack的resolve配置
|
|
86
|
+
* @param userResolve
|
|
87
|
+
* @returns
|
|
88
|
+
*/
|
|
89
|
+
declare const getResolve: (resolveConfig: TResolve) => TResolve;
|
|
90
|
+
|
|
91
|
+
declare const getResolveLoader: () => TResolveLoader;
|
|
92
|
+
|
|
93
|
+
declare const createCompiler: (config: Configuration) => webpack__default.Compiler | null;
|
|
94
|
+
|
|
95
|
+
declare class Ctx {
|
|
96
|
+
configCtx: ConfigCtx;
|
|
97
|
+
webpackConfig: Configuration;
|
|
98
|
+
devServerConfig: Configuration$1;
|
|
99
|
+
envParams: TEnvParams;
|
|
100
|
+
constructor(configCtx: ConfigCtx);
|
|
101
|
+
updateEnvParams(argv: Partial<TEnvParams>): void;
|
|
102
|
+
updateWebpackConfig(config: Configuration): void;
|
|
103
|
+
updateDevServerConfig(config: Configuration$1): void;
|
|
104
|
+
getDoraConfig(): _doracli_type.TDoraConfig;
|
|
105
|
+
geTDoraConfigWebpack(): _doracli_type.TDoraConfigWebpack;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* 启动服务
|
|
110
|
+
* @param options
|
|
111
|
+
* @param compiler
|
|
112
|
+
*/
|
|
113
|
+
declare const service: (options: Configuration$1, compiler: Compiler) => Promise<void>;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* 合并多个 devServer 配置
|
|
117
|
+
* @param configs
|
|
118
|
+
* @returns
|
|
119
|
+
*/
|
|
120
|
+
declare const mergeServerConfig: (...configs: Configuration$1[]) => Configuration$1;
|
|
121
|
+
|
|
122
|
+
export { Ctx, babelLoader, build, createCompiler, cssLoader, getBabelConfig, getCssBaseLoader, getDevServer, getDevtool, getEntry, getExternals, getHtmlWebpackPlugin, getMode, getOptimization, getOutput, getReactModulePreset, getReactPluginsPreset, getResolve, getResolveLoader, getTsconfigPlugin, lessLoader, mergeServerConfig, postcssLoader, postcssPresetEnv, sassLoader, service, styleLoader };
|
|
123
|
+
export type { TAction, TDevtool, TEntry, TEnvParams, TExperiments, TExternals, TMode, TModule, TOptimization, TOutput, TPlugins, TResolve, TResolveLoader };
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@doracli/webpack",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "use webpack",
|
|
5
|
+
"author": "cclr <18843152354@163.com>",
|
|
6
|
+
"homepage": "",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"exports": {
|
|
10
|
+
"import": "./lib/esm/index.js",
|
|
11
|
+
"require": "./lib/cjs/index.js"
|
|
12
|
+
},
|
|
13
|
+
"types": "lib/type/index.d.ts",
|
|
14
|
+
"directories": {
|
|
15
|
+
"lib": "lib"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"lib",
|
|
19
|
+
"README.md"
|
|
20
|
+
],
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public",
|
|
23
|
+
"registry": "https://registry.npmjs.org/"
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"test": "vitest",
|
|
27
|
+
"g:test": "vitest run",
|
|
28
|
+
"build": "ccf build"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@dorabag/open-browser": "^1.0.10"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@cclr/lang": "^0.1.28",
|
|
35
|
+
"@cclr/utils": "^0.1.28",
|
|
36
|
+
"@dorabag/config-loader": "^1.0.10",
|
|
37
|
+
"@dorabag/file-pro": "^1.0.10",
|
|
38
|
+
"@dorabag/open-browser": "^1.0.7",
|
|
39
|
+
"@dorabag/srv-tool": "^1.0.10",
|
|
40
|
+
"@doracli/helper": "^0.0.1",
|
|
41
|
+
"@doracli/preset-babel": "^0.0.1",
|
|
42
|
+
"@doracli/type": "^0.0.1",
|
|
43
|
+
"babel-loader": "^10.0.0",
|
|
44
|
+
"css-loader": "^7.1.2",
|
|
45
|
+
"html-webpack-plugin": "^5.6.4",
|
|
46
|
+
"less": "^4.4.2",
|
|
47
|
+
"less-loader": "^12.3.0",
|
|
48
|
+
"mini-css-extract-plugin": "^2.9.4",
|
|
49
|
+
"picocolors": "^1.1.1",
|
|
50
|
+
"postcss": "^8.5.6",
|
|
51
|
+
"postcss-loader": "^8.2.0",
|
|
52
|
+
"postcss-preset-env": "^10.4.0",
|
|
53
|
+
"sass": "^1.93.2",
|
|
54
|
+
"sass-loader": "^16.0.5",
|
|
55
|
+
"style-loader": "^4.0.0",
|
|
56
|
+
"terser-webpack-plugin": "^5.3.14",
|
|
57
|
+
"webpack": "^5.102.1",
|
|
58
|
+
"webpack-bundle-analyzer": "^4.10.2",
|
|
59
|
+
"webpack-dev-server": "^5.2.2",
|
|
60
|
+
"webpackbar": "^7.0.0"
|
|
61
|
+
},
|
|
62
|
+
"gitHead": "40ab496f25042487a671979074515f3345c96453"
|
|
63
|
+
}
|