|
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 | 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
|
0 commit comments