Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bundle JavaScript with gem #4

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
514 changes: 514 additions & 0 deletions app/assets/javascripts/turbo_power.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions app/assets/javascripts/turbo_power.min.js

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

1 change: 1 addition & 0 deletions app/assets/javascripts/turbo_power.min.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions app/javascript/turbo_power/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import TurboPower from "turbo_power"
export default TurboPower
14 changes: 14 additions & 0 deletions lib/turbo_power/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,19 @@ class Engine < Rails::Engine
initializer "turbo_power.helpers", after: :initialize do
Turbo::Streams::TagBuilder.include(TurboPower::StreamHelper)
end

# If you don't want to precompile TurboPower's assets (eg. because you're using webpack
# or esbuild), you can do this in an initializer:
#
# config.after_initialize do
# config.assets.precompile -= TurboPower::Engine::PRECOMPILE_ASSETS
# end
PRECOMPILE_ASSETS = ["turbo_power.js", "turbo_power.min.js", "turbo_power.min.js.map"]

initializer "turbo_power.assets" do
if Rails.application.config.respond_to?(:assets)
Rails.application.config.assets.precompile += PRECOMPILE_ASSETS
end
end
end
end
28 changes: 28 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"private": true,
"name": "turbo_power-rails",
"version": "0.1.6",
"description": "Power-pack for Turbo Streams",
"license": "MIT",
"author": "Marco Roth <[email protected]>",
"repository": "https://github.com/marcoroth/turbo_power-rails",
"homepage": "https://github.com/marcoroth/turbo_power-rails",
"module": "app/javascript/turbo_power/index.js",
"main": "app/assets/javascripts/turbo_power.js",
"files": [
"app/javascript/turbo_power"
],
"scripts": {
"build": "rollup -c",
"prerelease": "yarn build"
},
"dependencies": {
"@hotwired/turbo": "^7.2.2",
"turbo_power": "^0.1.6"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^11.0.1",
"rollup": "^2.35.1",
"rollup-plugin-terser": "^7.0.2"
}
}
46 changes: 46 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import resolve from "@rollup/plugin-node-resolve"
import { terser } from "rollup-plugin-terser"
import packageInfo from "./package.json"

const minify = () => {
return terser({
mangle: true,
compress: true
})
}

const pretty = () => {
return terser({
mangle: false,
compress: false,
format: {
beautify: true,
indent_level: 2
}
})
}

const output = [
{
file: packageInfo.main,
format: "es",
inlineDynamicImports: true,
plugins: [pretty()]
},
{
file: "app/assets/javascripts/turbo_power.min.js",
format: "es",
inlineDynamicImports: true,
sourcemap: true,
plugins: [minify()]
}
]

export default [
{
external: ["@hotwired/turbo"],
input: packageInfo.module,
output,
plugins: [resolve()]
}
]
Loading