Skip to content

Commit 04140de

Browse files
feat: removed cjs wrapper (#29)
1 parent 012b0f3 commit 04140de

File tree

7 files changed

+54
-50
lines changed

7 files changed

+54
-50
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
"type": "opencollective",
1212
"url": "https://opencollective.com/webpack"
1313
},
14-
"main": "dist/cjs.js",
15-
"types": "types/cjs.d.ts",
14+
"main": "dist/index.js",
15+
"types": "types/index.d.ts",
1616
"engines": {
1717
"node": ">= 12.13.0"
1818
},
1919
"scripts": {
2020
"start": "npm run build -- -w",
21-
"clean": "del-cli dist",
21+
"clean": "del-cli dist types",
2222
"prebuild": "npm run clean",
2323
"build:types": "tsc --declaration --emitDeclarationOnly --outDir types && prettier \"types/**/*.ts\" --write",
2424
"build:code": "cross-env NODE_ENV=production babel src -d dist --copy-files",

src/cjs.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { validate } from "schema-utils";
1+
const { validate } = require("schema-utils");
22

3-
import schema from "./options.json";
4-
import { minify as minifyFn } from "./minify";
3+
const schema = require("./options.json");
4+
const { minify } = require("./minify");
55

66
/** @typedef {import("schema-utils/declarations/validate").Schema} Schema */
77
/** @typedef {import("webpack").Compiler} Compiler */
@@ -156,7 +156,7 @@ class JsonMinimizerPlugin {
156156
};
157157

158158
try {
159-
output = await minifyFn(options);
159+
output = await minify(options);
160160
} catch (error) {
161161
compilation.errors.push(
162162
/** @type {WebpackError} */ (
@@ -220,4 +220,4 @@ class JsonMinimizerPlugin {
220220
}
221221
}
222222

223-
export default JsonMinimizerPlugin;
223+
module.exports = JsonMinimizerPlugin;

src/minify.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ const minify = async (options) => {
2525
return { code: result };
2626
};
2727

28-
module.exports.minify = minify;
28+
module.exports = { minify };

test/cjs.test.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

types/cjs.d.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

types/index.d.ts

Lines changed: 45 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,4 @@
1-
export default JsonMinimizerPlugin;
2-
export type Schema = import("schema-utils/declarations/validate").Schema;
3-
export type Compiler = import("webpack").Compiler;
4-
export type Compilation = import("webpack").Compilation;
5-
export type Asset = import("webpack").Asset;
6-
export type WebpackError = import("webpack").WebpackError;
7-
export type Rule = RegExp | string;
8-
export type Rules = Rule[] | Rule;
9-
export type JSONOptions = {
10-
replacer?:
11-
| ((this: any, key: string, value: any) => any | (number | string)[] | null)
12-
| undefined;
13-
space?: string | number | undefined;
14-
};
15-
export type BasePluginOptions = {
16-
test?: Rules | undefined;
17-
include?: Rules | undefined;
18-
exclude?: Rules | undefined;
19-
minimizerOptions?: JSONOptions | undefined;
20-
};
21-
export type MinimizedResult = {
22-
code: string;
23-
};
24-
export type InternalOptions = {
25-
input: string;
26-
minimizerOptions?: JSONOptions | undefined;
27-
};
28-
export type InternalPluginOptions = BasePluginOptions;
1+
export = JsonMinimizerPlugin;
292
/** @typedef {import("schema-utils/declarations/validate").Schema} Schema */
303
/** @typedef {import("webpack").Compiler} Compiler */
314
/** @typedef {import("webpack").Compilation} Compilation */
@@ -59,13 +32,12 @@ export type InternalPluginOptions = BasePluginOptions;
5932
*/
6033
declare class JsonMinimizerPlugin {
6134
/**
62-
* @private
6335
* @param {any} error
6436
* @param {string} file
6537
* @param {string} context
6638
* @returns {Error}
6739
*/
68-
private static buildError;
40+
static buildError(error: any, file: string, context: string): Error;
6941
/**
7042
* @param {BasePluginOptions} [options]
7143
*/
@@ -89,3 +61,46 @@ declare class JsonMinimizerPlugin {
8961
*/
9062
apply(compiler: Compiler): void;
9163
}
64+
declare namespace JsonMinimizerPlugin {
65+
export {
66+
Schema,
67+
Compiler,
68+
Compilation,
69+
Asset,
70+
WebpackError,
71+
Rule,
72+
Rules,
73+
JSONOptions,
74+
BasePluginOptions,
75+
MinimizedResult,
76+
InternalOptions,
77+
InternalPluginOptions,
78+
};
79+
}
80+
type Compiler = import("webpack").Compiler;
81+
type BasePluginOptions = {
82+
test?: Rules | undefined;
83+
include?: Rules | undefined;
84+
exclude?: Rules | undefined;
85+
minimizerOptions?: JSONOptions | undefined;
86+
};
87+
type Schema = import("schema-utils/declarations/validate").Schema;
88+
type Compilation = import("webpack").Compilation;
89+
type Asset = import("webpack").Asset;
90+
type WebpackError = import("webpack").WebpackError;
91+
type Rule = RegExp | string;
92+
type Rules = Rule[] | Rule;
93+
type JSONOptions = {
94+
replacer?:
95+
| ((this: any, key: string, value: any) => any | (number | string)[] | null)
96+
| undefined;
97+
space?: string | number | undefined;
98+
};
99+
type MinimizedResult = {
100+
code: string;
101+
};
102+
type InternalOptions = {
103+
input: string;
104+
minimizerOptions?: JSONOptions | undefined;
105+
};
106+
type InternalPluginOptions = BasePluginOptions;

0 commit comments

Comments
 (0)