diff --git a/package.json b/package.json index a2e0523..94c1005 100644 --- a/package.json +++ b/package.json @@ -11,14 +11,14 @@ "type": "opencollective", "url": "https://opencollective.com/webpack" }, - "main": "dist/cjs.js", - "types": "types/cjs.d.ts", + "main": "dist/index.js", + "types": "types/index.d.ts", "engines": { "node": ">= 12.13.0" }, "scripts": { "start": "npm run build -- -w", - "clean": "del-cli dist", + "clean": "del-cli dist types", "prebuild": "npm run clean", "build:types": "tsc --declaration --emitDeclarationOnly --outDir types && prettier \"types/**/*.ts\" --write", "build:code": "cross-env NODE_ENV=production babel src -d dist --copy-files", diff --git a/src/cjs.js b/src/cjs.js deleted file mode 100644 index 0f29dbe..0000000 --- a/src/cjs.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require("./index").default; diff --git a/src/index.js b/src/index.js index c3f94c3..b01aa3c 100644 --- a/src/index.js +++ b/src/index.js @@ -1,7 +1,7 @@ -import { validate } from "schema-utils"; +const { validate } = require("schema-utils"); -import schema from "./options.json"; -import { minify as minifyFn } from "./minify"; +const schema = require("./options.json"); +const { minify } = require("./minify"); /** @typedef {import("schema-utils/declarations/validate").Schema} Schema */ /** @typedef {import("webpack").Compiler} Compiler */ @@ -156,7 +156,7 @@ class JsonMinimizerPlugin { }; try { - output = await minifyFn(options); + output = await minify(options); } catch (error) { compilation.errors.push( /** @type {WebpackError} */ ( @@ -220,4 +220,4 @@ class JsonMinimizerPlugin { } } -export default JsonMinimizerPlugin; +module.exports = JsonMinimizerPlugin; diff --git a/src/minify.js b/src/minify.js index fe190e2..9d6b0a0 100644 --- a/src/minify.js +++ b/src/minify.js @@ -25,4 +25,4 @@ const minify = async (options) => { return { code: result }; }; -module.exports.minify = minify; +module.exports = { minify }; diff --git a/test/cjs.test.js b/test/cjs.test.js deleted file mode 100644 index 06cab73..0000000 --- a/test/cjs.test.js +++ /dev/null @@ -1,8 +0,0 @@ -import src from "../src"; -import cjs from "../src/cjs"; - -describe("CJS", () => { - it("should export loader", () => { - expect(cjs).toEqual(src); - }); -}); diff --git a/types/cjs.d.ts b/types/cjs.d.ts deleted file mode 100644 index a7e7d3c..0000000 --- a/types/cjs.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -declare const _exports: typeof import("./index").default; -export = _exports; diff --git a/types/index.d.ts b/types/index.d.ts index 35a093f..2a9ed08 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,31 +1,4 @@ -export default JsonMinimizerPlugin; -export type Schema = import("schema-utils/declarations/validate").Schema; -export type Compiler = import("webpack").Compiler; -export type Compilation = import("webpack").Compilation; -export type Asset = import("webpack").Asset; -export type WebpackError = import("webpack").WebpackError; -export type Rule = RegExp | string; -export type Rules = Rule[] | Rule; -export type JSONOptions = { - replacer?: - | ((this: any, key: string, value: any) => any | (number | string)[] | null) - | undefined; - space?: string | number | undefined; -}; -export type BasePluginOptions = { - test?: Rules | undefined; - include?: Rules | undefined; - exclude?: Rules | undefined; - minimizerOptions?: JSONOptions | undefined; -}; -export type MinimizedResult = { - code: string; -}; -export type InternalOptions = { - input: string; - minimizerOptions?: JSONOptions | undefined; -}; -export type InternalPluginOptions = BasePluginOptions; +export = JsonMinimizerPlugin; /** @typedef {import("schema-utils/declarations/validate").Schema} Schema */ /** @typedef {import("webpack").Compiler} Compiler */ /** @typedef {import("webpack").Compilation} Compilation */ @@ -59,13 +32,12 @@ export type InternalPluginOptions = BasePluginOptions; */ declare class JsonMinimizerPlugin { /** - * @private * @param {any} error * @param {string} file * @param {string} context * @returns {Error} */ - private static buildError; + static buildError(error: any, file: string, context: string): Error; /** * @param {BasePluginOptions} [options] */ @@ -89,3 +61,46 @@ declare class JsonMinimizerPlugin { */ apply(compiler: Compiler): void; } +declare namespace JsonMinimizerPlugin { + export { + Schema, + Compiler, + Compilation, + Asset, + WebpackError, + Rule, + Rules, + JSONOptions, + BasePluginOptions, + MinimizedResult, + InternalOptions, + InternalPluginOptions, + }; +} +type Compiler = import("webpack").Compiler; +type BasePluginOptions = { + test?: Rules | undefined; + include?: Rules | undefined; + exclude?: Rules | undefined; + minimizerOptions?: JSONOptions | undefined; +}; +type Schema = import("schema-utils/declarations/validate").Schema; +type Compilation = import("webpack").Compilation; +type Asset = import("webpack").Asset; +type WebpackError = import("webpack").WebpackError; +type Rule = RegExp | string; +type Rules = Rule[] | Rule; +type JSONOptions = { + replacer?: + | ((this: any, key: string, value: any) => any | (number | string)[] | null) + | undefined; + space?: string | number | undefined; +}; +type MinimizedResult = { + code: string; +}; +type InternalOptions = { + input: string; + minimizerOptions?: JSONOptions | undefined; +}; +type InternalPluginOptions = BasePluginOptions;