cssbundling-rails 1.4.1 → 1.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a644c7ba1cafbe1174c0c1fec2cbc9b545e1fc9e620d9c9e348c9cd58f2477a9
4
- data.tar.gz: 756402251b7446a021598edcbd26b24fd6e89be36aeeb0f42592febabe5d336a
3
+ metadata.gz: 319fde756ef3f014dc55f2e3c826e8420d7a294c1284b7858d7195f4df3263f2
4
+ data.tar.gz: 22855d55faabba57015601f580c548eef162d8ff34f364ea0290bd46c2c04b86
5
5
  SHA512:
6
- metadata.gz: 63e4c7932449cf676e20d0f3d6510c653ecf1e90aa1fdabae9a5f43b4edb41ee6e8697ce12cff1b1debd2a0d410356ffeec141fe1032b2015edb689e1c6a8920
7
- data.tar.gz: b0abcc8f73a13d588066195646989b2218c5a7bd3d9d85344ae1802136ddfa3f660eca75af03835f5af4f75f0c9ea87d026dbbd99efbc4a1b12104d374d6689a
6
+ metadata.gz: 88081e41b62f0e7b58f729d82f865d7b1557c1628de598aa2f96327d4be0277720e5c79a4657ac52f7b9a833d4ef78c9896d392cebe12b37024be2dccb4be4f3
7
+ data.tar.gz: 22ce728830cd4be3ad30cba5d9066b9dfba630dfa21aa677959a28e2d86999efd7996898d88e62af9e904de3c312da1bc4368ca0b97137c637fa8ac5cb9a19e8
data/README.md CHANGED
@@ -12,8 +12,7 @@ This also happens in testing where the bundler attaches to the `test:prepare` ta
12
12
 
13
13
  That's it!
14
14
 
15
- You can configure your bundler options in the `build:css` script in `package.json` or via the installer-generated `tailwind.config.js` for Tailwind or `postcss.config.js` for PostCSS.
16
-
15
+ You can configure your bundler options in the `build:css` script in `package.json` or `postcss.config.js` for PostCSS.
17
16
 
18
17
  ## Installation
19
18
 
@@ -22,8 +21,7 @@ You must already have node and yarn installed on your system. You will also need
22
21
  1. Run `./bin/bundle add cssbundling-rails`
23
22
  2. Run `./bin/rails css:install:[tailwind|bootstrap|bulma|postcss|sass]`
24
23
 
25
- Or, in Rails 7+, you can preconfigure your new application to use a specific bundler with `rails new myapp --css [tailwind|bootstrap|bulma|postcss|sass]`.
26
-
24
+ Or, in Rails 7+, you can preconfigure your new application to use `cssbundling-rails` for `bootstrap`, `bulma` or `postcss` with `rails new myapp --css [bootstrap|bulma|postcss]`.
27
25
 
28
26
  ## FAQ
29
27
 
@@ -31,9 +29,17 @@ Or, in Rails 7+, you can preconfigure your new application to use a specific bun
31
29
 
