cssbundling-rails 0.1.1 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -5
- data/lib/cssbundling/version.rb +1 -1
- data/lib/install/Procfile.dev +2 -0
- data/lib/install/bootstrap/application.bootstrap.scss +1 -0
- data/lib/install/bootstrap/install.rb +14 -0
- data/lib/install/dev +3 -0
- data/lib/install/install.rb +18 -1
- data/lib/install/sass/install.rb +1 -1
- data/lib/tasks/cssbundling/build.rake +1 -1
- data/lib/tasks/cssbundling/install.rake +5 -0
- metadata +23 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe36ff64ebb7a3e45b17d6ce9b8f17646f553688ddfc2394c2b6afa266381bb0
|
4
|
+
data.tar.gz: e76290b4d74b34c56bd3c8ade7758a9b8108ee64da63b047d3a284357a9b1d1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c122aae327a208eb707a291852d96fea430939cea9ad7a1dae182f03efb1f9201c0b2a917e93159c114e7a4e544b10c8faf8f4b8b5b506524d7ef07a405270f
|
7
|
+
data.tar.gz: 5378466b5910acf675be8499cddcb7cb37c39531d4dbc71be6004066ef285438331405faf77c89573f8024f33d3cdcb29d9edcdf0d834a2a5df8db845d4333e9
|
data/README.md
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
# CSS Bundling for Rails
|
2
2
|
|
3
|
-
Use [Tailwind CSS](https://tailwindcss.com), [PostCSS](https://postcss.org), or [Dart Sass](https://sass-lang.com/) to bundle and process your CSS, then deliver it via the asset pipeline in Rails. This gem provides installers to get you going with the bundler of your choice in a new Rails application, and a convention to use `app/assets/builds` to hold your bundled output as artifacts that are not checked into source control (the installer adds this directory to `.gitignore` by default).
|
3
|
+
Use [Tailwind CSS](https://tailwindcss.com), [Bootstrap](https://getbootstrap.com/), [PostCSS](https://postcss.org), or [Dart Sass](https://sass-lang.com/) to bundle and process your CSS, then deliver it via the asset pipeline in Rails. This gem provides installers to get you going with the bundler of your choice in a new Rails application, and a convention to use `app/assets/builds` to hold your bundled output as artifacts that are not checked into source control (the installer adds this directory to `.gitignore` by default).
|
4
4
|
|
5
|
-
You develop using this approach by running the bundler in watch mode in a terminal with `yarn build:css --watch` (and your Rails server in another, if you're not using something like [puma-dev](https://github.com/puma/puma-dev)). Whenever the bundler detects changes to any of the stylesheet files in your project, it'll bundle `app/assets/stylesheets/application.[bundler].css` into `app/assets/builds/application.css`. This build output takes over from the regular asset pipeline default file. So you continue to refer to the build output in your layout using the standard asset pipeline approach with `<%=
|
5
|
+
You develop using this approach by running the bundler in watch mode in a terminal with `yarn build:css --watch` (and your Rails server in another, if you're not using something like [puma-dev](https://github.com/puma/puma-dev)). Whenever the bundler detects changes to any of the stylesheet files in your project, it'll bundle `app/assets/stylesheets/application.[bundler].css` into `app/assets/builds/application.css`. This build output takes over from the regular asset pipeline default file. So you continue to refer to the build output in your layout using the standard asset pipeline approach with `<%= stylesheet_link_tag "application" %>`.
|
6
6
|
|
7
7
|
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.
|
8
8
|
|
9
9
|
This also happens in testing where the bundler attaches to the `test:prepare` task to ensure the stylesheets have been bundled before testing commences. (Note that this currently only applies to rails `test:*` tasks (like `test:all` or `test:controllers`), not "rails test", as that doesn't load `test:prepare`).
|
10
10
|
|
11
|
+
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.
|
12
|
+
|
11
13
|
That's it!
|
12
14
|
|
13
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.
|
@@ -15,13 +17,13 @@ You can configure your bundler options in the `build:css` script in `package.jso
|
|
15
17
|
|
16
18
|
## Installation
|
17
19
|
|
18
|
-
You must already have node and yarn installed on your system. Then:
|
20
|
+
You must already have node and yarn installed on your system. You will also need npx version 7.1.0 or later. Then:
|
19
21
|
|
20
22
|
1. Add `cssbundling-rails` to your Gemfile with `gem 'cssbundling-rails'`
|
21
23
|
2. Run `./bin/bundle install`
|
22
|
-
3. Run `./bin/rails css:install:[tailwind|postcss|sass]`
|
24
|
+
3. Run `./bin/rails css:install:[tailwind|bootstrap|postcss|sass]`
|
23
25
|
|
24
|
-
Or, in Rails 7+, you can preconfigure your new application to use a specific bundler with `rails new myapp --css [tailwind|postcss|sass]`.
|
26
|
+
Or, in Rails 7+, you can preconfigure your new application to use a specific bundler with `rails new myapp --css [tailwind|bootstrap|postcss|sass]`.
|
25
27
|
|
26
28
|
|
27
29
|
## License
|
data/lib/cssbundling/version.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
@import 'bootstrap/scss/bootstrap';
|
@@ -0,0 +1,14 @@
|
|
1
|
+
say "Install Bootstrap with Popperjs/core"
|
2
|
+
copy_file "#{__dir__}/application.bootstrap.scss",
|
3
|
+
"app/assets/stylesheets/application.bootstrap.scss"
|
4
|
+
run "yarn add sass bootstrap @popperjs/core"
|
5
|
+
|
6
|
+
if Rails.root.join("app/javascript/application.js").exist?
|
7
|
+
say "Appending Bootstrap JavaScript import to default entry point"
|
8
|
+
append_to_file "app/javascript/application.js", %(import * as bootstrap from "bootstrap"\n)
|
9
|
+
else
|
10
|
+
say %(Add import * as bootstrap from "bootstrap" to your entry point JavaScript file), :red
|
11
|
+
end
|
12
|
+
|
13
|
+
say "Add build:css script"
|
14
|
+
run %(npm set-script build:css "sass ./app/assets/stylesheets/application.bootstrap.scss ./app/assets/builds/application.css --no-source-map --load-path=node_modules")
|
data/lib/install/dev
ADDED
data/lib/install/install.rb
CHANGED
@@ -3,8 +3,11 @@ empty_directory "app/assets/builds"
|
|
3
3
|
keep_file "app/assets/builds"
|
4
4
|
append_to_file "app/assets/config/manifest.js", %(//= link_tree ../builds\n)
|
5
5
|
|
6
|
+
say "Stop linking stylesheets automatically"
|
7
|
+
gsub_file "app/assets/config/manifest.js", "//= link_directory ../stylesheets .css", ""
|
8
|
+
|
6
9
|
if Rails.root.join(".gitignore").exist?
|
7
|
-
append_to_file(".gitignore", %(/app/assets/builds\n))
|
10
|
+
append_to_file(".gitignore", %(/app/assets/builds\n!/app/assets/builds/.keep\n))
|
8
11
|
end
|
9
12
|
|
10
13
|
say "Remove app/assets/stylesheets/application.css so build output can take over"
|
@@ -14,3 +17,17 @@ unless Rails.root.join("package.json").exist?
|
|
14
17
|
say "Add default package.json"
|
15
18
|
copy_file "#{__dir__}/package.json", "package.json"
|
16
19
|
end
|
20
|
+
|
21
|
+
if Rails.root.join("Procfile.dev").exist?
|
22
|
+
append_to_file "Procfile.dev", "css: yarn build:css --watch"
|
23
|
+
else
|
24
|
+
say "Add default Procfile.dev"
|
25
|
+
copy_file "#{__dir__}/Procfile.dev", "Procfile.dev"
|
26
|
+
|
27
|
+
say "Ensure foreman is install"
|
28
|
+
run "gem install foreman"
|
29
|
+
end
|
30
|
+
|
31
|
+
say "Add bin/dev to start foreman"
|
32
|
+
copy_file "#{__dir__}/dev", "bin/dev"
|
33
|
+
chmod "bin/dev", 0755, verbose: false
|
data/lib/install/sass/install.rb
CHANGED
@@ -3,4 +3,4 @@ copy_file "#{__dir__}/application.sass.scss", "app/assets/stylesheets/applicatio
|
|
3
3
|
run "yarn add sass"
|
4
4
|
|
5
5
|
say "Add build:css script"
|
6
|
-
run %(npm set-script build:css "sass ./app/assets/stylesheets/application.sass.scss ./app/assets/builds/application.css --no-source-map")
|
6
|
+
run %(npm set-script build:css "sass ./app/assets/stylesheets/application.sass.scss ./app/assets/builds/application.css --no-source-map --load-path=node_modules")
|
@@ -19,5 +19,10 @@ namespace :css do
|
|
19
19
|
task sass: "css:install:shared" do
|
20
20
|
system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../../install/sass/install.rb", __dir__)}"
|
21
21
|
end
|
22
|
+
|
23
|
+
desc "Install Bootstrap"
|
24
|
+
task bootstrap: "css:install:shared" do
|
25
|
+
system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../../install/bootstrap/install.rb", __dir__)}"
|
26
|
+
end
|
22
27
|
end
|
23
28
|
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: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Heinemeier Hansson
|
@@ -9,10 +9,10 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-09-
|
12
|
+
date: 2021-09-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
15
|
+
name: railties
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
18
|
- - ">="
|
@@ -25,6 +25,20 @@ dependencies:
|
|
25
25
|
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: 6.0.0
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: sprockets-rails
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 2.0.0
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 2.0.0
|
28
42
|
description:
|
29
43
|
email: david@loudthinking.com
|
30
44
|
executables: []
|
@@ -36,6 +50,10 @@ files:
|
|
36
50
|
- lib/cssbundling-rails.rb
|
37
51
|
- lib/cssbundling/engine.rb
|
38
52
|
- lib/cssbundling/version.rb
|
53
|
+
- lib/install/Procfile.dev
|
54
|
+
- lib/install/bootstrap/application.bootstrap.scss
|
55
|
+
- lib/install/bootstrap/install.rb
|
56
|
+
- lib/install/dev
|
39
57
|
- lib/install/install.rb
|
40
58
|
- lib/install/package.json
|
41
59
|
- lib/install/postcss/application.postcss.css
|
@@ -71,5 +89,6 @@ requirements: []
|
|
71
89
|
rubygems_version: 3.1.4
|
72
90
|
signing_key:
|
73
91
|
specification_version: 4
|
74
|
-
summary: Bundle and process CSS with Tailwind, PostCSS,
|
92
|
+
summary: Bundle and process CSS with Tailwind, Bootstrap, PostCSS, Sass in Rails via
|
93
|
+
Node.js.
|
75
94
|
test_files: []
|