From 5827509ab42b8139ea2d41fb98e6f89460400f8b Mon Sep 17 00:00:00 2001 From: Marco Roth Date: Thu, 7 Oct 2021 09:17:18 +0200 Subject: [PATCH] Include `webpack-helpers` in `stimulus` glue/proxy package (#453) * move webpack-helpers back to it's own file So they can be impored with `stimulus/webpack-helpers` again See: https://github.com/hotwired/stimulus/blob/v2.0.0/packages/stimulus/webpack-helpers.js * rollup webpack-helpers too * add browser field too --- .gitignore | 1 - packages/stimulus/index.d.ts | 2 + packages/stimulus/package.json | 29 +++++++++- packages/stimulus/rollup.config.js | 76 +++++++++++++++++++------- packages/stimulus/webpack-helpers.d.ts | 2 + packages/stimulus/webpack-helpers.js | 1 + packages/stimulus/yarn.lock | 5 ++ 7 files changed, 92 insertions(+), 24 deletions(-) create mode 100644 packages/stimulus/index.d.ts create mode 100644 packages/stimulus/webpack-helpers.d.ts create mode 100644 packages/stimulus/webpack-helpers.js diff --git a/.gitignore b/.gitignore index 5adc4fc4..57f3abb9 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,3 @@ node_modules/ docs/api/ *.log *.tsbuildinfo -*.d.ts diff --git a/packages/stimulus/index.d.ts b/packages/stimulus/index.d.ts new file mode 100644 index 00000000..cff69969 --- /dev/null +++ b/packages/stimulus/index.d.ts @@ -0,0 +1,2 @@ +export * from "@hotwired/stimulus" +export as namespace Stimulus diff --git a/packages/stimulus/package.json b/packages/stimulus/package.json index 1e789456..0964aa51 100644 --- a/packages/stimulus/package.json +++ b/packages/stimulus/package.json @@ -9,16 +9,39 @@ "Javan Makhmali ", "Sam Stephenson " ], - "main": "dist/stimulus.js", - "module": "dist/stimulus.esm.js", + "main": "./dist/stimulus.js", + "module": "./dist/stimulus.js", + "browser": "./dist/stimulus.js", + "umd:main": "./dist/stimulus.umd.js", + "types": "./index.d.ts", + "exports": { + ".": { + "browser": "./dist/stimulus.js", + "import": "./dist/stimulus.js", + "umd": "./dist/stimulus.umd.js", + "types": "./index.d.ts" + }, + "./webpack-helpers": { + "browser": "./dist/webpack-helpers.js", + "import": "./dist/webpack-helpers.js", + "umd": "./dist/webpack-helpers.umd.js", + "types": "./webpack-helpers.d.ts" + } + }, "files": [ + "index.d.ts", "dist/stimulus.js", "dist/stimulus.umd.js", + "webpack-helpers.js", + "webpack-helpers.d.ts", + "dist/webpack-helpers.js", + "dist/webpack-helpers.umd.js", "README.md" ], "license": "MIT", "dependencies": { - "@hotwired/stimulus": "^3.0.0" + "@hotwired/stimulus": "^3.0.0", + "@hotwired/stimulus-webpack-helpers": "^1.0.0" }, "devDependencies": { "@rollup/plugin-node-resolve": "^13.0.0", diff --git a/packages/stimulus/rollup.config.js b/packages/stimulus/rollup.config.js index 5311ffd7..21668cf7 100644 --- a/packages/stimulus/rollup.config.js +++ b/packages/stimulus/rollup.config.js @@ -4,23 +4,59 @@ import { version } from "./package.json" const year = new Date().getFullYear() const banner = `/*\nStimulus ${version}\nCopyright © ${year} Basecamp, LLC\n */` -export default { - input: "index.js", - output: [ - { - name: "Stimulus", - file: "dist/stimulus.umd.js", - format: "umd", - banner - }, - { - file: "dist/stimulus.js", - format: "es", - banner - }, - ], - context: "window", - plugins: [ - resolve() - ] -} +export default [ + { + external: [ + "@hotwired/stimulus", + "@hotwired/stimulus-webpack-helpers" + ], + input: "index.js", + output: [ + { + globals: { + '@hotwired/stimulus': 'Stimulus' + }, + name: "Stimulus", + file: "dist/stimulus.umd.js", + format: "umd", + banner + }, + { + file: "dist/stimulus.js", + format: "es", + banner + }, + ], + context: "window", + plugins: [ + resolve() + ] + }, + { + external: [ + "@hotwired/stimulus", + "@hotwired/stimulus-webpack-helpers" + ], + input: "webpack-helpers.js", + output: [ + { + globals: { + '@hotwired/stimulus-webpack-helpers': 'StimulusWebpackHelpers' + }, + name: "Stimulus", + file: "dist/webpack-helpers.umd.js", + format: "umd", + banner + }, + { + file: "dist/webpack-helpers.js", + format: "es", + banner + }, + ], + context: "window", + plugins: [ + resolve() + ] + } +] diff --git a/packages/stimulus/webpack-helpers.d.ts b/packages/stimulus/webpack-helpers.d.ts new file mode 100644 index 00000000..7b2857d8 --- /dev/null +++ b/packages/stimulus/webpack-helpers.d.ts @@ -0,0 +1,2 @@ +export * from "@hotwired/stimulus-webpack-helpers" +export as namespace StimulusWebpackHelpers diff --git a/packages/stimulus/webpack-helpers.js b/packages/stimulus/webpack-helpers.js new file mode 100644 index 00000000..7dce34b6 --- /dev/null +++ b/packages/stimulus/webpack-helpers.js @@ -0,0 +1 @@ +export * from "@hotwired/stimulus-webpack-helpers" diff --git a/packages/stimulus/yarn.lock b/packages/stimulus/yarn.lock index d19f7d36..5c5c297c 100644 --- a/packages/stimulus/yarn.lock +++ b/packages/stimulus/yarn.lock @@ -2,6 +2,11 @@ # yarn lockfile v1 +"@hotwired/stimulus-webpack-helpers@^1.0.0": + version "1.0.0" + resolved "https://registry.yarnpkg.com/@hotwired/stimulus-webpack-helpers/-/stimulus-webpack-helpers-1.0.0.tgz#6bd7906a4a2b6e1cd8732203b60264f987bd1084" + integrity sha512-6oKDmJDSsV+zdlHnF485nneuekY/Zbl669wei4HIiwxUWHhVSU1XIVji4aj+Ws9AXghjTYBS8H5ralB97BVMDw== + "@hotwired/stimulus@^3.0.0": version "3.0.0" resolved "https://registry.yarnpkg.com/@hotwired/stimulus/-/stimulus-3.0.0.tgz#45171e61417af60f0e546665c52fae5b67295cee"