forked from activeadmin/activeadmin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make NPM package compatible with tools like vite_rails (activeadmin#8234
) ### Context This PR is related to activeadmin#8228. It changes the content of our npm package to be compatible with tools like `vite_rails`. _Note:_ Our source code is still written for a host app using `importmap-rails`. This PR doesn't change that. Our tests and development apps work like that and there is no plan to change it. ### Description Our source code is written with importmaps in mind. All imports are absolute and based on `active_admin` alias/map. We don't distribute any importmap definition within our npm package. That makes it impossible to use our package with bundlers/tools like vite, webpack, rollup, etc out of the box. To integrate with `vite_rails` I want to define the following file ```javascript // app/javascript/entrypoints/active_admin.js import '@activeadmin/activeadmin' ``` Our main file is `app/javascript/active_admin.js`, when `vite` parses the file it fails to resolve imports like `import "active_admin/features/dark_mode_toggle"`. Even more, since we are vendoring external dependencies `vite` can't process `import "flowbite"`. This PR does two things: 1) add external dependencies to package.json 2) add a build step to preprocess our code and generate a dist folder where alias is replaced with relative imports.
- Loading branch information
Showing
4 changed files
with
179 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ | |
/src | ||
/vendor/bundle | ||
/rails_70 | ||
/dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import path from 'node:path'; | ||
import { URL, fileURLToPath } from 'node:url'; | ||
import { readFileSync } from 'node:fs'; | ||
import alias from '@rollup/plugin-alias'; | ||
|
||
const packageJson = JSON.parse( | ||
readFileSync(new URL('./package.json', import.meta.url)) | ||
); | ||
|
||
const __dirname = fileURLToPath(new URL('.', import.meta.url)); | ||
const projectRootDir = path.resolve(__dirname); | ||
const assetsDir = path.resolve(projectRootDir, 'app/javascript'); | ||
|
||
|
||
/** | ||
* @type {import('rollup').RollupOptions} | ||
*/ | ||
export default [ | ||
// build dist folder with all files from app/javascript using relative imports. | ||
// let bundler tools like webpack or rollup to process our package | ||
{ | ||
input: ['app/javascript/active_admin.js'], | ||
output: { | ||
format: 'es', | ||
dir: 'dist', | ||
preserveModules: true, | ||
}, | ||
external: Object.keys(packageJson.dependencies), | ||
plugins: [ | ||
alias({ | ||
entries: [ | ||
{ | ||
find: 'active_admin', | ||
replacement: path.join(assetsDir, 'active_admin'), | ||
}, | ||
] | ||
}) | ||
] | ||
} | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,6 +133,11 @@ | |
resolved "https://registry.yarnpkg.com/@pkgjs/parseargs/-/parseargs-0.11.0.tgz#a77ea742fab25775145434eb1d2328cf5013ac33" | ||
integrity sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg== | ||
|
||
"@popperjs/core@^2.9.3": | ||
version "2.11.8" | ||
resolved "https://registry.yarnpkg.com/@popperjs/core/-/core-2.11.8.tgz#6b79032e760a0899cd4204710beede972a3a185f" | ||
integrity sha512-P1st0aksCrn9sGZhp8GMYwBnQsbvAWsZAX44oXNNvLHGqAOcoVxmjZiohstwQ7SqKnbR47akdNi+uleWD8+g6A== | ||
|
||
"@protobufjs/aspromise@^1.1.1", "@protobufjs/aspromise@^1.1.2": | ||
version "1.1.2" | ||
resolved "https://registry.yarnpkg.com/@protobufjs/aspromise/-/aspromise-1.1.2.tgz#9b8b0cc663d669a7d8f6f5d0893a14d348f30fbf" | ||
|
@@ -186,6 +191,88 @@ | |
resolved "https://registry.yarnpkg.com/@protobufjs/utf8/-/utf8-1.1.0.tgz#a777360b5b39a1a2e5106f8e858f2fd2d060c570" | ||
integrity sha512-Vvn3zZrhQZkkBE8LSuW3em98c0FwgO4nxzv6OdSxPKJIEKY2bGbHn+mhGIPerzI4twdxaP8/0+06HBpwf345Lw== | ||
|
||
"@rails/[email protected]": | ||
version "7.1.2" | ||
resolved "https://registry.yarnpkg.com/@rails/ujs/-/ujs-7.1.2.tgz#ea903bcc0224e17156015d995b6f1b83e27d64b2" | ||
integrity sha512-c5x02djEKEVVE4qfN4XgElJS4biM0xxtIVpcJ0ZHLK116U19rowTtmD0AJ/RCb3Xaewa4GPIWLlwgeC0dCQqzw== | ||
|
||
"@rollup/plugin-alias@^5.1.0": | ||
version "5.1.0" | ||
resolved "https://registry.yarnpkg.com/@rollup/plugin-alias/-/plugin-alias-5.1.0.tgz#99a94accc4ff9a3483be5baeedd5d7da3b597e93" | ||
integrity sha512-lpA3RZ9PdIG7qqhEfv79tBffNaoDuukFDrmhLqg9ifv99u/ehn+lOg30x2zmhf8AQqQUZaMk/B9fZraQ6/acDQ== | ||
dependencies: | ||
slash "^4.0.0" | ||
|
||
"@rollup/[email protected]": | ||
version "4.9.5" | ||
resolved "https://registry.yarnpkg.com/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.9.5.tgz#b752b6c88a14ccfcbdf3f48c577ccc3a7f0e66b9" | ||
integrity sha512-idWaG8xeSRCfRq9KpRysDHJ/rEHBEXcHuJ82XY0yYFIWnLMjZv9vF/7DOq8djQ2n3Lk6+3qfSH8AqlmHlmi1MA== | ||
|
||
"@rollup/[email protected]": | ||
version "4.9.5" | ||
resolved "https://registry.yarnpkg.com/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.9.5.tgz#33757c3a448b9ef77b6f6292d8b0ec45c87e9c1a" | ||
integrity sha512-f14d7uhAMtsCGjAYwZGv6TwuS3IFaM4ZnGMUn3aCBgkcHAYErhV1Ad97WzBvS2o0aaDv4mVz+syiN0ElMyfBPg== | ||
|
||
"@rollup/[email protected]": | ||
version "4.9.5" | ||
resolved "https://registry.yarnpkg.com/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.9.5.tgz#5234ba62665a3f443143bc8bcea9df2cc58f55fb" | ||
integrity sha512-ndoXeLx455FffL68OIUrVr89Xu1WLzAG4n65R8roDlCoYiQcGGg6MALvs2Ap9zs7AHg8mpHtMpwC8jBBjZrT/w== | ||
|
||
"@rollup/[email protected]": | ||
version "4.9.5" | ||
resolved "https://registry.yarnpkg.com/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.9.5.tgz#981256c054d3247b83313724938d606798a919d1" | ||
integrity sha512-UmElV1OY2m/1KEEqTlIjieKfVwRg0Zwg4PLgNf0s3glAHXBN99KLpw5A5lrSYCa1Kp63czTpVll2MAqbZYIHoA== | ||
|
||
"@rollup/[email protected]": | ||
version "4.9.5" | ||
resolved "https://registry.yarnpkg.com/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.9.5.tgz#120678a5a2b3a283a548dbb4d337f9187a793560" | ||
integrity sha512-Q0LcU61v92tQB6ae+udZvOyZ0wfpGojtAKrrpAaIqmJ7+psq4cMIhT/9lfV6UQIpeItnq/2QDROhNLo00lOD1g== | ||
|
||
"@rollup/[email protected]": | ||
version "4.9.5" | ||
resolved "https://registry.yarnpkg.com/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.9.5.tgz#c99d857e2372ece544b6f60b85058ad259f64114" | ||
integrity sha512-dkRscpM+RrR2Ee3eOQmRWFjmV/payHEOrjyq1VZegRUa5OrZJ2MAxBNs05bZuY0YCtpqETDy1Ix4i/hRqX98cA== | ||
|
||
"@rollup/[email protected]": | ||
version "4.9.5" | ||
resolved "https://registry.yarnpkg.com/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.9.5.tgz#3064060f568a5718c2a06858cd6e6d24f2ff8632" | ||
integrity sha512-QaKFVOzzST2xzY4MAmiDmURagWLFh+zZtttuEnuNn19AiZ0T3fhPyjPPGwLNdiDT82ZE91hnfJsUiDwF9DClIQ== | ||
|
||
"@rollup/[email protected]": | ||
version "4.9.5" | ||
resolved "https://registry.yarnpkg.com/@rollup/rollup-linux-riscv64-gnu/-/rollup-linux-riscv64-gnu-4.9.5.tgz#987d30b5d2b992fff07d055015991a57ff55fbad" | ||
integrity sha512-HeGqmRJuyVg6/X6MpE2ur7GbymBPS8Np0S/vQFHDmocfORT+Zt76qu+69NUoxXzGqVP1pzaY6QIi0FJWLC3OPA== | ||
|
||
"@rollup/[email protected]": | ||
version "4.9.5" | ||
resolved "https://registry.yarnpkg.com/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.9.5.tgz#85946ee4d068bd12197aeeec2c6f679c94978a49" | ||
integrity sha512-Dq1bqBdLaZ1Gb/l2e5/+o3B18+8TI9ANlA1SkejZqDgdU/jK/ThYaMPMJpVMMXy2uRHvGKbkz9vheVGdq3cJfA== | ||
|
||
"@rollup/[email protected]": | ||
version "4.9.5" | ||
resolved "https://registry.yarnpkg.com/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.9.5.tgz#fe0b20f9749a60eb1df43d20effa96c756ddcbd4" | ||
integrity sha512-ezyFUOwldYpj7AbkwyW9AJ203peub81CaAIVvckdkyH8EvhEIoKzaMFJj0G4qYJ5sw3BpqhFrsCc30t54HV8vg== | ||
|
||
"@rollup/[email protected]": | ||
version "4.9.5" | ||
resolved "https://registry.yarnpkg.com/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.9.5.tgz#422661ef0e16699a234465d15b2c1089ef963b2a" | ||
integrity sha512-aHSsMnUw+0UETB0Hlv7B/ZHOGY5bQdwMKJSzGfDfvyhnpmVxLMGnQPGNE9wgqkLUs3+gbG1Qx02S2LLfJ5GaRQ== | ||
|
||
"@rollup/[email protected]": | ||
version "4.9.5" | ||
resolved "https://registry.yarnpkg.com/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.9.5.tgz#7b73a145891c202fbcc08759248983667a035d85" | ||
integrity sha512-AiqiLkb9KSf7Lj/o1U3SEP9Zn+5NuVKgFdRIZkvd4N0+bYrTOovVd0+LmYCPQGbocT4kvFyK+LXCDiXPBF3fyA== | ||
|
||
"@rollup/[email protected]": | ||
version "4.9.5" | ||
resolved "https://registry.yarnpkg.com/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.9.5.tgz#10491ccf4f63c814d4149e0316541476ea603602" | ||
integrity sha512-1q+mykKE3Vot1kaFJIDoUFv5TuW+QQVaf2FmTT9krg86pQrGStOSJJ0Zil7CFagyxDuouTepzt5Y5TVzyajOdQ== | ||
|
||
"@types/[email protected]": | ||
version "1.0.5" | ||
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-1.0.5.tgz#a6ce3e556e00fd9895dd872dd172ad0d4bd687f4" | ||
integrity sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw== | ||
|
||
"@types/long@^4.0.1": | ||
version "4.0.2" | ||
resolved "https://registry.yarnpkg.com/@types/long/-/long-4.0.2.tgz#b74129719fc8d11c01868010082d483b7545591a" | ||
|
@@ -606,6 +693,14 @@ flatted@^3.2.9: | |
resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.2.9.tgz#7eb4c67ca1ba34232ca9d2d93e9886e611ad7daf" | ||
integrity sha512-36yxDn5H7OFZQla0/jFJmbIKTdZAQHngCedGxiMmpNfEZM0sdEeT+WczLQrjK6D7o2aiyLYDnkw0R3JK0Qv1RQ== | ||
|
||
[email protected]: | ||
version "2.2.1" | ||
resolved "https://registry.yarnpkg.com/flowbite/-/flowbite-2.2.1.tgz#9e22be9ff746bccb9fcf87979bbc5e41a16eaf7a" | ||
integrity sha512-iiZyBTtriEDRHrqXZgpKHaxl4B2J8HZUP8Yn1RXozUDKszWHDVj4GxQqMMB9AJHRWOgXV/4E/LJZ/zqQgBUhWA== | ||
dependencies: | ||
"@popperjs/core" "^2.9.3" | ||
mini-svg-data-uri "^1.4.3" | ||
|
||
foreground-child@^3.1.0: | ||
version "3.1.1" | ||
resolved "https://registry.yarnpkg.com/foreground-child/-/foreground-child-3.1.1.tgz#1d173e776d75d2772fed08efe4a0de1ea1b12d0d" | ||
|
@@ -907,6 +1002,11 @@ micromatch@^4.0.4, micromatch@^4.0.5: | |
braces "^3.0.2" | ||
picomatch "^2.3.1" | ||
|
||
mini-svg-data-uri@^1.4.3: | ||
version "1.4.4" | ||
resolved "https://registry.yarnpkg.com/mini-svg-data-uri/-/mini-svg-data-uri-1.4.4.tgz#8ab0aabcdf8c29ad5693ca595af19dd2ead09939" | ||
integrity sha512-r9deDe9p5FJUPZAk3A59wGH7Ii9YrjjWw0jmw/liSbHl2CHiyXj6FcDXDu2K3TjVAXqiJdaw3xxwlZZr9E6nHg== | ||
|
||
minimatch@^3.0.4, minimatch@^3.0.5, minimatch@^3.1.1, minimatch@^3.1.2: | ||
version "3.1.2" | ||
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.1.2.tgz#19cd194bfd3e428f049a70817c038d89ab4be35b" | ||
|
@@ -1180,6 +1280,28 @@ rimraf@^3.0.2: | |
dependencies: | ||
glob "^7.1.3" | ||
|
||
rollup@^4.9.4: | ||
version "4.9.5" | ||
resolved "https://registry.yarnpkg.com/rollup/-/rollup-4.9.5.tgz#62999462c90f4c8b5d7c38fc7161e63b29101b05" | ||
integrity sha512-E4vQW0H/mbNMw2yLSqJyjtkHY9dslf/p0zuT1xehNRqUTBOFMqEjguDvqhXr7N7r/4ttb2jr4T41d3dncmIgbQ== | ||
dependencies: | ||
"@types/estree" "1.0.5" | ||
optionalDependencies: | ||
"@rollup/rollup-android-arm-eabi" "4.9.5" | ||
"@rollup/rollup-android-arm64" "4.9.5" | ||
"@rollup/rollup-darwin-arm64" "4.9.5" | ||
"@rollup/rollup-darwin-x64" "4.9.5" | ||
"@rollup/rollup-linux-arm-gnueabihf" "4.9.5" | ||
"@rollup/rollup-linux-arm64-gnu" "4.9.5" | ||
"@rollup/rollup-linux-arm64-musl" "4.9.5" | ||
"@rollup/rollup-linux-riscv64-gnu" "4.9.5" | ||
"@rollup/rollup-linux-x64-gnu" "4.9.5" | ||
"@rollup/rollup-linux-x64-musl" "4.9.5" | ||
"@rollup/rollup-win32-arm64-msvc" "4.9.5" | ||
"@rollup/rollup-win32-ia32-msvc" "4.9.5" | ||
"@rollup/rollup-win32-x64-msvc" "4.9.5" | ||
fsevents "~2.3.2" | ||
|
||
run-parallel@^1.1.9: | ||
version "1.2.0" | ||
resolved "https://registry.yarnpkg.com/run-parallel/-/run-parallel-1.2.0.tgz#66d1368da7bdf921eb9d95bd1a9229e7f21a43ee" | ||
|
@@ -1209,6 +1331,11 @@ signal-exit@^4.0.1: | |
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-4.1.0.tgz#952188c1cbd546070e2dd20d0f41c0ae0530cb04" | ||
integrity sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw== | ||
|
||
slash@^4.0.0: | ||
version "4.0.0" | ||
resolved "https://registry.yarnpkg.com/slash/-/slash-4.0.0.tgz#2422372176c4c6c5addb5e2ada885af984b396a7" | ||
integrity sha512-3dOsAHXXUkQTpOYcoAxLIorMTp4gIQr5IW3iVb7A7lFIp0VHhnynm9izx6TssdrIcVIESAlVjtnO2K8bg+Coew== | ||
|
||
source-map-js@^1.0.2: | ||
version "1.0.2" | ||
resolved "https://registry.yarnpkg.com/source-map-js/-/source-map-js-1.0.2.tgz#adbc361d9c62df380125e7f161f71c826f1e490c" | ||
|