Skip to content

Commit

Permalink
Switch to ESBuild (#567)
Browse files Browse the repository at this point in the history
* First commit for esbuild over webpack mix

* Get Stimulus working

* Make a yarn prod command that works

* Update webpack terminology
  • Loading branch information
stephendolan authored Dec 13, 2021
1 parent 5c2c750 commit 8b47120
Show file tree
Hide file tree
Showing 13 changed files with 372 additions and 5,061 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ start_server
/tmp
/public/js
/public/css
/public/mix-manifest.json
/node_modules
yarn-error.log
.DS_Store
3 changes: 2 additions & 1 deletion Procfile.dev
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
system_check: script/system_check && sleep 100000
web: lucky watch --reload-browser
assets: yarn watch
js_assets: yarn watch:js
css_assets: yarn watch:css
docker: docker-compose up
10 changes: 5 additions & 5 deletions dockerfiles/webserver.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ COPY shard.yml shard.lock ./
RUN shards install --production

# Install the application Yarn dependencies, then compile production CSS/JS
FROM node:alpine as webpack_build
WORKDIR /webpack
FROM node:alpine as asset_build
WORKDIR /assets
COPY . .
RUN yarn install
RUN yarn prod
Expand All @@ -19,7 +19,7 @@ ENV LUCKY_ENV=production
RUN apk --no-cache add yaml-static
COPY . .
COPY --from=crystal_dependencies /shards/lib lib
COPY --from=webpack_build /webpack/public public
COPY --from=asset_build /assets/public public
RUN crystal build --static --release tasks.cr -o /usr/local/bin/lucky

# Build the webserver binary
Expand All @@ -29,7 +29,7 @@ RUN apk --no-cache add yaml-static
ENV LUCKY_ENV=production
COPY . .
COPY --from=crystal_dependencies /shards/lib lib
COPY --from=webpack_build /webpack/public public
COPY --from=asset_build /assets/public public
RUN shards build --production --static --release
RUN mv ./bin/webserver /usr/local/bin/webserver

Expand All @@ -46,5 +46,5 @@ RUN apk --no-cache add postgresql-client
COPY --from=release_script_build /usr/local/bin/release release
COPY --from=lucky_tasks_build /usr/local/bin/lucky /usr/local/bin/lucky
COPY --from=lucky_webserver_build /usr/local/bin/webserver webserver
COPY --from=webpack_build /webpack/public public
COPY --from=asset_build /assets/public public
CMD ["./release"]
23 changes: 10 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,33 @@
"license": "UNLICENSED",
"private": true,
"dependencies": {
"@fontsource/inter": "^4.5.1",
"@hotwired/stimulus": "^3.0.1",
"@hotwired/stimulus-webpack-helpers": "^1.0.1",
"@rails/ujs": "^6.1.4",
"@tailwindcss/aspect-ratio": "^0.4.0",
"@tailwindcss/forms": "^0.3.4",
"@tailwindcss/typography": "^0.4.1",
"autoprefixer": "^10.3.6",
"esbuild": "^0.13.3",
"postcss": "^8.4.5",
"tailwindcss": "^2.2.19",
"turbolinks": "^5.2.0"
},
"scripts": {
"heroku-postbuild": "yarn prod",
"dev": "TAILWIND_MODE=build yarn run mix",
"watch": "yarn run mix watch",
"prod": "yarn run mix --production"
"build:js": "esbuild src/js/app.ts --bundle --sourcemap=inline --target=es2016 --outfile=public/js/app.js",
"build:css": "tailwindcss --postcss --input=src/css/app.css --output=public/css/app.css",
"watch:js": "esbuild src/js/app.ts --bundle --watch --sourcemap=inline --target=es2016 --outfile=public/js/app.js",
"watch:css": "tailwindcss --postcss --watch --input=src/css/app.css --output=public/css/app.css",
"prod:js": "esbuild src/js/app.ts --bundle --minify --sourcemap=inline --target=es2016 --outfile=public/js/app.js",
"prod:css": "tailwindcss --postcss --minify --input=src/css/app.css --output=public/css/app.css",
"prod": "yarn prod:js && yarn prod:css"
},
"devDependencies": {
"@babel/compat-data": "^7.16.4",
"@types/node": "^16.11.12",
"@types/webpack-env": "^1.16.3",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"browser-sync": "^2.27.7",
"compression-webpack-plugin": "^9.1.1",
"eslint": "^7.32.0",
"laravel-mix": "^6.0.34",
"prettier": "^2.5.1",
"resolve-url-loader": "4.0.0",
"ts-loader": "^9.2.6",
"tailwindcss-font-inter": "^3.0.0",
"typescript": "^4.5.3"
}
}
6 changes: 6 additions & 0 deletions postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
plugins: {
autoprefixer: {},
tailwindcss: {},
},
};
4 changes: 4 additions & 0 deletions public/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"/js/app.js": "/js/app.js",
"/css/app.css": "/css/app.css"
}
4 changes: 0 additions & 4 deletions script/setup
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ print_done

notice "Installing node dependencies"
yarn install --no-progress | indent

notice "Compiling assets"
yarn dev | indent

print_done

notice "Installing shards"
Expand Down
20 changes: 14 additions & 6 deletions src/js/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,25 @@ require("@rails/ujs").start();
// Turbolinks is optional. Learn more: https://github.com/turbolinks/turbolinks/
require("turbolinks").start();

import "@fontsource/inter";

// If using Turbolinks, you can attach events to page load like this:
//
// document.addEventListener("turbolinks:load", function() {
// ...
// })

import { Application } from "@hotwired/stimulus";
import { definitionsFromContext } from "@hotwired/stimulus-webpack-helpers";

const application = Application.start();
const context = require.context("./controllers", true, /\.ts$/);
application.load(definitionsFromContext(context));
import HelloController from "./controllers/hello_controller";
import RemovableController from "./controllers/removable_controller";
import ToggleController from "./controllers/toggle_controller";

declare global {
interface Window {
Stimulus: any;
}
}

let Stimulus = (window.Stimulus = Application.start());
Stimulus.register("hello", HelloController);
Stimulus.register("toggle", ToggleController);
Stimulus.register("removable", RemovableController);
2 changes: 1 addition & 1 deletion src/pages/auth_layout.cr
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ abstract class AuthLayout
html lang: "en" do
mount Shared::LayoutHead, page_title: page_title

body do
body class: "font-inter" do
mount Shared::Navbar, simple: true
mount Shared::FlashMessages, context.flash
content
Expand Down
2 changes: 1 addition & 1 deletion src/pages/main_layout.cr
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ abstract class MainLayout
html lang: "en" do
mount Shared::LayoutHead, page_title: page_title

body class: "min-h-screen bg-gray-100" do
body class: "font-inter min-h-screen bg-gray-100" do
mount Shared::Navbar, user: current_user
mount Shared::FlashMessages, context.flash

Expand Down
1 change: 1 addition & 0 deletions tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ module.exports = {
require("@tailwindcss/forms"),
require("@tailwindcss/typography"),
require("@tailwindcss/aspect-ratio"),
require("tailwindcss-font-inter"),
],
};
112 changes: 0 additions & 112 deletions webpack.mix.js

This file was deleted.

Loading

0 comments on commit 8b47120

Please sign in to comment.