Skip to content

Add task 6 #90

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: CI

on: [push]

jobs:
build:
runs-on: ubuntu-latest
name: sitespeedio
steps:
- name: checkout code
uses: actions/checkout@v2
- name: run sitespeedio test
run: docker run -v "$(pwd):/sitespeed.io" sitespeedio/sitespeed.io:latest https://8b18-5-152-41-9.ngrok-free.app/ -n 1 --budget.configPath budget.json
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,6 @@ package-lock.json
.idea/

#sitemap
/public/sitemap.xml.gz
/public/sitemap.xml.gz

/sitespeed-result/**/*
6 changes: 3 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ end
gem "actionpack-action_caching", "~> 1.2"
gem "active_record_union", "~> 1.3"
gem "acts-as-taggable-on", "~> 5.0"
gem "acts_as_follower"
gem "acts_as_follower", github: "forem/acts_as_follower", branch: "master"
gem "addressable", "~> 2.5", ">= 2.5.2"
gem "administrate", "~> 0.11"
gem "ahoy_email", "~> 0.5"
Expand Down Expand Up @@ -89,7 +89,7 @@ gem "sdoc", "~> 1.0", group: :doc
gem "serviceworker-rails", "~> 0.5"
gem "share_meow_client", "~> 0.1"
gem "sitemap_generator", "~> 6.0"
gem "skylight", "~> 3.1"
# gem "skylight", "~> 3.1"
gem "slack-notifier", "~> 2.3"
gem "sprockets", "~> 3.7"
gem "staccato", "~> 0.5"
Expand Down Expand Up @@ -122,7 +122,7 @@ group :development, :test do
gem "derailed", "~> 0.1"
gem "erb_lint", "~> 0.0", require: false
gem "faker", git: "https://github.com/stympy/faker.git", branch: "master"
gem "fix-db-schema-conflicts"
gem "fix-db-schema-conflicts", github: "jakeonrails/fix-db-schema-conflicts", branch: "master"
gem "memory_profiler", "~> 0.9"
gem "parallel_tests", "~> 2.27"
gem "pry-byebug", "~> 3.7"
Expand Down
28 changes: 18 additions & 10 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
GIT
remote: https://github.com/forem/acts_as_follower.git
revision: 06393d3693a1a3d4b390aec4976c8b8f3a81cf01
branch: master
specs:
acts_as_follower (0.2.1)
activerecord (>= 4.0)

GIT
remote: https://github.com/jakeonrails/fix-db-schema-conflicts.git
revision: 1e94f518503f1d1addd6ed052454efcbec0b3c6a
branch: master
specs:
fix-db-schema-conflicts (3.1.0)
rubocop (>= 0.38.0)

GIT
remote: https://github.com/stympy/faker.git
revision: 9910aa58d92c018abab25d491191576fcc1a7707
Expand Down Expand Up @@ -58,7 +74,6 @@ GEM
tzinfo (~> 1.1)
acts-as-taggable-on (5.0.0)
activerecord (>= 4.2.8)
acts_as_follower (0.2.1)
addressable (2.5.2)
public_suffix (>= 2.0.2, < 4.0)
administrate (0.11.0)
Expand Down Expand Up @@ -307,8 +322,6 @@ GEM
thor (~> 0.14)
fission (0.5.0)
CFPropertyList (~> 2.2)
fix-db-schema-conflicts (3.1.0)
rubocop (>= 0.38.0)
fog (1.41.0)
fog-aliyun (>= 0.1.0)
fog-atmos
Expand Down Expand Up @@ -830,10 +843,6 @@ GEM
tilt (~> 2.0)
sitemap_generator (6.0.2)
builder (~> 3.0)
skylight (3.1.4)
skylight-core (= 3.1.4)
skylight-core (3.1.4)
activesupport (>= 4.2.0)
slack-notifier (2.3.2)
smart_properties (1.13.1)
spring (2.0.2)
Expand Down Expand Up @@ -935,7 +944,7 @@ DEPENDENCIES
actionpack-action_caching (~> 1.2)
active_record_union (~> 1.3)
acts-as-taggable-on (~> 5.0)
acts_as_follower
acts_as_follower!
addressable (~> 2.5, >= 2.5.2)
administrate (~> 0.11)
ahoy_email (~> 0.5)
Expand Down Expand Up @@ -979,7 +988,7 @@ DEPENDENCIES
fastly-rails (~> 0.8)
feedjira (~> 2.2)
figaro (~> 1.1)
fix-db-schema-conflicts
fix-db-schema-conflicts!
fog (~> 1.41)
front_matter_parser (~> 0.2)
gemoji (~> 3.0.0)
Expand Down Expand Up @@ -1044,7 +1053,6 @@ DEPENDENCIES
simplecov (~> 0.16)
sinatra (~> 2.0)
sitemap_generator (~> 6.0)
skylight (~> 3.1)
slack-notifier (~> 2.3)
spring (~> 2.0)
spring-commands-rspec (~> 1.0)
Expand Down
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,12 @@

