cssbundling-rails 1.1.2 → 1.3.0
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 +4 -4
- data/README.md +9 -3
- data/lib/cssbundling/version.rb +1 -1
- data/lib/install/Procfile_for_bun.dev +2 -0
- data/lib/install/Procfile_for_node.dev +2 -0
- data/lib/install/bootstrap/install.rb +15 -14
- data/lib/install/bulma/install.rb +6 -13
- data/lib/install/dev +3 -0
- data/lib/install/helpers.rb +42 -0
- data/lib/install/install.rb +5 -2
- data/lib/install/postcss/install.rb +6 -13
- data/lib/install/postcss/postcss.config.js +1 -0
- data/lib/install/sass/install.rb +6 -13
- data/lib/install/tailwind/install.rb +6 -13
- data/lib/tasks/cssbundling/build.rake +39 -9
- data/lib/tasks/cssbundling/clobber.rake +1 -1
- metadata +6 -4
- data/lib/install/Procfile.dev +0 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80c2c969114694a1020f70a4f5025ddaaddd9814c802646e768631942a1adbdf
|
4
|
+
data.tar.gz: d5a828cf779270bf0f05257fcc2e9ee33fbbae7b23e5f668bcad26779a0131f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a42545bdef51ea41c6c386067a643a84c862fe996b0f1d519891ada561db3ad067796a66172ee628bcfc993540644529dfda0c6b938410a121d727c04e111ada
|
7
|
+
data.tar.gz: 1ed4b170f44f51e8db2d04e7d963702bacef1eab17099eac42a9df6166f1aa4ad480b60caa11437973e219ab1c35c3a6292eb08252db42ccf26c88ddc08ac4bb
|
data/README.md
CHANGED
@@ -8,9 +8,7 @@ Whenever the bundler detects changes to any of the stylesheet files in your proj
|
|
8
8
|
|
9
9
|
When you deploy your application to production, the `css:build` task attaches to the `assets:precompile` task to ensure that all your package dependencies from `package.json` have been installed via yarn, and then runs `yarn build:css` to process your stylesheet entrypoint, as it would in development. This output is then picked up by the asset pipeline, digested, and copied into public/assets, as any other asset pipeline file.
|
10
10
|
|
11
|
-
This also happens in testing where the bundler attaches to the `test:prepare` task to ensure the stylesheets have been bundled before testing commences.
|
12
|
-
|
13
|
-
If your test framework does not define a `test:prepare` Rake task, ensure that your test framework runs `css:build` to bundle stylesheets before testing commences. If your setup uses [jsbundling-rails](https://github.com/rails/jsbundling-rails) (ie, esbuild + tailwind), you will also need to run `javascript:build`.
|
11
|
+
This also happens in testing where the bundler attaches to the `test:prepare` task to ensure the stylesheets have been bundled before testing commences. If your test framework does not call the `test:prepare` Rake task, ensure that your test framework runs `css:build` to bundle stylesheets before testing commences. If your setup uses [jsbundling-rails](https://github.com/rails/jsbundling-rails) (ie, esbuild + tailwind), you will also need to run `javascript:build`.
|
14
12
|
|
15
13
|
That's it!
|
16
14
|
|
@@ -45,6 +43,14 @@ Some CSS packages use new CSS features that are not supported by the default Sas
|
|
45
43
|
|
46
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.
|
47
45
|
|
46
|
+
### Why isn't Rails using my updated css files?
|
47
|
+
|
48
|
+
Watch out - if you precompile your files locally, those will be served over the dynamically created ones you expect. The solution:
|
49
|
+
|
50
|
+
```shell
|
51
|
+
rails assets:clobber
|
52
|
+
```
|
53
|
+
|
48
54
|
## License
|
49
55
|
|
50
56
|
CSS Bundling for Rails is released under the [MIT License](https://opensource.org/licenses/MIT).
|
data/lib/cssbundling/version.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
|
-
|
1
|
+
require_relative "../helpers"
|
2
|
+
self.extend Helpers
|
3
|
+
|
4
|
+
say "Install Bootstrap with Bootstrap Icons, Popperjs/core and Autoprefixer"
|
2
5
|
copy_file "#{__dir__}/application.bootstrap.scss",
|
3
6
|
"app/assets/stylesheets/application.bootstrap.scss"
|
4
|
-
run "
|
7
|
+
run "#{bundler_cmd} add sass bootstrap bootstrap-icons @popperjs/core postcss postcss-cli autoprefixer nodemon"
|
5
8
|
|
6
9
|
inject_into_file "config/initializers/assets.rb", after: /.*Rails.application.config.assets.paths.*\n/ do
|
7
10
|
<<~RUBY
|
@@ -16,16 +19,14 @@ else
|
|
16
19
|
say %(Add import * as bootstrap from "bootstrap" to your entry point JavaScript file), :red
|
17
20
|
end
|
18
21
|
|
19
|
-
|
20
|
-
|
22
|
+
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")
|
23
|
+
add_package_json_script("build:css:prefix", "postcss ./app/assets/builds/application.css --use=autoprefixer --output=./app/assets/builds/application.css")
|
24
|
+
add_package_json_script("build:css", "#{bundler_run_cmd} build:css:compile && #{bundler_run_cmd} build:css:prefix")
|
25
|
+
add_package_json_script("watch:css", "nodemon --watch ./app/assets/stylesheets/ --ext scss --exec \"#{bundler_run_cmd} build:css\"", false)
|
21
26
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
run %(yarn build:css)
|
29
|
-
else
|
30
|
-
say %(Add "scripts": { "build:css": "#{build_script}" } to your package.json), :green
|
31
|
-
end
|
27
|
+
gsub_file "Procfile.dev", "build:css --watch", "watch:css"
|
28
|
+
|
29
|
+
package_json = JSON.parse(File.read("package.json"))
|
30
|
+
package_json["browserslist"] ||= {}
|
31
|
+
package_json["browserslist"] = ["defaults"]
|
32
|
+
File.write("package.json", JSON.pretty_generate(package_json))
|
@@ -1,18 +1,11 @@
|
|
1
|
+
require_relative "../helpers"
|
2
|
+
self.extend Helpers
|
3
|
+
|
1
4
|
say "Install Bulma"
|
2
5
|
copy_file "#{__dir__}/application.bulma.scss",
|
3
6
|
"app/assets/stylesheets/application.bulma.scss"
|
4
|
-
run "
|
7
|
+
run "#{bundler_cmd} add sass bulma"
|
5
8
|
|
6
9
|
say "Add build:css script"
|
7
|
-
|
8
|
-
|
9
|
-
case `npx -v`.to_f
|
10
|
-
when 7.1...8.0
|
11
|
-
run %(npm set-script build:css "#{build_script}")
|
12
|
-
run %(yarn build:css)
|
13
|
-
when (8.0..)
|
14
|
-
run %(npm pkg set scripts.build:css="#{build_script}")
|
15
|
-
run %(yarn build:css)
|
16
|
-
else
|
17
|
-
say %(Add "scripts": { "build:css": "#{build_script}" } to your package.json), :green
|
18
|
-
end
|
10
|
+
add_package_json_script "build:css",
|
11
|
+
"sass ./app/assets/stylesheets/application.bulma.scss:./app/assets/builds/application.css --no-source-map --load-path=node_modules"
|
data/lib/install/dev
CHANGED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module Helpers
|
4
|
+
def bundler_cmd
|
5
|
+
using_bun? ? "bun" : "yarn"
|
6
|
+
end
|
7
|
+
|
8
|
+
def bundler_run_cmd
|
9
|
+
using_bun? ? "bun run" : "yarn"
|
10
|
+
end
|
11
|
+
|
12
|
+
def using_bun?
|
13
|
+
File.exist?('bun.lockb') || (tool_exists?('bun') && !File.exist?('yarn.lock'))
|
14
|
+
end
|
15
|
+
|
16
|
+
def tool_exists?(tool)
|
17
|
+
system "command -v #{tool} > /dev/null"
|
18
|
+
end
|
19
|
+
|
20
|
+
def add_package_json_script(name, script, run_script=true)
|
21
|
+
if using_bun?
|
22
|
+
package_json = JSON.parse(File.read("package.json"))
|
23
|
+
package_json["scripts"] ||= {}
|
24
|
+
package_json["scripts"][name] = script
|
25
|
+
File.write("package.json", JSON.pretty_generate(package_json))
|
26
|
+
run %(bun run #{name}) if run_script
|
27
|
+
else
|
28
|
+
case `npx -v`.to_f
|
29
|
+
when 7.1...8.0
|
30
|
+
say "Add #{name} script"
|
31
|
+
run %(npm set-script #{name} "#{script}")
|
32
|
+
run %(yarn #{name}) if run_script
|
33
|
+
when (8.0..)
|
34
|
+
say "Add #{name} script"
|
35
|
+
run %(npm pkg set scripts.#{name}="#{script}")
|
36
|
+
run %(yarn #{name}) if run_script
|
37
|
+
else
|
38
|
+
say %(Add "scripts": { "#{name}": "#{script}" } to your package.json), :green
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/install/install.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
require_relative "helpers"
|
2
|
+
self.extend Helpers
|
3
|
+
|
1
4
|
say "Build into app/assets/builds"
|
2
5
|
empty_directory "app/assets/builds"
|
3
6
|
keep_file "app/assets/builds"
|
@@ -41,10 +44,10 @@ unless Rails.root.join("package.json").exist?
|
|
41
44
|
end
|
42
45
|
|
43
46
|
if Rails.root.join("Procfile.dev").exist?
|
44
|
-
append_to_file "Procfile.dev", "css:
|
47
|
+
append_to_file "Procfile.dev", "css: #{bundler_run_cmd} build:css --watch\n"
|
45
48
|
else
|
46
49
|
say "Add default Procfile.dev"
|
47
|
-
copy_file "#{__dir__}
|
50
|
+
copy_file "#{__dir__}/#{using_bun? ? "Procfile_for_bun" : "Procfile_for_node"}", "Procfile.dev"
|
48
51
|
|
49
52
|
say "Ensure foreman is installed"
|
50
53
|
run "gem install foreman"
|
@@ -1,18 +1,11 @@
|
|
1
|
+
require_relative "../helpers"
|
2
|
+
self.extend Helpers
|
3
|
+
|
1
4
|
say "Install PostCSS w/ nesting and autoprefixer"
|
2
5
|
copy_file "#{__dir__}/postcss.config.js", "postcss.config.js"
|
3
6
|
copy_file "#{__dir__}/application.postcss.css", "app/assets/stylesheets/application.postcss.css"
|
4
|
-
run "
|
7
|
+
run "#{bundler_cmd} add postcss postcss-cli postcss-import postcss-nesting autoprefixer"
|
5
8
|
|
6
9
|
say "Add build:css script"
|
7
|
-
|
8
|
-
|
9
|
-
case `npx -v`.to_f
|
10
|
-
when 7.1...8.0
|
11
|
-
run %(npm set-script build:css "#{build_script}")
|
12
|
-
run %(yarn build:css)
|
13
|
-
when (8.0..)
|
14
|
-
run %(npm pkg set scripts.build:css="#{build_script}")
|
15
|
-
run %(yarn build:css)
|
16
|
-
else
|
17
|
-
say %(Add "scripts": { "build:css": "#{build_script}" } to your package.json), :green
|
18
|
-
end
|
10
|
+
add_package_json_script "build:css",
|
11
|
+
"postcss ./app/assets/stylesheets/application.postcss.css -o ./app/assets/builds/application.css"
|
data/lib/install/sass/install.rb
CHANGED
@@ -1,17 +1,10 @@
|
|
1
|
+
require_relative "../helpers"
|
2
|
+
self.extend Helpers
|
3
|
+
|
1
4
|
say "Install Sass"
|
2
5
|
copy_file "#{__dir__}/application.sass.scss", "app/assets/stylesheets/application.sass.scss"
|
3
|
-
run "
|
6
|
+
run "#{bundler_cmd} add sass"
|
4
7
|
|
5
8
|
say "Add build:css script"
|
6
|
-
|
7
|
-
|
8
|
-
case `npx -v`.to_f
|
9
|
-
when 7.1...8.0
|
10
|
-
run %(npm set-script build:css "#{build_script}")
|
11
|
-
run %(yarn build:css)
|
12
|
-
when (8.0..)
|
13
|
-
run %(npm pkg set scripts.build:css="#{build_script}")
|
14
|
-
run %(yarn build:css)
|
15
|
-
else
|
16
|
-
say %(Add "scripts": { "build:css": "#{build_script}" } to your package.json), :green
|
17
|
-
end
|
9
|
+
add_package_json_script "build:css",
|
10
|
+
"sass ./app/assets/stylesheets/application.sass.scss:./app/assets/builds/application.css --no-source-map --load-path=node_modules"
|
@@ -1,18 +1,11 @@
|
|
1
|
+
require_relative "../helpers"
|
2
|
+
self.extend Helpers
|
3
|
+
|
1
4
|
say "Install Tailwind (+PostCSS w/ autoprefixer)"
|
2
5
|
copy_file "#{__dir__}/tailwind.config.js", "tailwind.config.js"
|
3
6
|
copy_file "#{__dir__}/application.tailwind.css", "app/assets/stylesheets/application.tailwind.css"
|
4
|
-
run "
|
7
|
+
run "#{bundler_cmd} add tailwindcss@latest postcss@latest autoprefixer@latest"
|
5
8
|
|
6
9
|
say "Add build:css script"
|
7
|
-
|
8
|
-
|
9
|
-
case `npx -v`.to_f
|
10
|
-
when 7.1...8.0
|
11
|
-
run %(npm set-script build:css "#{build_script}")
|
12
|
-
run %(yarn build:css)
|
13
|
-
when (8.0..)
|
14
|
-
run %(npm pkg set scripts.build:css="#{build_script}")
|
15
|
-
run %(yarn build:css)
|
16
|
-
else
|
17
|
-
say %(Add "scripts": { "build:css": "#{build_script}" } to your package.json), :green
|
18
|
-
end
|
10
|
+
add_package_json_script "build:css",
|
11
|
+
"tailwindcss -i ./app/assets/stylesheets/application.tailwind.css -o ./app/assets/builds/application.css --minify"
|
@@ -1,18 +1,48 @@
|
|
1
1
|
namespace :css do
|
2
|
+
desc "Install JavaScript dependencies"
|
3
|
+
task :install do
|
4
|
+
command = install_command
|
5
|
+
unless system(command)
|
6
|
+
raise "cssbundling-rails: Command install failed, ensure #{command.split.first} is installed"
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
2
10
|
desc "Build your CSS bundle"
|
3
|
-
task :build do
|
4
|
-
|
5
|
-
|
11
|
+
build_task = task :build do
|
12
|
+
command = build_command
|
13
|
+
unless system(command)
|
14
|
+
raise "cssbundling-rails: Command build failed, ensure `#{command}` runs without errors"
|
6
15
|
end
|
7
16
|
end
|
17
|
+
build_task.prereqs << :install unless ENV["SKIP_YARN_INSTALL"] || ENV["SKIP_BUN_INSTALL"]
|
18
|
+
end
|
19
|
+
|
20
|
+
def install_command
|
21
|
+
return "bun install" if File.exist?('bun.lockb') || (tool_exists?('bun') && !File.exist?('yarn.lock'))
|
22
|
+
return "yarn install" if File.exist?('yarn.lock') || tool_exists?('yarn')
|
23
|
+
raise "cssbundling-rails: No suitable tool found for installing JavaScript dependencies"
|
8
24
|
end
|
9
25
|
|
10
|
-
|
11
|
-
|
26
|
+
def build_command
|
27
|
+
return "bun run build:css" if File.exist?('bun.lockb') || (tool_exists?('bun') && !File.exist?('yarn.lock'))
|
28
|
+
return "yarn build:css" if File.exist?('yarn.lock') || tool_exists?('yarn')
|
29
|
+
raise "cssbundling-rails: No suitable tool found for building CSS"
|
12
30
|
end
|
13
31
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
32
|
+
def tool_exists?(tool)
|
33
|
+
system "command -v #{tool} > /dev/null"
|
34
|
+
end
|
35
|
+
|
36
|
+
unless ENV["SKIP_CSS_BUILD"]
|
37
|
+
if Rake::Task.task_defined?("assets:precompile")
|
38
|
+
Rake::Task["assets:precompile"].enhance(["css:build"])
|
39
|
+
end
|
40
|
+
|
41
|
+
if Rake::Task.task_defined?("test:prepare")
|
42
|
+
Rake::Task["test:prepare"].enhance(["css:build"])
|
43
|
+
elsif Rake::Task.task_defined?("spec:prepare")
|
44
|
+
Rake::Task["spec:prepare"].enhance(["css:build"])
|
45
|
+
elsif Rake::Task.task_defined?("db:test:prepare")
|
46
|
+
Rake::Task["db:test:prepare"].enhance(["css:build"])
|
47
|
+
end
|
18
48
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cssbundling-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Heinemeier Hansson
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2023-09-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: railties
|
@@ -36,12 +36,14 @@ files:
|
|
36
36
|
- lib/cssbundling-rails.rb
|
37
37
|
- lib/cssbundling/engine.rb
|
38
38
|
- lib/cssbundling/version.rb
|
39
|
-
- lib/install/
|
39
|
+
- lib/install/Procfile_for_bun.dev
|
40
|
+
- lib/install/Procfile_for_node.dev
|
40
41
|
- lib/install/bootstrap/application.bootstrap.scss
|
41
42
|
- lib/install/bootstrap/install.rb
|
42
43
|
- lib/install/bulma/application.bulma.scss
|
43
44
|
- lib/install/bulma/install.rb
|
44
45
|
- lib/install/dev
|
46
|
+
- lib/install/helpers.rb
|
45
47
|
- lib/install/install.rb
|
46
48
|
- lib/install/package.json
|
47
49
|
- lib/install/postcss/application.postcss.css
|
@@ -75,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
77
|
- !ruby/object:Gem::Version
|
76
78
|
version: '0'
|
77
79
|
requirements: []
|
78
|
-
rubygems_version: 3.
|
80
|
+
rubygems_version: 3.4.10
|
79
81
|
signing_key:
|
80
82
|
specification_version: 4
|
81
83
|
summary: Bundle and process CSS with Tailwind, Bootstrap, PostCSS, Sass in Rails via
|
data/lib/install/Procfile.dev
DELETED