Skip to content

Commit c0a4954

Browse files
committed
Replace webpack with esbuild and move static assets
Phoenix has changed the place to store static assets to be directly in the priv/static folder, and also it changed the building solution for assets in favor to esbuild which proved to be much faster
1 parent 905d6b8 commit c0a4954

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+448
-21354
lines changed

.credo.exs

+154-104
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
configs: [
1111
%{
1212
#
13-
# Run any exec using `mix credo -C <name>`. If no exec name is given
13+
# Run any config using `mix credo -C <name>`. If no config name is given
1414
# "default" is used.
1515
#
1616
name: "default",
@@ -21,10 +21,23 @@
2121
# You can give explicit globs or simply directories.
2222
# In the latter case `**/*.{ex,exs}` will be used.
2323
#
24-
included: ["lib/", "src/", "test/", "web/", "apps/"],
24+
included: [
25+
"lib/",
26+
"src/",
27+
"test/",
28+
"web/",
29+
"apps/*/lib/",
30+
"apps/*/src/",
31+
"apps/*/test/",
32+
"apps/*/web/"
33+
],
2534
excluded: [~r"/_build/", ~r"/deps/", ~r"/node_modules/"]
2635
},
2736
#
37+
# Load and configure plugins here:
38+
#
39+
plugins: [],
40+
#
2841
# If you create your own checks, you must specify the source files for
2942
# them here, so they can be loaded by Credo before running the analysis.
3043
#
@@ -35,6 +48,10 @@
3548
#
3649
strict: false,
3750
#
51+
# To modify the timeout for parsing files, change this value:
52+
#
53+
parse_timeout: 5000,
54+
#
3855
# If you want to use uncolored output by default, you can change `color`
3956
# to `false` below:
4057
#
@@ -47,114 +64,147 @@
4764
#
4865
# {Credo.Check.Design.DuplicatedCode, false}
4966
#
50-
checks: [
51-
#
52-
## Consistency Checks
53-
#
54-
{Credo.Check.Consistency.ExceptionNames, []},
55-
{Credo.Check.Consistency.LineEndings, []},
56-
{Credo.Check.Consistency.ParameterPatternMatching, []},
57-
{Credo.Check.Consistency.SpaceAroundOperators, []},
58-
{Credo.Check.Consistency.SpaceInParentheses, []},
59-
{Credo.Check.Consistency.TabsOrSpaces, []},
67+
checks: %{
68+
enabled: [
69+
#
70+
## Consistency Checks
71+
#
72+
{Credo.Check.Consistency.ExceptionNames, []},
73+
{Credo.Check.Consistency.LineEndings, []},
74+
{Credo.Check.Consistency.ParameterPatternMatching, []},
75+
{Credo.Check.Consistency.SpaceAroundOperators, []},
76+
{Credo.Check.Consistency.SpaceInParentheses, []},
77+
{Credo.Check.Consistency.TabsOrSpaces, []},
6078

61-
#
62-
## Design Checks
63-
#
64-
# You can customize the priority of any check
65-
# Priority values are: `low, normal, high, higher`
66-
#
67-
{Credo.Check.Design.AliasUsage,
68-
[priority: :low, if_nested_deeper_than: 2, if_called_more_often_than: 0]},
69-
# You can also customize the exit_status of each check.
70-
# If you don't want TODO comments to cause `mix credo` to fail, just
71-
# set this value to 0 (zero).
72-
#
73-
{Credo.Check.Design.TagTODO, [exit_status: 2]},
74-
{Credo.Check.Design.TagFIXME, []},
79+
#
80+
## Design Checks
81+
#
82+
# You can customize the priority of any check
83+
# Priority values are: `low, normal, high, higher`
84+
#
85+
{Credo.Check.Design.AliasUsage,
86+
[priority: :low, if_nested_deeper_than: 2, if_called_more_often_than: 0]},
87+
# You can also customize the exit_status of each check.
88+
# If you don't want TODO comments to cause `mix credo` to fail, just
89+
# set this value to 0 (zero).
90+
#
91+
{Credo.Check.Design.TagTODO, [exit_status: 2]},
92+
{Credo.Check.Design.TagFIXME, []},
7593

76-
#
77-
## Readability Checks
78-
#
79-
{Credo.Check.Readability.AliasOrder, []},
80-
{Credo.Check.Readability.FunctionNames, []},
81-
{Credo.Check.Readability.LargeNumbers, []},
82-
{Credo.Check.Readability.MaxLineLength, [priority: :low, max_length: 120]},
83-
{Credo.Check.Readability.ModuleAttributeNames, []},
84-
{Credo.Check.Readability.ModuleDoc, false},
85-
{Credo.Check.Readability.ModuleNames, []},
86-
{Credo.Check.Readability.ParenthesesInCondition, []},
87-
{Credo.Check.Readability.ParenthesesOnZeroArityDefs, []},
88-
{Credo.Check.Readability.PredicateFunctionNames, []},
89-
{Credo.Check.Readability.PreferImplicitTry, []},
90-
{Credo.Check.Readability.RedundantBlankLines, []},
91-
{Credo.Check.Readability.Semicolons, []},
92-
{Credo.Check.Readability.SpaceAfterCommas, []},
93-
{Credo.Check.Readability.StringSigils, []},
94-
{Credo.Check.Readability.TrailingBlankLine, []},
95-
{Credo.Check.Readability.TrailingWhiteSpace, []},
96-
# TODO: enable by default in Credo 1.1
97-
{Credo.Check.Readability.UnnecessaryAliasExpansion, false},
98-
{Credo.Check.Readability.VariableNames, []},
94+
#
95+
## Readability Checks
96+
#
97+
{Credo.Check.Readability.AliasOrder, []},
98+
{Credo.Check.Readability.FunctionNames, []},
99+
{Credo.Check.Readability.LargeNumbers, []},
100+
{Credo.Check.Readability.MaxLineLength, [priority: :low, max_length: 120]},
101+
{Credo.Check.Readability.ModuleAttributeNames, []},
102+
{Credo.Check.Readability.ModuleDoc, false},
103+
{Credo.Check.Readability.ModuleNames, []},
104+
{Credo.Check.Readability.ParenthesesInCondition, []},
105+
{Credo.Check.Readability.ParenthesesOnZeroArityDefs, []},
106+
{Credo.Check.Readability.PipeIntoAnonymousFunctions, []},
107+
{Credo.Check.Readability.PredicateFunctionNames, []},
108+
{Credo.Check.Readability.PreferImplicitTry, []},
109+
{Credo.Check.Readability.RedundantBlankLines, []},
110+
{Credo.Check.Readability.Semicolons, []},
111+
{Credo.Check.Readability.SpaceAfterCommas, []},
112+
{Credo.Check.Readability.StringSigils, []},
113+
{Credo.Check.Readability.TrailingBlankLine, []},
114+
{Credo.Check.Readability.TrailingWhiteSpace, []},
115+
{Credo.Check.Readability.UnnecessaryAliasExpansion, []},
116+
{Credo.Check.Readability.VariableNames, []},
117+
{Credo.Check.Readability.WithSingleClause, []},
99118

100-
#
101-
## Refactoring Opportunities
102-
#
103-
{Credo.Check.Refactor.CondStatements, []},
104-
{Credo.Check.Refactor.CyclomaticComplexity, []},
105-
{Credo.Check.Refactor.FunctionArity, []},
106-
{Credo.Check.Refactor.LongQuoteBlocks, []},
107-
{Credo.Check.Refactor.MapInto, false},
108-
{Credo.Check.Refactor.MatchInCondition, []},
109-
{Credo.Check.Refactor.NegatedConditionsInUnless, []},
110-
{Credo.Check.Refactor.NegatedConditionsWithElse, []},
111-
{Credo.Check.Refactor.Nesting, []},
112-
{Credo.Check.Refactor.PipeChainStart,
113-
[
114-
excluded_argument_types: [:atom, :binary, :fn, :keyword, :number],
115-
excluded_functions: []
116-
]},
117-
{Credo.Check.Refactor.UnlessWithElse, []},
119+
#
120+
## Refactoring Opportunities
121+
#
122+
{Credo.Check.Refactor.Apply, []},
123+
{Credo.Check.Refactor.CondStatements, []},
124+
{Credo.Check.Refactor.CyclomaticComplexity, []},
125+
{Credo.Check.Refactor.FunctionArity, []},
126+
{Credo.Check.Refactor.LongQuoteBlocks, []},
127+
{Credo.Check.Refactor.MatchInCondition, []},
128+
{Credo.Check.Refactor.MapJoin, []},
129+
{Credo.Check.Refactor.NegatedConditionsInUnless, []},
130+
{Credo.Check.Refactor.NegatedConditionsWithElse, []},
131+
{Credo.Check.Refactor.Nesting, []},
132+
{Credo.Check.Refactor.UnlessWithElse, []},
133+
{Credo.Check.Refactor.WithClauses, []},
134+
{Credo.Check.Refactor.FilterFilter, []},
135+
{Credo.Check.Refactor.RejectReject, []},
136+
{Credo.Check.Refactor.RedundantWithClauseResult, []},
118137

119-
#
120-
## Warnings
121-
#
122-
{Credo.Check.Warning.BoolOperationOnSameValues, []},
123-
{Credo.Check.Warning.ExpensiveEmptyEnumCheck, []},
124-
{Credo.Check.Warning.IExPry, []},
125-
{Credo.Check.Warning.IoInspect, []},
126-
{Credo.Check.Warning.LazyLogging, false},
127-
{Credo.Check.Warning.OperationOnSameValues, []},
128-
{Credo.Check.Warning.OperationWithConstantResult, []},
129-
{Credo.Check.Warning.RaiseInsideRescue, []},
130-
{Credo.Check.Warning.UnusedEnumOperation, []},
131-
{Credo.Check.Warning.UnusedFileOperation, []},
132-
{Credo.Check.Warning.UnusedKeywordOperation, []},
133-
{Credo.Check.Warning.UnusedListOperation, []},
134-
{Credo.Check.Warning.UnusedPathOperation, []},
135-
{Credo.Check.Warning.UnusedRegexOperation, []},
136-
{Credo.Check.Warning.UnusedStringOperation, []},
137-
{Credo.Check.Warning.UnusedTupleOperation, []},
138+
#
139+
## Warnings
140+
#
141+
{Credo.Check.Warning.ApplicationConfigInModuleAttribute, []},
142+
{Credo.Check.Warning.BoolOperationOnSameValues, []},
143+
{Credo.Check.Warning.ExpensiveEmptyEnumCheck, []},
144+
{Credo.Check.Warning.IExPry, []},
145+
{Credo.Check.Warning.IoInspect, []},
146+
{Credo.Check.Warning.OperationOnSameValues, []},
147+
{Credo.Check.Warning.OperationWithConstantResult, []},
148+
{Credo.Check.Warning.RaiseInsideRescue, []},
149+
{Credo.Check.Warning.SpecWithStruct, []},
150+
{Credo.Check.Warning.WrongTestFileExtension, []},
151+
{Credo.Check.Warning.UnusedEnumOperation, []},
152+
{Credo.Check.Warning.UnusedFileOperation, []},
153+
{Credo.Check.Warning.UnusedKeywordOperation, []},
154+
{Credo.Check.Warning.UnusedListOperation, []},
155+
{Credo.Check.Warning.UnusedPathOperation, []},
156+
{Credo.Check.Warning.UnusedRegexOperation, []},
157+
{Credo.Check.Warning.UnusedStringOperation, []},
158+
{Credo.Check.Warning.UnusedTupleOperation, []},
159+
{Credo.Check.Warning.UnsafeExec, []}
160+
],
161+
disabled: [
162+
#
163+
# Checks scheduled for next check update (opt-in for now, just replace `false` with `[]`)
138164

139-
#
140-
# Controversial and experimental checks (opt-in, just replace `false` with `[]`)
141-
#
142-
{Credo.Check.Consistency.MultiAliasImportRequireUse, false},
143-
{Credo.Check.Design.DuplicatedCode, false},
144-
{Credo.Check.Readability.MultiAlias, false},
145-
{Credo.Check.Readability.Specs, false},
146-
{Credo.Check.Refactor.ABCSize, false},
147-
{Credo.Check.Refactor.AppendSingleItem, false},
148-
{Credo.Check.Refactor.DoubleBooleanNegation, false},
149-
{Credo.Check.Refactor.ModuleDependencies, false},
150-
{Credo.Check.Refactor.VariableRebinding, false},
151-
{Credo.Check.Warning.MapGetUnsafePass, false},
152-
{Credo.Check.Warning.UnsafeToAtom, false}
165+
#
166+
# Controversial and experimental checks (opt-in, just move the check to `:enabled`
167+
# and be sure to use `mix credo --strict` to see low priority checks)
168+
#
169+
{Credo.Check.Consistency.MultiAliasImportRequireUse, []},
170+
{Credo.Check.Consistency.UnusedVariableNames, []},
171+
{Credo.Check.Design.DuplicatedCode, []},
172+
{Credo.Check.Design.SkipTestWithoutComment, []},
173+
{Credo.Check.Readability.AliasAs, []},
174+
{Credo.Check.Readability.BlockPipe, []},
175+
{Credo.Check.Readability.ImplTrue, []},
176+
{Credo.Check.Readability.MultiAlias, []},
177+
{Credo.Check.Readability.NestedFunctionCalls, []},
178+
{Credo.Check.Readability.SeparateAliasRequire, []},
179+
{Credo.Check.Readability.SingleFunctionToBlockPipe, []},
180+
{Credo.Check.Readability.SinglePipe, []},
181+
{Credo.Check.Readability.Specs, []},
182+
{Credo.Check.Readability.StrictModuleLayout, []},
183+
{Credo.Check.Readability.WithCustomTaggedTuple, []},
184+
{Credo.Check.Refactor.ABCSize, []},
185+
{Credo.Check.Refactor.AppendSingleItem, []},
186+
{Credo.Check.Refactor.DoubleBooleanNegation, []},
187+
{Credo.Check.Refactor.FilterReject, []},
188+
{Credo.Check.Refactor.IoPuts, []},
189+
{Credo.Check.Refactor.MapMap, []},
190+
{Credo.Check.Refactor.ModuleDependencies, []},
191+
{Credo.Check.Refactor.NegatedIsNil, []},
192+
{Credo.Check.Refactor.PipeChainStart, []},
193+
{Credo.Check.Refactor.RejectFilter, []},
194+
{Credo.Check.Refactor.VariableRebinding, []},
195+
{Credo.Check.Warning.LazyLogging, []},
196+
{Credo.Check.Warning.LeakyEnvironment, []},
197+
{Credo.Check.Warning.MapGetUnsafePass, []},
198+
{Credo.Check.Warning.MixEnv, []},
199+
{Credo.Check.Warning.UnsafeToAtom, []}
153200

154-
#
155-
# Custom checks can be created using `mix credo.gen.check`.
156-
#
157-
]
201+
# {Credo.Check.Refactor.MapInto, []},
202+
203+
#
204+
# Custom checks can be created using `mix credo.gen.check`.
205+
#
206+
]
207+
}
158208
}
159209
]
160210
}

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ jobs:
9595
- name: NPM Install
9696
run: cd assets && npm install
9797
- name: Build assets
98-
run: cd assets && node node_modules/webpack/bin/webpack.js --mode production
98+
run: mix assets.deploy
9999
- name: Digest assets
100100
run: mix phx.digest
101101
- name: Run tests

