現在Docker + Rails 環境でアプリを作成しています。
EC2でアプリが動作しないためローカルでproductionモードで動作させています。
具体的には各コマンドの末尾にRAILS_ENV=production
をつけて
- DBを作成(rails db:create)
- マイグレーションを実行(rails db:migrate)
- シードデータを投入
- プリコンパイル(rails assets:precompile)
というところまで来ています。
ただ、docker-compose run --rm web rails assets:precompile RAILS_ENV=production
というコマンドを実行したところ
下記のような警告が表示されました。
bash
1WARNING in asset size limit: The following asset(s) exceed the recommended size limit (244 KiB). 2This can impact web performance. 3Assets: 4 js/application-e2fa607a36268bd325e5.js (1.34 MiB) 5 js/tops-3552fb8f1ed147cabba5.js.map.gz (261 KiB) 6 js/application-e2fa607a36268bd325e5.js.gz (493 KiB) 7 js/application-e2fa607a36268bd325e5.js.map.gz (720 KiB) 8 js/application-e2fa607a36268bd325e5.js.br (408 KiB) 9 js/application-e2fa607a36268bd325e5.js.map.br (595 KiB) 10 11WARNING in entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (244 KiB). This can impact web performance. 12Entrypoints: 13 application (1.34 MiB) 14 js/application-e2fa607a36268bd325e5.js 15 16 17WARNING in webpack performance recommendations: 18You can limit the size of your bundles by using import() or require.ensure to lazy load some parts of your application. 19For more info visit https://webpack.js.org/guides/code-splitting/ 20Child mini-css-extract-plugin node_modules/css-loader/dist/cjs.js??ref--6-1!node_modules/postcss-loader/src/index.js??ref--6-2!node_modules/@ttskch/select2-bootstrap4-theme/dist/select2-bootstrap4.min.css: 21 Entrypoint mini-css-extract-plugin = * 22 2 modules 23Child mini-css-extract-plugin node_modules/css-loader/dist/cjs.js??ref--6-1!node_modules/postcss-loader/src/index.js??ref--6-2!node_modules/select2/dist/css/select2.css: 24 Entrypoint mini-css-extract-plugin = * 25 2 modules
このWARNINGを解消するにはどうすればいいのか調べてみると
[webpack] WARNING in asset size limit、と出たときの対処法
という記事が見つかりましたが、
Rails(webpacker)ではどのようにすればよいのか全くわかりません。
もしわかる方がいらっしゃればご教授いただきますようよろしくお願いいたします(m_ _m)
動作環境
Ruby: 2.5.7
Rails: 6.0.3.5
Docker for Mac: 2.2.0.5
期待する動作
- 上記のWARNINGログが表示されなくなること
- 動作が軽くなること
該当しそうなコード
config/webpacker.yml(1/2)
yml
1# Note: You must restart bin/webpack-dev-server for changes to take effect 2 3default: &default 4 source_path: app/javascript 5 source_entry_path: packs 6 public_root_path: public 7 public_output_path: packs 8 cache_path: tmp/cache/webpacker 9 check_yarn_integrity: false 10 webpack_compile_output: true 11 12 # Additional paths webpack should lookup modules 13 # ['app/assets', 'engine/foo/app/assets'] 14 resolved_paths: [] 15 16 # Reload manifest.json on all requests so we reload latest compiled packs 17 cache_manifest: false 18 19 # Extract and emit a css file 20 extract_css: false 21 22 static_assets_extensions: 23 - .jpg 24 - .jpeg 25 - .png 26 - .gif 27 - .tiff 28 - .ico 29 - .svg 30 - .eot 31 - .otf 32 - .ttf 33 - .woff 34 - .woff2 35 36 extensions: 37 - .mjs 38 - .js 39 - .sass 40 - .scss 41 - .css 42 - .module.sass 43 - .module.scss 44 - .module.css 45 - .png 46 - .svg 47 - .gif 48 - .jpeg 49 - .jpg 50 51development: 52 <<: *default 53 compile: true 54 55 # Verifies that correct packages and versions are installed by inspecting package.json, yarn.lock, and node_modules 56 check_yarn_integrity: true 57 58 # Reference: https://webpack.js.org/configuration/dev-server/ 59 dev_server: 60 https: false 61 host: 0.0.0.0 62 port: 3035 63 public: 0.0.0.0:3035 64 hmr: false 65 # Inline should be set to true if using HMR 66 inline: true 67 overlay: true 68 compress: true 69 disable_host_check: true 70 use_local_ip: false 71 quiet: false 72 pretty: false 73 headers: 74 'Access-Control-Allow-Origin': '*' 75 watch_options: 76 ignored: '**/node_modules/**' 77 78 79test: 80 <<: *default 81 compile: true 82 83 # Compile test packs to a separate directory 84 public_output_path: packs-test 85 86production: 87 <<: *default 88 89 # Production depends on precompilation of packs prior to booting for performance. 90 compile: false 91 92 # Extract and emit a css file 93 extract_css: true 94 95 # Cache manifest.json for performance 96 cache_manifest: true 97
config/webpack/production.js
js
1process.env.NODE_ENV = process.env.NODE_ENV || 'production' 2 3const environment = require('./environment') 4 5module.exports = environment.toWebpackConfig() 6
回答1件
あなたの回答
tips
プレビュー