cssbundling-rails 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 157a239ed259b5466360204b02cbe2b260f6bd1fe9357e7a8d190f24658f21e4
4
+ data.tar.gz: beaa568932183609d735427a7cb32f3bc8a54c468296eeb86bd09f1e101b9c76
5
+ SHA512:
6
+ metadata.gz: 50acd8f5b93b5f7be810b2fed9a563fc1a5526362985206865d3478e01b1f555e97018793c129f62835552475a929a22579eef2722e6eb0b77787ff99901e78e
7
+ data.tar.gz: b50e046ba8cef422ee3d7d404696e66dae05c341d1f7342f98d92d748cece0b81e9c6198dd096e89700334dbc49605b0c970de1c20b0c443d8178e5ec90ab2a9
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2021 David Heinemeier Hansson
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # CSS Bundling for Rails
2
+
3
+ Use [Tailwind CSS](https://tailwindcss.com), [PostCSS](https://postcss.org), or [Dart Sass](https://sass-lang.com/) to bundle and process your JavaScript, 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
+
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_include_tag "application" %>`.
6
+
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
+
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
+
11
+ That's it!
12
+
13
+ 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.
14
+
15
+
16
+ ## Installation
17
+
18
+ You must already have node and yarn installed on your system. Then:
19
+
20
+ 1. Add `cssbundling-rails` to your Gemfile with `gem 'cssbundling-rails'`
21
+ 2. Run `./bin/bundle install`
22
+ 3. Run `./bin/rails css:install:[tailwind|postcss|sass]`
23
+
24
+ Or, in Rails 7+, you can preconfigure your new application to use a specific bundler with `rails new myapp --css [tailwind|postcss|sass]`.
25
+
26
+
27
+ ## License
28
+
29
+ CSS Bundling for Rails is released under the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,4 @@
1
+ module Cssbundling
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module Cssbundling
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,5 @@
1
+ module Cssbundling
2
+ end
3
+
4
+ require "cssbundling/version"
5
+ require "cssbundling/engine"
@@ -0,0 +1,16 @@
1
+ say "Build into app/assets/builds"
2
+ empty_directory "app/assets/builds"
3
+ keep_file "app/assets/builds"
4
+ append_to_file "app/assets/config/manifest.js", %(//= link_tree ../builds\n)
5
+
6
+ if Rails.root.join(".gitignore").exist?
7
+ append_to_file(".gitignore", %(/app/assets/builds\n))
8
+ end
9
+
10
+ say "Remove app/assets/stylesheets/application.css so build output can take over"
11
+ remove_file "app/assets/stylesheets/application.css"
12
+
13
+ unless Rails.root.join("package.json").exist?
14
+ say "Add default package.json"
15
+ copy_file "#{__dir__}/package.json", "package.json"
16
+ end
@@ -0,0 +1,4 @@
1
+ {
2
+ "name": "app",
3
+ "private": "true"
4
+ }
@@ -0,0 +1 @@
1
+ /* Entry point for your PostCSS build */
@@ -0,0 +1,7 @@
1
+ say "Install PostCSS w/ postcss-preset-env"
2
+ copy_file "#{__dir__}/postcss.config.js", "postcss.config.js"
3
+ copy_file "#{__dir__}/application.postcss.css", "app/assets/stylesheets/application.postcss.css"
4
+ run "yarn add postcss postcss-cli postcss-preset-env"
5
+
6
+ say "Add build:css script"
7
+ run %(npm set-script build:css "postcss ./app/assets/stylesheets/application.postcss.css -o ./app/assets/builds/application.css")
@@ -0,0 +1,10 @@
1
+ module.exports = {
2
+ plugins: [
3
+ require('postcss-preset-env')({
4
+ stage: 2,
5
+ features: {
6
+ 'nesting-rules': true
7
+ }
8
+ })
9
+ ],
10
+ }
@@ -0,0 +1 @@
1
+ // Entry point for your Sass build
@@ -0,0 +1,6 @@
1
+ say "Install Sass"
2
+ copy_file "#{__dir__}/application.sass.scss", "app/assets/stylesheets/application.sass.scss"
3
+ run "yarn add sass"
4
+
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")
@@ -0,0 +1,3 @@
1
+ @tailwind base;
2
+ @tailwind components;
3
+ @tailwind utilities;
@@ -0,0 +1,7 @@
1
+ say "Install Tailwind (+PostCSS w/ autoprefixer)"
2
+ copy_file "#{__dir__}/tailwind.config.js", "tailwind.config.js"
3
+ copy_file "#{__dir__}/application.tailwind.css", "app/assets/stylesheets/application.tailwind.css"
4
+ run "yarn add tailwindcss@latest postcss@latest autoprefixer@latest"
5
+
6
+ say "Add build:css script"
7
+ run %(npm set-script build:css "tailwindcss -i ./app/assets/stylesheets/application.tailwind.css -o ./app/assets/builds/application.css")
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "app",
3
+ "private": "true",
4
+ "scripts": {
5
+ "build:css": "tailwindcss -i ./app/assets/stylesheets/application.tw.css -o ./app/assets/builds/application.css"
6
+ }
7
+ }
@@ -0,0 +1,8 @@
1
+ module.exports = {
2
+ mode: 'jit',
3
+ purge: [
4
+ './app/views/**/*.html.erb',
5
+ './app/helpers/**/*.rb',
6
+ './app/javascript/**/*.js'
7
+ ]
8
+ }
@@ -0,0 +1,9 @@
1
+ namespace :css do
2
+ desc "Build your CSS bundle"
3
+ task :build do
4
+ system "yarn install && yarn build:css"
5
+ end
6
+ end
7
+
8
+ Rake::Task["assets:precompile"].enhance(["css:build"])
9
+ Rake::Task["test:prepare"].enhance(["css:build"])
@@ -0,0 +1,23 @@
1
+ namespace :css do
2
+ namespace :install do
3
+ desc "Install shared elements for all bundlers"
4
+ task :shared do
5
+ system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../../install/install.rb", __dir__)}"
6
+ end
7
+
8
+ desc "Install Tailwind"
9
+ task tailwind: "css:install:shared" do
10
+ system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../../install/tailwind/install.rb", __dir__)}"
11
+ end
12
+
13
+ desc "Install PostCSS"
14
+ task postcss: "css:install:shared" do
15
+ system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../../install/postcss/install.rb", __dir__)}"
16
+ end
17
+
18
+ desc "Install Sass"
19
+ task sass: "css:install:shared" do
20
+ system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../../install/sass/install.rb", __dir__)}"
21
+ end
22
+ end
23
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cssbundling-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - David Heinemeier Hansson
8
+ - Dom Christie
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2021-09-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: 6.0.0
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: 6.0.0
28
+ description:
29
+ email: david@loudthinking.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - MIT-LICENSE
35
+ - README.md
36
+ - lib/cssbundling-rails.rb
37
+ - lib/cssbundling/engine.rb
38
+ - lib/cssbundling/version.rb
39
+ - lib/install/install.rb
40
+ - lib/install/package.json
41
+ - lib/install/postcss/application.postcss.css
42
+ - lib/install/postcss/install.rb
43
+ - lib/install/postcss/postcss.config.js
44
+ - lib/install/sass/application.sass.scss
45
+ - lib/install/sass/install.rb
46
+ - lib/install/tailwind/application.tailwind.css
47
+ - lib/install/tailwind/install.rb
48
+ - lib/install/tailwind/package.json
49
+ - lib/install/tailwind/tailwind.config.js
50
+ - lib/tasks/cssbundling/build.rake
51
+ - lib/tasks/cssbundling/install.rake
52
+ homepage: https://github.com/rails/cssbundling-rails
53
+ licenses:
54
+ - MIT
55
+ metadata: {}
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubygems_version: 3.1.4
72
+ signing_key:
73
+ specification_version: 4
74
+ summary: Bundle and process CSS with Tailwind, PostCSS, or Sass in Rails via Node.js.
75
+ test_files: []