From 4d5137de8a03f2bfb578a9874b5a9ecdf85ae251 Mon Sep 17 00:00:00 2001 From: "voraton.l" Date: Mon, 24 Jan 2022 16:34:23 +0700 Subject: [PATCH] fix: Exposing type BREAKING CHANGE: Export module for TS require export as object so please import as object --- README.md | 2 +- package.json | 3 ++- rollup.config.js | 4 +++- src/index.ts | 4 +--- test/webpack.config.js | 2 +- yarn.lock | 13 ++++--------- 6 files changed, 12 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index f076974..df741a7 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ yarn add --dev define-after-bundle-webpack-plugin #### In your webpack config ```js -const DefineAfterBundleWebpackPlugin = require('define-after-bundle-webpack-plugin') +const { DefineAfterBundleWebpackPlugin } = require('define-after-bundle-webpack-plugin') module.exports = { ... diff --git a/package.json b/package.json index 10b6351..254d503 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "define-after-bundle-webpack-plugin", "version": "0.0.0", "main": "build/index.js", + "types": "build/index.d.ts", "entry": "src/index.ts", "deploy": "build", "license": "MIT", @@ -19,7 +20,7 @@ "@rollup/plugin-commonjs": "19.0.0", "@rollup/plugin-json": "4.1.0", "@rollup/plugin-node-resolve": "13.0.0", - "@rollup/plugin-typescript": "8.2.1", + "@rollup/plugin-typescript": "8.3.0", "@types/node": "16.11.6", "@types/webpack": "4", "@types/webpack-env": "1.16.3", diff --git a/rollup.config.js b/rollup.config.js index efc9270..94db42c 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -19,7 +19,9 @@ export default { resolve(), commonjs(), typescript({ - outDir: config.deploy + outDir: config.deploy, + declaration: true, + emitDeclarationOnly: true, }), json(), visualizer({ diff --git a/src/index.ts b/src/index.ts index 655628d..65ca9a7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,7 +3,7 @@ import { ConcatSource } from 'webpack-sources' const PLUGIN_NAME = 'DefineAfterBundleWebpackPlugin' -class DefineAfterBundleWebpackPlugin { +export class DefineAfterBundleWebpackPlugin { replaceMapper: Record constructor(replaceMapper: Record) { @@ -39,5 +39,3 @@ class DefineAfterBundleWebpackPlugin { }) } } - -module.exports = DefineAfterBundleWebpackPlugin diff --git a/test/webpack.config.js b/test/webpack.config.js index 134ce6c..c3b4640 100644 --- a/test/webpack.config.js +++ b/test/webpack.config.js @@ -1,5 +1,5 @@ const path = require('path') -const DefineAfterBundleWebpackPlugin = require('../build') +const { DefineAfterBundleWebpackPlugin } = require('../build') module.exports = { entry: path.resolve(__dirname, 'index.js'), diff --git a/yarn.lock b/yarn.lock index 0f691d6..d1efd56 100644 --- a/yarn.lock +++ b/yarn.lock @@ -366,10 +366,10 @@ is-module "^1.0.0" resolve "^1.19.0" -"@rollup/plugin-typescript@8.2.1": - version "8.2.1" - resolved "https://registry.yarnpkg.com/@rollup/plugin-typescript/-/plugin-typescript-8.2.1.tgz#f1a32d4030cc83432ce36a80a922280f0f0b5d44" - integrity sha512-Qd2E1pleDR4bwyFxqbjt4eJf+wB0UKVMLc7/BAFDGVdAXQMCsD4DUv5/7/ww47BZCYxWtJqe1Lo0KVNswBJlRw== +"@rollup/plugin-typescript@8.3.0": + version "8.3.0" + resolved "https://registry.yarnpkg.com/@rollup/plugin-typescript/-/plugin-typescript-8.3.0.tgz#bc1077fa5897b980fc27e376c4e377882c63e68b" + integrity sha512-I5FpSvLbtAdwJ+naznv+B4sjXZUcIvLLceYpITAn7wAP8W0wqc5noLdGIp9HGVntNhRWXctwPYrSSFQxtl0FPA== dependencies: "@rollup/pluginutils" "^3.1.0" resolve "^1.17.0" @@ -5560,11 +5560,6 @@ source-map@^0.7.3: resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.7.3.tgz#5302f8169031735226544092e64981f751750383" integrity sha512-CkCj6giN3S+n9qrYiBTX5gystlENnRW5jZeNLHpe6aue+SrHcG5VYwujhW9s4dY31mEGsxBDrHR6oI69fTXsaQ== -source-replacement@1.0.4: - version "1.0.4" - resolved "https://registry.yarnpkg.com/source-replacement/-/source-replacement-1.0.4.tgz#0ef6aa9fd5c15ac10b64a2df29ee449432324232" - integrity sha512-/QTmwxiHRMaBp5NPwtnryDVIXKHs+3SaErnaiPPoKyzr4rODKdPrPxG35Y6iaPtvae2Tq+P/nRu5natt2JgdEw== - sourcemap-codec@^1.4.4: version "1.4.8" resolved "https://registry.yarnpkg.com/sourcemap-codec/-/sourcemap-codec-1.4.8.tgz#ea804bd94857402e6992d05a38ef1ae35a9ab4c4"