Skip to content

Commit

Permalink
Re-add build.mjs and remove AlpineJS references (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
hopsoft authored Feb 15, 2024
1 parent 4ced60b commit 07dbf99
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 62 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,8 @@ Commands can be tested in isolation as well as with standard Rails controller, i
- [rails](https://rubygems.org/gems/rails) `>= 6.1`
- [turbo-rails](https://rubygems.org/gems/turbo-rails) `>= 1.1`
- [@hotwired/turbo-rails](https://www.npmjs.com/package/@hotwired/turbo-rails) `>= 7.2`
- [alpinejs](https://www.npmjs.com/package/alpinejs) `>= 3.13`
- [@alpinejs/morph](https://www.npmjs.com/package/@alpinejs/morph) `>= 3.13`
- [@turbo-boost/streams](https://www.npmjs.com/package/@turbo-boost/streams) `>= 0.1.7`
- [turbo_boost-streams](https://rubygems.org/gems/turbo_boost-streams) `>= 0.1.10`
- [@turbo-boost/streams](https://www.npmjs.com/package/@turbo-boost/streams) `>= 0.1.10`

## Setup

Expand Down
42 changes: 42 additions & 0 deletions bin/build.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import * as esbuild from 'esbuild'
import fs from 'fs'

const debug = process.argv.includes('--debug')

const context = await esbuild.context({
entryPoints: ['app/javascript/index.js'],
external: ['@hotwired/turbo'],
bundle: true,
format: 'esm',
logLevel: 'debug',
metafile: true,
minify: !debug,
outfile: 'app/assets/builds/@turbo-boost/commands.js',
sourcemap: true,
target: ['chrome79', 'edge44', 'es2020', 'firefox71', 'opera65', 'safari13']
})

const watch = process.argv.includes('--watch')

if (watch) {
context.logLevel = 'verbose'
await context.watch()
} else {
const result = await context.rebuild()
const metafile = 'app/assets/builds/@turbo-boost/commands.metafile.json'

fs.writeFile(metafile, JSON.stringify(result.metafile), ex => {
if (ex) {
console.error('Build failed!❗️')
conosle.error(ex)
} else {
const message = [
'Build succeeded! 🚀',
`|- Metafile saved to ... → ${metafile}`,
'|- Analyze the bundle at → https://esbuild.github.io/analyze/'
]
console.log(message.join('\n'))
}
context.dispose()
})
}
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ services:
esbuild:
<<: *default_app
container_name: turbo_boost-commands-esbuild
command: /bin/bash -c "npm run build -- --watch"
command: /bin/bash -c "npm run build:watch"
depends_on:
web:
condition: service_healthy
Expand Down
68 changes: 23 additions & 45 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@
"author": "Nate Hopkins (hopsoft) <[email protected]>",
"license": "MIT",
"peerDependencies": {
"@alpinejs/morph": ">= 3.13.5",
"@hotwired/turbo-rails": ">= 7.2.0",
"@turbo-boost/streams": "^0.1.8",
"alpinejs": ">= 3.13.5"
"@turbo-boost/streams": "^0.1.10"
},
"devDependencies": {
"@tailwindcss/aspect-ratio": "^0.4.2",
Expand All @@ -34,6 +32,7 @@
"tailwindcss": "^3.4.1"
},
"scripts": {
"build": "esbuild app/javascript/index.js --bundle --minify --sourcemap --external:alpinejs --external:@alpinejs/morph --external:@hotwired/turbo-rails --external:@turbo-boost/streams --format=esm --target=es2020,chrome79,edge44,firefox71,opera65,safari13 --outfile=app/assets/builds/@turbo-boost/commands.js"
"build": "node bin/build.mjs",
"build:watch": "node bin/build.mjs --watch"
}
}
4 changes: 1 addition & 3 deletions test/dummy/config/importmap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

# Pin npm packages by running ./bin/importmap

pin "@alpinejs/morph", to: "@alpinejs--morph.js" # @3.13.5
pin "@hotwired/stimulus", to: "@hotwired--stimulus.js" # @3.2.2
pin "@hotwired/turbo", to: "@hotwired--turbo.js" # @8.0.2
pin "@hotwired/turbo-rails", to: "@hotwired--turbo-rails.js" # @8.0.2
pin "@rails/actioncable", to: "@rails--actioncable.js" # @7.1.3
pin "@rails/actioncable/src", to: "@rails--actioncable--src.js" # @7.1.3
pin "@turbo-boost/streams", to: "@turbo-boost--streams.js" # @0.1.8
pin "alpinejs" # @3.13.5
pin "@turbo-boost/streams", to: "@turbo-boost--streams.js" # @0.1.10

# NOTE: The following libs stop working if we allow Rails to vendor them
pin "flowbite", to: "https://cdnjs.cloudflare.com/ajax/libs/flowbite/1.7.0/flowbite.turbo.min.js"
Expand Down
2 changes: 0 additions & 2 deletions test/dummy/vendor/javascript/@alpinejs--morph.js

This file was deleted.

Loading

0 comments on commit 07dbf99

Please sign in to comment.