cssbundling-rails 1.1.2 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 45868eda1ae67158b652d75c9ad8d89bc55bf67ac62e0539b8a30b91122d0186
4
- data.tar.gz: d6b0d91eaf919c44628aa7c9edbdf3a56d3d34e0ace6651dd42aca2091acb30e
3
+ metadata.gz: 3eb8589b682d3c0c276c75baa0923c706e3f09de2a554e47ea7f008e01b555c5
4
+ data.tar.gz: c8c43687d5cbf5cf3fc7f2e7fcbeb35f99b80e2986227135e306cb4a42167423
5
5
  SHA512:
6
- metadata.gz: 517e8067a0fabc88db726ca0d89c4ec488a3815aef2c6c5cf5e4df254c2706ed6826693610062e4fe0385b3d42688217f46de5005bd8b631b8ba8e8f10720346
7
- data.tar.gz: f81ead37fb5b36fbf09a1d8751ae67fbeb3e28d82baa80d177cd0779d8c3bc36ed62b686021ce3fba5cb817f1c431d585346a6e067502e33e3483b283b501b80
6
+ metadata.gz: 88e4959bbf33a9b580f33a8316a327f437b3ce422d69a95e2e7c55df99e2fc840e98eb636c6baa9e281421415c62e5de28e42d39db2d1b0440db46895f498959
7
+ data.tar.gz: ee626b8d3329f131034b218ccac7c5590d36afa7d4191b75afa0a06ed5f27268fe5c1720cdd64d347102ec71d5bdff34c993d12b460030064802c0ccc6d71899
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. (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`).
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).
@@ -1,3 +1,3 @@
1
1
  module Cssbundling
2
- VERSION = "1.1.2"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -1,2 +1,2 @@
1
- web: unset PORT && bin/rails server
1
+ web: unset PORT && env RUBY_DEBUG_OPEN=true bin/rails server
2
2
  css: yarn build:css --watch
@@ -1,7 +1,7 @@
1
- say "Install Bootstrap with Bootstrap Icons and Popperjs/core"
1
+ say "Install Bootstrap with Bootstrap Icons, Popperjs/core and Autoprefixer"
2
2
  copy_file "#{__dir__}/application.bootstrap.scss",
3
3
  "app/assets/stylesheets/application.bootstrap.scss"
4
- run "yarn add sass bootstrap bootstrap-icons @popperjs/core"
4
+ run "yarn add sass bootstrap bootstrap-icons @popperjs/core postcss postcss-cli autoprefixer nodemon"
5
5
 
6
6
  inject_into_file "config/initializers/assets.rb", after: /.*Rails.application.config.assets.paths.*\n/ do
7
7
  <<~RUBY
@@ -16,16 +16,32 @@ else
16
16
  say %(Add import * as bootstrap from "bootstrap" to your entry point JavaScript file), :red
17
17
  end
18
18
 
19
- say "Add build:css script"
20
- build_script = "sass ./app/assets/stylesheets/application.bootstrap.scss:./app/assets/builds/application.css --no-source-map --load-path=node_modules"
19
+ def add_npm_script(name, script, run_script=true)
20
+ case `npx -v`.to_f
21
+ when 7.1...8.0
22
+ say "Add #{name} script"
23
+ run %(npm set-script #{name} "#{script}")
24
+ run %(yarn #{name}) if run_script
25
+ when (8.0..)
26
+ say "Add #{name} script"
27
+ run %(npm pkg set scripts.#{name}="#{script}")
28
+ run %(yarn #{name}) if run_script
29
+ else
30
+ say %(Add "scripts": { "#{name}": "#{script}" } to your package.json), :green
31
+ end
32
+ end
33
+
34
+ add_npm_script("build:css:compile", "sass ./app/assets/stylesheets/application.bootstrap.scss:./app/assets/builds/application.css --no-source-map --load-path=node_modules")
35
+ add_npm_script("build:css:prefix", "postcss ./app/assets/builds/application.css --use=autoprefixer --output=./app/assets/builds/application.css")
36
+ add_npm_script("build:css", "yarn build:css:compile && yarn build:css:prefix")
37
+ add_npm_script("watch:css", "nodemon --watch ./app/assets/stylesheets/ --ext scss --exec \\\"yarn build:css\\\"", false)
38
+
39
+ gsub_file "Procfile.dev", "build:css --watch", "watch:css"
21
40
 
22
41
  case `npx -v`.to_f
23
- when 7.1...8.0
24
- run %(npm set-script build:css "#{build_script}")
25
- run %(yarn build:css)
26
- when (8.0..)
27
- run %(npm pkg set scripts.build:css="#{build_script}")
28
- run %(yarn build:css)
42
+ when (7.1..)
43
+ say "Add browserslist config"
44
+ run %(npm pkg set browserslist[]=defaults)
29
45
  else
30
- say %(Add "scripts": { "build:css": "#{build_script}" } to your package.json), :green
46
+ say %(Add "browserslist": ["defaults"] to your package.json), :green
31
47
  end
@@ -2,17 +2,21 @@ namespace :css do
2
2
  desc "Build your CSS bundle"
3
3
  task :build do
4
4
  unless system "yarn install && yarn build:css"
5
- raise "cssbundling-rails: Command css:build failed, ensure yarn is installed and `yarn build:css` runs without errors"
5
+ raise "cssbundling-rails: Command css:build failed, ensure yarn is installed and `yarn build:css` runs without errors or use SKIP_CSS_BUILD env variable"
6
6
  end
7
7
  end
8
8
  end
9
9
 
10
- if Rake::Task.task_defined?("assets:precompile")
11
- Rake::Task["assets:precompile"].enhance(["css:build"])
12
- end
10
+ unless ENV["SKIP_CSS_BUILD"]
11
+ if Rake::Task.task_defined?("assets:precompile")
12
+ Rake::Task["assets:precompile"].enhance(["css:build"])
13
+ end
13
14
 
14
- if Rake::Task.task_defined?("test:prepare")
15
- Rake::Task["test:prepare"].enhance(["css:build"])
16
- elsif Rake::Task.task_defined?("db:test:prepare")
17
- Rake::Task["db:test:prepare"].enhance(["css:build"])
15
+ if Rake::Task.task_defined?("test:prepare")
16
+ Rake::Task["test:prepare"].enhance(["css:build"])
17
+ elsif Rake::Task.task_defined?("spec:prepare")
18
+ Rake::Task["spec:prepare"].enhance(["css:build"])
19
+ elsif Rake::Task.task_defined?("db:test:prepare")
20
+ Rake::Task["db:test:prepare"].enhance(["css:build"])
21
+ end
18
22
  end
@@ -1,7 +1,7 @@
1
1
  namespace :css do
2
2
  desc "Remove CSS builds"
3
3
  task :clobber do
4
- rm_rf Dir["app/assets/builds/**/[^.]*.css"], verbose: false
4
+ rm_rf Dir["app/assets/builds/**/[^.]*.{css,css.map}"], verbose: false
5
5
  end
6
6
  end
7
7
 
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.1.2
4
+ version: 1.2.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: 2022-12-14 00:00:00.000000000 Z
12
+ date: 2023-06-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
@@ -75,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
75
  - !ruby/object:Gem::Version
76
76
  version: '0'
77
77
  requirements: []
78
- rubygems_version: 3.3.26
78
+ rubygems_version: 3.4.10
79
79
  signing_key:
80
80
  specification_version: 4
81
81
  summary: Bundle and process CSS with Tailwind, Bootstrap, PostCSS, Sass in Rails via