.gitignore

-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,3 @@
1313
erl_crash.dump
1414
npm-debug.log
1515
tilex-*.tar
16-
17-
# webpack
18-
/priv/static/

assets/.babelrc

-4
This file was deleted.

assets/js/app.js

+46-25
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,49 @@
1-
// Brunch automatically concatenates all files in your
2-
// watched paths. Those paths can be configured at
3-
// config.paths.watched in "brunch-config.js".
4-
//
5-
// However, those files will only be executed if
6-
// explicitly imported. The only exception are files
7-
// in vendor, which are never wrapped in imports and
8-
// therefore are always executed.
1+
// We import the CSS which is extracted to its own file by esbuild.
2+
// Remove this line if you add a your own CSS build pipeline (e.g postcss).
3+
import "../css/app.css"
94

10-
// Import dependencies
11-
//
12-
// If you no longer want to use a dependency, remember
13-
// to also remove its path from "config.paths.watched".
14-
import 'phoenix_html';
15-
import $ from 'jquery';
16-
import 'jquery.cookie';
5+
// If you want to use Phoenix channels, run `mix help phx.gen.channel`
6+
// to get started and then uncomment the line below.
7+
// import "./user_socket.js"
178

18-
// Import local files
9+
// You can include dependencies in two ways.
10+
//
11+
// The simplest option is to put them in assets/vendor and
12+
// import them using relative paths:
13+
//
14+
// import "../vendor/some-package.js"
15+
//
16+
// Alternatively, you can `npm install some-package --prefix assets` and import
17+
// them using a path starting with the package name:
18+
//
19+
// import "some-package"
1920
//
20-
// Local files can be imported directly using relative
21-
// paths "./socket" or full ones "web/static/js/socket".
22-
import css from '../css/app.css';
23-
24-
// import socket from "./socket"
25-
import tilex from './tilex';
26-
import like from './like';
27-
import twitter from './twitter_button';
28-
import prism from '../vendor/js/prism';
21+
22+
// Include phoenix_html to handle method=PUT/DELETE in forms and buttons.
23+
import "phoenix_html"
24+
// Establish Phoenix Socket and LiveView configuration.
25+
import {Socket} from "phoenix"
26+
import {LiveSocket} from "phoenix_live_view"
27+
import topbar from "../vendor/topbar"
28+
29+
import './tilex';
30+
import './like';
31+
import './twitter_button';
32+
import '../vendor/js/prism';
33+
34+
let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content")
35+
let liveSocket = new LiveSocket("/live", Socket, {params: {_csrf_token: csrfToken}})
36+
37+
// Show progress bar on live navigation and form submits
38+
topbar.config({barColors: {0: "#29d"}, shadowColor: "rgba(0, 0, 0, .3)"})
39+
window.addEventListener("phx:page-loading-start", info => topbar.show())
40+
window.addEventListener("phx:page-loading-stop", info => topbar.hide())
41+
42+
// connect if there are any LiveViews on the page
43+
liveSocket.connect()
44+
45+
// expose liveSocket on window for web console debug logs and latency simulation:
46+
// >> liveSocket.enableDebug()
47+
// >> liveSocket.enableLatencySim(1000) // enabled for duration of browser session
48+
// >> liveSocket.disableLatencySim()
49+
window.liveSocket = liveSocket

0 commit comments

Comments
 (0)