run:
docker-compose build && docker-compose run --rm web rails db:setup

setup:
bin/setup

dev:
bin/startup

clean:
bin/rails jobs:clear
7 changes: 7 additions & 0 deletions budget.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"budget": {
"transferSize": {
"javascript": 470000
}
}
}
Binary file added bundle_data_after.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bundle_data_before.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 57 additions & 0 deletions case-study-template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Case-study оптимизации

## Бюджет

Добавил бюджет

```json
{
"budget": {
"transferSize": {
"javascript": 460000
}
}
}
```

... и он оказался провален:

```
JavaScript Transfer Size with value 1.1 MB limit max 449.2 KB
```

## Оптимизация: диагностика

- Установлен плагин `webpack-bundle-analyzer`
- Выполнен анализ исходной версии приложения: см.: bundle_data_before.png
- Закомментирован `proCharts.js`
- Выполнен повторный анализ: см.: after_data_before.png
profit очевиден

## Оптимизация: работа

moment используется 1) в chart.js (views/dashboards/pro), 2) как подзависимость в геме momentjs-rails, но там он нас на беспокоит; vendor собирается в chunks - там его и поправим

В бюджет немного не уложились:(
`JavaScript Transfer Size with value 454.2 KB limit max 449.2 KB`
Поднимем его с 46_000 до 47_000:

```
INFO: Budget: 1 working, 0 failing tests and 0 errors
JavaScript Transfer Size with value 454.2 KB limit max 459.0 KB
```

## Настройка CI

Настроен `CI`: `Github Actions`.

## Настройка CI

Теперь настроим `CI`: `Travis` или `Github Actions`.

## Как сдать задание

- изменения кода
- описание
- скриншоты `bundle-analyzer` до и после оптимизации
- настроенный `CI` на `Github Actions`
11 changes: 11 additions & 0 deletions config/webpack/development.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
const environment = require('./environment');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer')
.BundleAnalyzerPlugin;

environment.plugins.append(
'BundleAnalyzer',
new BundleAnalyzerPlugin({
analyzerMode: 'static',
openAnalyzer: true,
}),
);

const config = environment.toWebpackConfig();

// For more information, see https://webpack.js.org/configuration/devtool/#devtool
Expand Down
28 changes: 16 additions & 12 deletions config/webpack/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,31 @@

// module.exports = environment;


const { environment } = require('@rails/webpacker')
const webpack = require('webpack')
const { environment } = require('@rails/webpacker');
const webpack = require('webpack');

environment.plugins.append(
'CommonsChunkVendor',
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks: (module) => {
minChunks: module => {
// this assumes your vendor imports exist in the node_modules directory
return module.context && module.context.indexOf('node_modules') !== -1
}
})
)
return (
module.context &&
module.context.indexOf('node_modules') !== -1 &&
module.context.indexOf('moment') === -1 &&
module.context.indexOf('chart.js') === -1
);
},
}),
);

environment.plugins.append(
'CommonsChunkManifest',
new webpack.optimize.CommonsChunkPlugin({
name: 'manifest',
minChunks: Infinity
})
)
minChunks: Infinity,
}),
);

module.exports = environment
module.exports = environment;
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@
"prop-types": "^15.7.2",
"pusher-js": "^4.4.0",
"twilio-video": "^1.15.2",
"web-share-wrapper": "^0.2.1"
"web-share-wrapper": "^0.2.1",
"webpack-bundle-analyzer": "^4.8.0"
},
"jest": {
"setupFiles": [
Expand Down
Loading