File tree Expand file tree Collapse file tree 5 files changed +46
-15
lines changed
Expand file tree Collapse file tree 5 files changed +46
-15
lines changed Original file line number Diff line number Diff line change @@ -16,24 +16,24 @@ yarn add webcrack
1616pnpm add webcrack
1717```
1818
19+ ## Basic Usage
20+
1921:::
2022
2123::: info
22- This is a pure ESM package, so you need to use ` import ` instead of ` require ` .
23- For more info, check out [ this gist] ( https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c ) .
24- Or use the following wrapper in commonjs projects:
24+ All examples are shown with ESM syntax.
25+ For CommonJS, use the following instead:
2526
2627``` js
27- async function webcrack (... args ) {
28- const { webcrack } = await import (' webcrack' );
29- return webcrack (... args);
30- }
28+ const { webcrack } = require (' webcrack' );
29+
30+ webcrack (' const a = 1+1;' ).then ((result ) => {
31+ console .log (result .code ); // 'const a = 2;'
32+ });
3133```
3234
3335:::
3436
35- ## Basic Usage
36-
3737``` js
3838import { webcrack } from ' webcrack' ;
3939
Original file line number Diff line number Diff line change @@ -9,15 +9,15 @@ const watch = args.length > 0 && /^(?:--watch|-w)$/i.test(args[0]);
99 */
1010const babelImportPlugin = {
1111 name : 'babel-import' ,
12- setup : build => {
13- build . onResolve ( { filter : / ^ @ b a b e l \/ ( t r a v e r s e | g e n e r a t o r ) $ / } , args => {
12+ setup : ( build ) => {
13+ build . onResolve ( { filter : / ^ @ b a b e l \/ ( t r a v e r s e | g e n e r a t o r ) $ / } , ( args ) => {
1414 return {
1515 path : args . path ,
1616 namespace : 'babel-import' ,
1717 } ;
1818 } ) ;
1919
20- build . onLoad ( { filter : / .* / , namespace : 'babel-import' } , args => {
20+ build . onLoad ( { filter : / .* / , namespace : 'babel-import' } , ( args ) => {
2121 return {
2222 resolveDir : 'node_modules' ,
2323 contents : `import module from '${ args . path } /lib/index.js';
@@ -35,6 +35,17 @@ const configs = [
3535 {
3636 entryPoints : [ 'src/index.ts' ] ,
3737 } ,
38+ {
39+ entryPoints : [
40+ {
41+ in : 'src/cjs-wrapper.ts' ,
42+ out : 'index' ,
43+ } ,
44+ ] ,
45+ outExtension : { '.js' : '.cjs' } ,
46+ format : 'cjs' ,
47+ bundle : false ,
48+ } ,
3849 {
3950 entryPoints : [ 'src/cli.ts' ] ,
4051 bundle : false ,
Original file line number Diff line number Diff line change 55 "author" : " j4k0xb" ,
66 "license" : " MIT" ,
77 "type" : " module" ,
8- "main" : " dist/index.js" ,
9- "types" : " dist/index.d.ts" ,
108 "bin" : " src/cli-wrapper.js" ,
9+ "main" : " dist/index.cjs" ,
10+ "types" : " dist/index.d.ts" ,
11+ "exports" : {
12+ "." : {
13+ "import" : {
14+ "types" : " ./dist/index.d.ts" ,
15+ "default" : " ./dist/index.js"
16+ },
17+ "require" : {
18+ "types" : " ./dist/index.d.ts" ,
19+ "default" : " ./dist/index.cjs"
20+ }
21+ }
22+ },
1123 "files" : [
1224 " dist" ,
1325 " src/cli-wrapper.js"
Original file line number Diff line number Diff line change 1+ import type { webcrack as wc } from './index.js' ;
2+
3+ export const webcrack : typeof wc = async ( ...args ) => {
4+ const { webcrack } = await import ( './index.js' ) ;
5+ return webcrack ( ...args ) ;
6+ } ;
Original file line number Diff line number Diff line change 99 " src"
1010 ],
1111 "exclude" : [
12- " **/test"
12+ " **/test" ,
13+ " src/cli.ts" ,
14+ " src/cjs-wrapper.ts"
1315 ]
1416}
You can’t perform that action at this time.
0 commit comments