@doracli/esbuild 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 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
@@ -0,0 +1,6 @@
1
+ # `cli`
2
+
3
+ > @doracli/cli
4
+ > 构建功能集合
5
+
6
+ ## Usage
@@ -0,0 +1 @@
1
+ "use strict";var e=require("esbuild"),t=require("@doracli/helper"),r=require("@craftamap/esbuild-plugin-html"),n=require("esbuild-plugin-less"),i=require("autoprefixer"),o=require("esbuild-plugin-postcss"),s=require("esbuild-plugin-sass"),u=require("@dorabag/file-pro"),c=require("@cclr/lang");function a(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,d(n.key),n)}}(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e}function l(e,t,r){return(t=d(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function f(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 p(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?f(Object(r),!0).forEach(function(t){l(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):f(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function d(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 g=function(){return a(function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),l(this,"configCtx",void 0),l(this,"esbuildConfig",{}),l(this,"envParams",{action:"build",workRootDir:u.getCwd()}),this.configCtx=t},[{key:"updateEnvParams",value:function(e){this.envParams=p(p({},this.envParams),e)}},{key:"updateEsbuildConfig",value:function(e){this.esbuildConfig=p(p({},this.esbuildConfig),e)}},{key:"getDoraConfig",value:function(){return this.configCtx.getDoraConfig()}},{key:"geTDoraConfigEsbuild",value:function(){return this.configCtx.getDoraConfig().esbuildConfig||{}}}])}();exports.Ctx=g,exports.builder=function(t){return new Promise(function(r,n){return r(e.build(t))})},exports.createContext=function(){return e.context({})},exports.extractEntry=function(e){var t=[];return e?(c.isString(e)?t.push(e):c.isArray(e)?e.forEach(function(e){c.isString(e)&&t.push(e),c.isObject(e)&&e.in&&t.push(e.in)}):c.isObject(e)&&Object.values(e).forEach(function(e){return t.push(e)}),t):[]},exports.getDefine=function(e){var t=e.NODE_ENV;return{"process.env.NODE_ENV":'"'.concat(t||"production",'"')}},exports.getEntryPoints=function(e,r){if(r)return r;var n=t.findInput(e.workRootDir);return n||(t.cLog.error("init","error","需要有一个入口文件 index 或者 src/index"),process.exit(1)),[n]},exports.getEsbuildPluginHtml=function(e){var t=e.cdnConfig,n=e.entry;return r.htmlPlugin({files:[p({filename:"index.html",entryPoints:[n],htmlTemplate:'\n<!DOCTYPE html>\n<html lang="zh-CN">\n <head>\n <meta charset="UTF-8" />\n <meta http-equiv="X-UA-Compatible" content="IE=edge" />\n <meta name="viewport" content="width=device-width, initial-scale=1.0" />\n <title>cclr</title>\n \x3c!-- 引入样式 --\x3e\n <% for (var i in define.headBeforeStyle) { %>\n <link\n href="<%= define.headBeforeStyle[i] %>"\n rel="stylesheet"\n />\n <% } %>\n\n \x3c!-- 引入js --\x3e\n <% for (var i in define.headAfterScript) { %>\n <script src="<%= define.headAfterScript[i] %>"><\/script>\n <% } %>\n </head>\n <body>\n <div id="main">welcome use cclr !!</div>\n </body>\n</html>\n',define:p({},t)},e)]})},exports.getLessPlugin=function(){return n.lessLoader()},exports.getNodeBuildConfigPreset=function(){return{entryPoints:["src/index.ts"],outdir:"dist",bundle:!0,minify:!0,sourcemap:!0,target:["es2020"],platform:"browser",external:["react","react-dom"],define:{"process.env.NODE_ENV":'"production"'},loader:{".png":"file",".svg":"file"},plugins:[]}},exports.getNodeLoaderPreset=function(){return{".js":"jsx",".ts":"ts"}},exports.getPostCssPlugin=function(){return o.default({postcssPlugin:[i]})},exports.getReactBuildConfigPreset=function(){return{entryPoints:["src/index.ts"],outdir:"dist",bundle:!0,minify:!0,sourcemap:!0,target:["es2020"],platform:"browser",external:["react","react-dom"],define:{"process.env.NODE_ENV":'"production"'},loader:{".png":"file",".svg":"file"},plugins:[]}},exports.getReactLoaderPreset=function(){return{".js":"jsx",".ts":"ts",".tsx":"tsx",".css":"css",".png":"file",".svg":"file",".json":"json"}},exports.getSassPlugin=function(){return s()},exports.inputFileDirList=["src/index","index"],exports.inputFileTypeList=[".ts",".js",".tsx",".jsx"];
@@ -0,0 +1 @@
1
+ import{build as e,context as t}from"esbuild";import{findInput as n,cLog as r}from"@doracli/helper";import{htmlPlugin as i}from"@craftamap/esbuild-plugin-html";import{lessLoader as o}from"esbuild-plugin-less";import s from"autoprefixer";import u from"esbuild-plugin-postcss";import c from"esbuild-plugin-sass";import{getCwd as f}from"@dorabag/file-pro";import{isString as a,isArray as l,isObject as p}from"@cclr/lang";var d=function(t){return new Promise(function(n,r){return n(e(t))})},m=function(e){var t=e.NODE_ENV;return{"process.env.NODE_ENV":'"'.concat(t||"production",'"')}},b=["src/index","index"],g=[".ts",".js",".tsx",".jsx"],v=function(e,t){if(t)return t;var i=n(e.workRootDir);return i||(r.error("init","error","需要有一个入口文件 index 或者 src/index"),process.exit(1)),[i]},h=function(){return{".js":"jsx",".ts":"ts",".tsx":"tsx",".css":"css",".png":"file",".svg":"file",".json":"json"}},y=function(){return{".js":"jsx",".ts":"ts"}};function j(e,t,n){return t&&function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,w(r.key),r)}}(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e}function x(e,t,n){return(t=w(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function O(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function P(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?O(Object(n),!0).forEach(function(t){x(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):O(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function w(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t);if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}var E=function(e){var t=e.cdnConfig,n=e.entry;return i({files:[P({filename:"index.html",entryPoints:[n],htmlTemplate:'\n<!DOCTYPE html>\n<html lang="zh-CN">\n <head>\n <meta charset="UTF-8" />\n <meta http-equiv="X-UA-Compatible" content="IE=edge" />\n <meta name="viewport" content="width=device-width, initial-scale=1.0" />\n <title>cclr</title>\n \x3c!-- 引入样式 --\x3e\n <% for (var i in define.headBeforeStyle) { %>\n <link\n href="<%= define.headBeforeStyle[i] %>"\n rel="stylesheet"\n />\n <% } %>\n\n \x3c!-- 引入js --\x3e\n <% for (var i in define.headAfterScript) { %>\n <script src="<%= define.headAfterScript[i] %>"><\/script>\n <% } %>\n </head>\n <body>\n <div id="main">welcome use cclr !!</div>\n </body>\n</html>\n',define:P({},t)},e)]})},C=function(){return o()},D=function(){return u.default({postcssPlugin:[s]})},N=function(){return c()},k=function(){return{entryPoints:["src/index.ts"],outdir:"dist",bundle:!0,minify:!0,sourcemap:!0,target:["es2020"],platform:"browser",external:["react","react-dom"],define:{"process.env.NODE_ENV":'"production"'},loader:{".png":"file",".svg":"file"},plugins:[]}},S=function(){return{entryPoints:["src/index.ts"],outdir:"dist",bundle:!0,minify:!0,sourcemap:!0,target:["es2020"],platform:"browser",external:["react","react-dom"],define:{"process.env.NODE_ENV":'"production"'},loader:{".png":"file",".svg":"file"},plugins:[]}},T=function(){return t({})},V=function(){return j(function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),x(this,"configCtx",void 0),x(this,"esbuildConfig",{}),x(this,"envParams",{action:"build",workRootDir:f()}),this.configCtx=t},[{key:"updateEnvParams",value:function(e){this.envParams=P(P({},this.envParams),e)}},{key:"updateEsbuildConfig",value:function(e){this.esbuildConfig=P(P({},this.esbuildConfig),e)}},{key:"getDoraConfig",value:function(){return this.configCtx.getDoraConfig()}},{key:"geTDoraConfigEsbuild",value:function(){return this.configCtx.getDoraConfig().esbuildConfig||{}}}])}(),_=function(e){var t=[];return e?(a(e)?t.push(e):l(e)?e.forEach(function(e){a(e)&&t.push(e),p(e)&&e.in&&t.push(e.in)}):p(e)&&Object.values(e).forEach(function(e){return t.push(e)}),t):[]};export{V as Ctx,d as builder,T as createContext,_ as extractEntry,m as getDefine,v as getEntryPoints,E as getEsbuildPluginHtml,C as getLessPlugin,k as getNodeBuildConfigPreset,y as getNodeLoaderPreset,D as getPostCssPlugin,S as getReactBuildConfigPreset,h as getReactLoaderPreset,N as getSassPlugin,b as inputFileDirList,g as inputFileTypeList};
@@ -0,0 +1,113 @@
1
+ import * as esbuild from 'esbuild';
2
+ import { BuildOptions } from 'esbuild';
3
+ import { TCdn, TDoraConfig } from '@doracli/type';
4
+ import { ConfigCtx } from '@doracli/helper';
5
+
6
+ declare const builder: (config: BuildOptions) => Promise<esbuild.BuildResult<BuildOptions>>;
7
+
8
+ declare const getDefine: (params: {
9
+ NODE_ENV: string;
10
+ }) => {
11
+ 'process.env.NODE_ENV': string;
12
+ };
13
+
14
+ type TEnvParams = {
15
+ action: 'build' | 'dev' | 'serve';
16
+ workRootDir: string;
17
+ };
18
+
19
+ type TEntryPoints = BuildOptions['entryPoints'];
20
+ type TOutfile = BuildOptions['outfile'];
21
+ type TOutdir = BuildOptions['outdir'];
22
+ type TBundle = BuildOptions['bundle'];
23
+ type TMinify = BuildOptions['minify'];
24
+ type TSourcemap = BuildOptions['sourcemap'];
25
+ type TTarget = BuildOptions['target'];
26
+ type TDefine = BuildOptions['define'];
27
+ type TPlugins = BuildOptions['plugins'];
28
+ type TLoader = BuildOptions['loader'];
29
+
30
+ declare const inputFileDirList: string[];
31
+ declare const inputFileTypeList: string[];
32
+ declare const getEntryPoints: (envParams: TEnvParams, input?: TEntryPoints) => TEntryPoints;
33
+
34
+ declare const getReactLoaderPreset: () => {
35
+ '.js': "jsx";
36
+ '.ts': "ts";
37
+ '.tsx': "tsx";
38
+ '.css': "css";
39
+ '.png': "file";
40
+ '.svg': "file";
41
+ '.json': "json";
42
+ };
43
+ declare const getNodeLoaderPreset: () => {
44
+ '.js': "jsx";
45
+ '.ts': "ts";
46
+ };
47
+
48
+ declare const getEsbuildPluginHtml: (params: {
49
+ cdnConfig?: TCdn;
50
+ entry: string;
51
+ }) => esbuild.Plugin;
52
+
53
+ declare const getLessPlugin: () => esbuild.Plugin;
54
+
55
+ declare const getPostCssPlugin: () => any;
56
+
57
+ declare const getSassPlugin: () => esbuild.Plugin;
58
+
59
+ declare const getNodeBuildConfigPreset: () => {
60
+ entryPoints: string[];
61
+ outdir: string;
62
+ bundle: boolean;
63
+ minify: boolean;
64
+ sourcemap: boolean;
65
+ target: string[];
66
+ platform: string;
67
+ external: string[];
68
+ define: {
69
+ 'process.env.NODE_ENV': string;
70
+ };
71
+ loader: {
72
+ '.png': string;
73
+ '.svg': string;
74
+ };
75
+ plugins: never[];
76
+ };
77
+
78
+ declare const getReactBuildConfigPreset: () => {
79
+ entryPoints: string[];
80
+ outdir: string;
81
+ bundle: boolean;
82
+ minify: boolean;
83
+ sourcemap: boolean;
84
+ target: string[];
85
+ platform: string;
86
+ external: string[];
87
+ define: {
88
+ 'process.env.NODE_ENV': string;
89
+ };
90
+ loader: {
91
+ '.png': string;
92
+ '.svg': string;
93
+ };
94
+ plugins: never[];
95
+ };
96
+
97
+ declare const createContext: () => Promise<esbuild.BuildContext<{}>>;
98
+
99
+ declare class Ctx {
100
+ configCtx: ConfigCtx;
101
+ esbuildConfig: BuildOptions;
102
+ envParams: TEnvParams;
103
+ constructor(configCtx: ConfigCtx);
104
+ updateEnvParams(argv: Partial<TEnvParams>): void;
105
+ updateEsbuildConfig(config: BuildOptions): void;
106
+ getDoraConfig(): TDoraConfig;
107
+ geTDoraConfigEsbuild(): {};
108
+ }
109
+
110
+ declare const extractEntry: (entryPoints: TEntryPoints) => string[];
111
+
112
+ export { Ctx, builder, createContext, extractEntry, getDefine, getEntryPoints, getEsbuildPluginHtml, getLessPlugin, getNodeBuildConfigPreset, getNodeLoaderPreset, getPostCssPlugin, getReactBuildConfigPreset, getReactLoaderPreset, getSassPlugin, inputFileDirList, inputFileTypeList };
113
+ export type { TBundle, TDefine, TEntryPoints, TEnvParams, TLoader, TMinify, TOutdir, TOutfile, TPlugins, TSourcemap, TTarget };
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@doracli/esbuild",
3
+ "version": "0.0.1",
4
+ "description": "package by esbuild",
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
+ "@cclr/lang": "^0.1.28",
32
+ "@cclr/utils": "^0.1.28",
33
+ "@craftamap/esbuild-plugin-html": "^0.9.0",
34
+ "@dorabag/file-pro": "^1.0.10",
35
+ "@doracli/commander": "^0.0.1",
36
+ "@doracli/helper": "^0.0.1",
37
+ "@doracli/type": "^0.0.1",
38
+ "@doracli/webpack": "^0.0.1",
39
+ "autoprefixer": "10.4.21",
40
+ "esbuild": "0.25.10",
41
+ "esbuild-plugin-less": "1.3.27",
42
+ "esbuild-plugin-postcss": "0.3.0",
43
+ "esbuild-plugin-sass": "1.0.1",
44
+ "postcss": "8.5.6"
45
+ },
46
+ "gitHead": "40ab496f25042487a671979074515f3345c96453"
47
+ }