32
30
  If you're already relying on Node to process your JavaScript, this gem is the way to go. But if you're using [the default import map setup in Rails 7+](https://github.com/rails/importmap-rails/), you can avoid having to deal with Node at all by using the standalone versions of Tailwind CSS and Dart Sass that are available through [tailwindcss-rails](https://github.com/rails/tailwindcss-rails/) and [dartsass-rails](https://github.com/rails/dartsass-rails/). It's simpler, fewer moving parts, and still has all the functionality.
33
31
 
32
+ In Rails 7+, you can preconfigure your new application to use `tailwindcss-rails` and `dartsass-rails` with `rails new myapp --css [tailwind|sass]`.
33
+
34
34
  ### How do I import relative CSS files with Tailwind?
35
35
 
36
- If you want to use `@import` statements as part of your Tailwind application.js file, you need to [configure Tailwind to use `postcss` and then `postcss-import`](https://tailwindcss.com/docs/using-with-preprocessors#build-time-imports). But you should also consider simply referring to your other CSS files directly, instead of bundling them all into one big file. It's better for caching, and it's simpler to setup. You can refer to other CSS files by expanding the `stylesheet_link_tag` in `application.html.erb` like so: `<%= stylesheet_link_tag "application", "other", "styles", "data-turbo-track": "reload" %>`.
36
+ Tailwind CSS 4 is configured using native CSS. Instead of bundling all your CSS into a single file, consider referencing individual CSS files directly. This approach simplifies setup and improves caching performance. To reference multiple CSS files in Rails, update the stylesheet_link_tag in application.html.erb like this:
37
+
38
+ ```erb
39
+ <%= stylesheet_link_tag "application", "other", "styles", "data-turbo-track": "reload" %>
40
+ ```
41
+
42
+ This ensures your files are properly linked and ready to use.
37
43
 
38
44
  ### How do I avoid SassC::SyntaxError exceptions on existing projects?
39
45
 
@@ -41,7 +47,7 @@ Some CSS packages use new CSS features that are not supported by the default Sas
41
47
 
42
48
  ### Why do I get `application.css not in asset pipeline` in production?
43
49
 
44
- A common issue is that your repository does not contain the output directory used by the build commands. You must have `app/assets/builds` available. Add the directory with a `.gitkeep` file, and you'll ensure it's available in production.
50
+ A common issue is that your repository does not contain the output directory used by the build commands. You must have `app/assets/builds` available. Add the directory with a `.keep` file, and you'll ensure it's available in production.
45
51
 
46
52
  ### How do I avoid `ActionView::Template::Error: Error: Function rgb is missing argument $green`?
47
53
 
@@ -57,7 +63,7 @@ Rails.application.config.assets.css_compressor = nil
57
63
  Watch out - if you precompile your files locally, those will be served over the dynamically created ones you expect. The solution:
58
64
 
59
65
  ```shell
60
- rails assets:clobber
66
+ rails assets:clobber
61
67
  ```
62
68
 
63
69
  ### How do I include 3rd party stylesheets from `node_modules` in my bundle?
@@ -1,3 +1,3 @@
1
1
  module Cssbundling
2
- VERSION = "1.4.1"
2
+ VERSION = "1.4.3"
3
3
  end
@@ -23,15 +23,15 @@ end
23
23
 
24
24
  if Rails.root.join("config/importmap.rb").exist?
25
25
  say "Pin Bootstrap"
26
- append_to_file "config/importmap.rb", %(pin "bootstrap", to: "bootstrap.min.js"\n)
26
+ append_to_file "config/importmap.rb", %(pin "bootstrap", to: "bootstrap.bundle.min.js"\n)
27
27
 
28
- inject_into_file "config/initializers/assets.rb", after: /.*Rails.application.config.assets.paths.*\n/ do
28
+ inject_into_file "config/initializers/assets.rb", after: /.*\/bootstrap-icons\/font.*\n/ do
29
29
  <<~RUBY
30
30
  Rails.application.config.assets.paths << Rails.root.join("node_modules/bootstrap/dist/js")
31
31
  RUBY
32
32
  end
33
33
 
34
- append_to_file "config/initializers/assets.rb", %(Rails.application.config.assets.precompile << "bootstrap.min.js")
34
+ append_to_file "config/initializers/assets.rb", %(Rails.application.config.assets.precompile << "bootstrap.bundle.min.js")
35
35
  end
36
36
 
37
37
  add_package_json_script("build:css:compile", "sass ./app/assets/stylesheets/application.bootstrap.scss:./app/assets/builds/application.css --no-source-map --load-path=node_modules")
@@ -9,8 +9,14 @@ module Helpers
9
9
  using_bun? ? "bun run" : "yarn"
10
10
  end
11
11
 
12
+ def bundler_x_cmd
13
+ using_bun? ? "bunx" : "npx"
14
+ end
15
+
12
16
  def using_bun?
13
- File.exist?('bun.lockb') || (tool_exists?('bun') && !File.exist?('yarn.lock'))
17
+ tool_exists?('bun') && (File.exist?('bun.lockb') ||
18
+ File.exist?('bun.lock') ||
19
+ File.exist?('yarn.lock'))
14
20
  end
15
21
 
16
22
  def tool_exists?(tool)
@@ -20,21 +20,23 @@ end
20
20
  say "Remove app/assets/stylesheets/application.css so build output can take over"
21
21
  remove_file "app/assets/stylesheets/application.css"
22
22
 
23
- if (app_layout_path = Rails.root.join("app/views/layouts/application.html.erb")).exist?
24
- say "Add stylesheet link tag in application layout"
25
- insert_into_file(
26
- app_layout_path.to_s,
27
- defined?(Turbo) ?
28
- %(\n <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>) :
29
- %(\n <%= stylesheet_link_tag "application" %>),
30
- before: /\s*<\/head>/
31
- )
32
- else
33
- say "Default application.html.erb is missing!", :red
34
- if defined?(Turbo)
35
- say %( Add <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %> within the <head> tag in your custom layout.)
23
+ if Rails::VERSION::MAJOR < 8
24
+ if (app_layout_path = Rails.root.join("app/views/layouts/application.html.erb")).exist?
25
+ say "Add stylesheet link tag in application layout"
26
+ insert_into_file(
27
+ app_layout_path.to_s,
28
+ defined?(Turbo) ?
29
+ %(\n <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>) :
30
+ %(\n <%= stylesheet_link_tag "application" %>),
31
+ before: /\s*<\/head>/
32
+ )
36
33
  else
37
- say %( Add <%= stylesheet_link_tag "application" %> within the <head> tag in your custom layout.)
34
+ say "Default application.html.erb is missing!", :red
35
+ if defined?(Turbo)
36
+ say %( Add <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %> within the <head> tag in your custom layout.)
37
+ else
38
+ say %( Add <%= stylesheet_link_tag "application" %> within the <head> tag in your custom layout.)
39
+ end
38
40
  end
39
41
  end
40
42
 
@@ -1,3 +1 @@
1
- @tailwind base;
2
- @tailwind components;
3
- @tailwind utilities;
1
+ @import "tailwindcss";
@@ -3,11 +3,10 @@ self.extend Helpers
3
3
 
4
4
  apply "#{__dir__}/../install.rb"
5
5
 
6
- say "Install Tailwind (+PostCSS w/ autoprefixer)"
7
- copy_file "#{__dir__}/tailwind.config.js", "tailwind.config.js"
6
+ say "Install Tailwind"
8
7
  copy_file "#{__dir__}/application.tailwind.css", "app/assets/stylesheets/application.tailwind.css"
9
- run "#{bundler_cmd} add tailwindcss@latest postcss@latest autoprefixer@latest"
8
+ run "#{bundler_cmd} add tailwindcss@latest @tailwindcss/cli@latest"
10
9
 
11
10
  say "Add build:css script"
12
11
  add_package_json_script "build:css",
13
- "tailwindcss -i ./app/assets/stylesheets/application.tailwind.css -o ./app/assets/builds/application.css --minify"
12
+ "#{bundler_x_cmd} @tailwindcss/cli -i ./app/assets/stylesheets/application.tailwind.css -o ./app/assets/builds/application.css --minify"
@@ -2,6 +2,6 @@
2
2
  "name": "app",
3
3
  "private": "true",
4
4
  "scripts": {
5
- "build:css": "tailwindcss -i ./app/assets/stylesheets/application.tailwind.css -o ./app/assets/builds/application.css"
5
+ "build:css": "npx @tailwindcss/cli -i ./app/assets/stylesheets/application.tailwind.css -o ./app/assets/builds/application.css"
6
6
  }
7
7
  }
@@ -1,5 +1,5 @@
1
1
  namespace :css do
2
- desc "Install JavaScript dependencies"
2
+ desc "Install CSS dependencies"
3
3
  task :install do
4
4
  command = Cssbundling::Tasks.install_command
5
5
  unless system(command)
@@ -21,42 +21,42 @@ module Cssbundling
21
21
  module Tasks
22
22
  extend self
23
23
 
24
+ LOCK_FILES = {
25
+ bun: %w[bun.lockb bun.lock yarn.lock],
26
+ yarn: %w[yarn.lock],
27
+ pnpm: %w[pnpm-lock.yaml],
28
+ npm: %w[package-lock.json]
29
+ }
30
+
24
31
  def install_command
25
- case tool
26
- when :bun then "bun install"
27
- when :yarn then "yarn install"
28
- when :pnpm then "pnpm install"
29
- when :npm then "npm install"
32
+ case
33
+ when using_tool?(:bun) then "bun install"
34
+ when using_tool?(:yarn) then "yarn install"
35
+ when using_tool?(:pnpm) then "pnpm install"
36
+ when using_tool?(:npm) then "npm install"
30
37
  else raise "cssbundling-rails: No suitable tool found for installing JavaScript dependencies"
31
38
  end
32
39
  end
33
40
 
34
41
  def build_command
35
- case tool
36
- when :bun then "bun run build:css"
37
- when :yarn then "yarn build:css"
38
- when :pnpm then "pnpm build:css"
39
- when :npm then "npm run build:css"
42
+ case
43
+ when using_tool?(:bun) then "bun run build:css"
44
+ when using_tool?(:yarn) then "yarn build:css"
45
+ when using_tool?(:pnpm) then "pnpm build:css"
46
+ when using_tool?(:npm) then "npm run build:css"
40
47
  else raise "cssbundling-rails: No suitable tool found for building CSS"
41
48
  end
42
49
  end
43
50
 
44
- def tool
45
- case
46
- when File.exist?('bun.lockb') then :bun
47
- when File.exist?('yarn.lock') then :yarn
48
- when File.exist?('pnpm-lock.yaml') then :pnpm
49
- when File.exist?('package-lock.json') then :npm
50
- when tool_exists?('bun') then :bun
51
- when tool_exists?('yarn') then :yarn
52
- when tool_exists?('pnpm') then :pnpm
53
- when tool_exists?('npm') then :npm
54
- end
55
- end
51
+ private
56
52
 
57
53
  def tool_exists?(tool)
58
54
  system "command -v #{tool} > /dev/null"
59
55
  end
56
+
57
+ def using_tool?(tool)
58
+ tool_exists?(tool) && LOCK_FILES[tool].any? { |file| File.exist?(file) }
59
+ end
60
60
  end
61
61
  end
62
62
 
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cssbundling-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
8
8
  - Dom Christie
9
- autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2024-07-29 00:00:00.000000000 Z
11
+ date: 2025-03-03 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: railties
@@ -25,7 +24,6 @@ dependencies:
25
24
  - - ">="
26
25
  - !ruby/object:Gem::Version
27
26
  version: 6.0.0
28
- description:
29
27
  email: david@loudthinking.com
30
28
  executables: []
31
29
  extensions: []
@@ -54,7 +52,6 @@ files:
54
52
  - lib/install/tailwind/application.tailwind.css
55
53
  - lib/install/tailwind/install.rb
56
54
  - lib/install/tailwind/package.json
57
- - lib/install/tailwind/tailwind.config.js
58
55
  - lib/tasks/cssbundling/build.rake
59
56
  - lib/tasks/cssbundling/clobber.rake
60
57
  - lib/tasks/cssbundling/install.rake
@@ -63,7 +60,6 @@ licenses:
63
60
  - MIT
64
61
  metadata:
65
62
  changelog_uri: https://github.com/rails/cssbundling-rails/releases
66
- post_install_message:
67
63
  rdoc_options: []
68
64
  require_paths:
69
65
  - lib
@@ -78,8 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
78
74
  - !ruby/object:Gem::Version
79
75
  version: '0'
80
76
  requirements: []
81
- rubygems_version: 3.5.11
82
- signing_key:
77
+ rubygems_version: 3.6.2
83
78
  specification_version: 4
84
79
  summary: Bundle and process CSS with Tailwind, Bootstrap, PostCSS, Sass in Rails via
85
80
  Node.js.
@@ -1,8 +0,0 @@
1
- module.exports = {
2
- content: [
3
- './app/views/**/*.html.erb',
4
- './app/helpers/**/*.rb',
5
- './app/assets/stylesheets/**/*.css',
6
- './app/javascript/**/*.js'
7
- ]
8
- }