Skip to content

Commit 727675e

Browse files
eldanogrzuy
andauthored
Prefer Phoenix v1.5 defaults when possible (#151)
Steps taken using phx_new 1.5.12: $ cd .. $ mix phx.new elixir_console --live --no-gettext --no-ecto --no-dashboard Manually chose what to keep and discard Co-authored-by: Gonzalo <grzuy0@gmail.com>
1 parent b16eb5d commit 727675e

16 files changed

Lines changed: 266 additions & 122 deletions

File tree

assets/js/app.js

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,61 @@
11
// We need to import the CSS so that webpack will load it.
22
// The MiniCssExtractPlugin is used to separate it out into
33
// its own CSS file.
4-
import '../css/app.css';
4+
import "../css/app.css"
55

66
// webpack automatically bundles all modules in your
77
// entry points. Those entry points can be configured
88
// in "webpack.config.js".
99
//
10-
// Import dependencies
10+
// Import deps with the dep name or local files with a relative path, for example:
1111
//
12-
import 'phoenix_html';
13-
14-
// Import local files
12+
// import {Socket} from "phoenix"
13+
// import socket from "./socket"
1514
//
16-
// Local files can be imported directly using relative paths, for example:
17-
// import socket from "./socket"
18-
19-
import {Socket} from 'phoenix';
20-
import { LiveSocket } from 'phoenix_live_view';
15+
import "phoenix_html"
16+
import {Socket} from "phoenix"
17+
import {LiveSocket} from "phoenix_live_view"
2118

2219
let Hooks = {};
2320
Hooks.CommandInput = {
2421
mounted() {
2522
const el = this.el;
26-
this.handleEvent('reset', () => {
27-
el.value = '';
23+
this.handleEvent("reset", () => {
24+
el.value = "";
2825
});
29-
el.addEventListener('keydown', (e) => {
30-
if (e.code === 'Tab') {
26+
el.addEventListener("keydown", (e) => {
27+
if (e.code === "Tab") {
3128
this.pushEventTo(
32-
'#commandInput',
33-
'suggest',
34-
{'value': el.value, 'caret_position': el.selectionEnd}
29+
"#commandInput",
30+
"suggest",
31+
{"value": el.value, "caret_position": el.selectionEnd}
3532
);
36-
} else if (e.code === 'ArrowUp') {
37-
this.pushEventTo('#commandInput', 'cycle_history_up');
38-
} else if (e.code === 'ArrowDown') {
39-
this.pushEventTo('#commandInput', 'cycle_history_down');
33+
} else if (e.code === "ArrowUp") {
34+
this.pushEventTo("#commandInput", "cycle_history_up");
35+
} else if (e.code === "ArrowDown") {
36+
this.pushEventTo("#commandInput", "cycle_history_down");
4037
}
4138
});
4239
},
4340
updated() {
4441
const newValue = this.el.dataset.input_value;
4542
const newCaretPosition = parseInt(this.el.dataset.caret_position);
4643

47-
if (newValue !== '') {
44+
if (newValue !== "") {
4845
this.el.value = newValue;
4946
this.el.setSelectionRange(newCaretPosition, newCaretPosition);
5047
}
5148
}
5249
};
5350

54-
let csrfToken = document.querySelector('meta[name=\'csrf-token\']').getAttribute('content');
51+
let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content")
5552
/* eslint-disable camelcase */
5653
let liveSocket = new LiveSocket(
57-
'/live',
54+
"/live",
5855
Socket,
5956
{
60-
hooks: Hooks,
6157
params: {_csrf_token: csrfToken},
58+
hooks: Hooks,
6259
metadata: {
6360
keydown: (_e, el) => {
6461
return {caret_position: el.selectionEnd};
@@ -67,12 +64,20 @@ let liveSocket = new LiveSocket(
6764
}
6865
);
6966
/* eslint-enable camelcase */
70-
liveSocket.connect();
7167

72-
document.addEventListener('DOMContentLoaded', () => {
73-
const input = document.getElementById('commandInput');
74-
input.addEventListener('keydown', (e) => {
75-
if (e.code === 'Tab') {
68+
// connect if there are any LiveViews on the page
69+
liveSocket.connect()
70+
71+
// expose liveSocket on window for web console debug logs and latency simulation:
72+
// >> liveSocket.enableDebug()
73+
// >> liveSocket.enableLatencySim(1000) // enabled for duration of browser session
74+
// >> liveSocket.disableLatencySim()
75+
window.liveSocket = liveSocket
76+
77+
document.addEventListener("DOMContentLoaded", () => {
78+
const input = document.getElementById("commandInput");
79+
input.addEventListener("keydown", (e) => {
80+
if (e.code === "Tab") {
7681
e.preventDefault();
7782
}
7883
}, true);

assets/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"repository": {},
3+
"description": " ",
34
"license": "MIT",
45
"scripts": {
56
"deploy": "webpack --mode production",
@@ -17,6 +18,7 @@
1718
"babel-loader": "^8.0.0",
1819
"copy-webpack-plugin": "^4.5.0",
1920
"css-loader": "^2.1.1",
21+
"hard-source-webpack-plugin": "^0.13.1",
2022
"mini-css-extract-plugin": "^0.4.0",
2123
"optimize-css-assets-webpack-plugin": "^5.0.1",
2224
"postcss-loader": "^3.0.0",

assets/webpack.config.js

Lines changed: 51 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,60 @@
11
const path = require('path');
22
const glob = require('glob');
3+
const HardSourceWebpackPlugin = require('hard-source-webpack-plugin');
34
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
4-
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
5+
const TerserPlugin = require('terser-webpack-plugin');
56
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
67
const CopyWebpackPlugin = require('copy-webpack-plugin');
78

8-
module.exports = (env, options) => ({
9-
optimization: {
10-
minimizer: [
11-
new UglifyJsPlugin({ cache: true, parallel: true, sourceMap: false }),
12-
new OptimizeCSSAssetsPlugin({})
13-
]
14-
},
15-
entry: {
16-
'./js/app.js': glob.sync('./vendor/**/*.js').concat(['./js/app.js'])
17-
},
18-
output: {
19-
filename: 'app.js',
20-
path: path.resolve(__dirname, '../priv/static/js')
21-
},
22-
module: {
23-
rules: [
24-
{
25-
test: /\.js$/,
26-
exclude: /node_modules/,
27-
use: {
28-
loader: 'babel-loader'
29-
}
30-
},
31-
{
32-
test: /\.css$/,
33-
use: [
34-
MiniCssExtractPlugin.loader,
35-
{ loader: 'css-loader', options: { importLoaders: 1 } },
36-
{
37-
loader: 'postcss-loader',
38-
options: {
39-
config: {
40-
path: './postcss.config.js'
9+
module.exports = (_env, options) => {
10+
const devMode = options.mode !== 'production';
11+
12+
return {
13+
optimization: {
14+
minimizer: [
15+
new TerserPlugin({ cache: true, parallel: true, sourceMap: devMode }),
16+
new OptimizeCSSAssetsPlugin({})
17+
]
18+
},
19+
entry: {
20+
'app': glob.sync('./vendor/**/*.js').concat(['./js/app.js'])
21+
},
22+
output: {
23+
filename: '[name].js',
24+
path: path.resolve(__dirname, '../priv/static/js'),
25+
publicPath: '/js/'
26+
},
27+
devtool: devMode ? 'eval-cheap-module-source-map' : undefined,
28+
module: {
29+
rules: [
30+
{
31+
test: /\.js$/,
32+
exclude: /node_modules/,
33+
use: {
34+
loader: 'babel-loader'
35+
}
36+
},
37+
{
38+
test: /\.css$/,
39+
use: [
40+
MiniCssExtractPlugin.loader,
41+
'css-loader',
42+
{
43+
loader: 'postcss-loader',
44+
options: {
45+
config: {
46+
path: './postcss.config.js'
47+
}
4148
}
4249
}
43-
}
44-
]
45-
}
50+
],
51+
}
52+
]
53+
},
54+
plugins: [
55+
new MiniCssExtractPlugin({ filename: '../css/app.css' }),
56+
new CopyWebpackPlugin([{ from: 'static/', to: '../' }])
4657
]
47-
},
48-
plugins: [
49-
new MiniCssExtractPlugin({ filename: '../css/app.css' }),
50-
new CopyWebpackPlugin([{ from: 'static/', to: '../' }])
51-
]
52-
});
58+
.concat(devMode ? [new HardSourceWebpackPlugin()] : [])
59+
}
60+
};

assets/yarn.lock

Lines changed: 68 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,6 +1647,11 @@ detect-file@^1.0.0:
16471647
resolved "https://registry.yarnpkg.com/detect-file/-/detect-file-1.0.0.tgz#f0d66d03672a825cb1b73bdb3fe62310c8e552b7"
16481648
integrity sha1-8NZtA2cqglyxtzvbP+YjEMjlUrc=
16491649

1650+
detect-indent@^5.0.0:
1651+
version "5.0.0"
1652+
resolved "https://registry.yarnpkg.com/detect-indent/-/detect-indent-5.0.0.tgz#3871cc0a6a002e8c3e5b3cf7f336264675f06b9d"
1653+
integrity sha1-OHHMCmoALow+Wzz38zYmRnXwa50=
1654+
16501655
detect-libc@^1.0.2:
16511656
version "1.0.3"
16521657
resolved "https://registry.yarnpkg.com/detect-libc/-/detect-libc-1.0.3.tgz#fa137c4bd698edf55cd5cd02ac559f91a4c4ba9b"
@@ -2176,6 +2181,25 @@ graceful-fs@^4.1.11, graceful-fs@^4.1.15, graceful-fs@^4.1.2, graceful-fs@^4.1.6
21762181
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.3.tgz#4a12ff1b60376ef09862c2093edd908328be8423"
21772182
integrity sha512-a30VEBm4PEdx1dRB7MFK7BejejvCvBronbLjht+sHuGYj8PHs7M/5Z+rt5lw551vZ7yfTCj4Vuyy3mSJytDWRQ==
21782183

2184+
hard-source-webpack-plugin@^0.13.1:
2185+
version "0.13.1"
2186+
resolved "https://registry.yarnpkg.com/hard-source-webpack-plugin/-/hard-source-webpack-plugin-0.13.1.tgz#a99071e25b232f1438a5bc3c99f10a3869e4428e"
2187+
integrity sha512-r9zf5Wq7IqJHdVAQsZ4OP+dcUSvoHqDMxJlIzaE2J0TZWn3UjMMrHqwDHR8Jr/pzPfG7XxSe36E7Y8QGNdtuAw==
2188+
dependencies:
2189+
chalk "^2.4.1"
2190+
find-cache-dir "^2.0.0"
2191+
graceful-fs "^4.1.11"
2192+
lodash "^4.15.0"
2193+
mkdirp "^0.5.1"
2194+
node-object-hash "^1.2.0"
2195+
parse-json "^4.0.0"
2196+
pkg-dir "^3.0.0"
2197+
rimraf "^2.6.2"
2198+
semver "^5.6.0"
2199+
tapable "^1.0.0-beta.5"
2200+
webpack-sources "^1.0.1"
2201+
write-json-file "^2.3.0"
2202+
21792203
has-flag@^3.0.0:
21802204
version "3.0.0"
21812205
resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-3.0.0.tgz#b5d454dc2199ae225699f3467e5a07f3b955bafd"
@@ -2572,6 +2596,11 @@ is-obj@^1.0.0:
25722596
resolved "https://registry.yarnpkg.com/is-obj/-/is-obj-1.0.1.tgz#3e4729ac1f5fde025cd7d83a896dab9f4f67db0f"
25732597
integrity sha1-PkcprB9f3gJc19g6iW2rn09n2w8=
25742598

2599+
is-plain-obj@^1.0.0:
2600+
version "1.1.0"
2601+
resolved "https://registry.yarnpkg.com/is-plain-obj/-/is-plain-obj-1.1.0.tgz#71a50c8429dfca773c92a390a4a03b39fcd51d3e"
2602+
integrity sha1-caUMhCnfync8kqOQpKA7OfzVHT4=
2603+
25752604
is-plain-object@^2.0.3, is-plain-object@^2.0.4:
25762605
version "2.0.4"
25772606
resolved "https://registry.yarnpkg.com/is-plain-object/-/is-plain-object-2.0.4.tgz#2c163b3fafb1b606d9d17928f05c2a1c38e07677"
@@ -2785,7 +2814,7 @@ lodash.uniq@^4.5.0:
27852814
resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773"
27862815
integrity sha1-0CJTc662Uq3BvILklFM5qEJ1R3M=
27872816

2788-
lodash@^4.17.11, lodash@^4.17.13, lodash@^4.17.5:
2817+
lodash@^4.15.0, lodash@^4.17.11, lodash@^4.17.13, lodash@^4.17.5:
27892818
version "4.17.21"
27902819
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
27912820
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==
@@ -3109,6 +3138,11 @@ node-libs-browser@^2.0.0:
31093138
util "^0.11.0"
31103139
vm-browserify "^1.0.1"
31113140

3141+
node-object-hash@^1.2.0:
3142+
version "1.4.2"
3143+
resolved "https://registry.yarnpkg.com/node-object-hash/-/node-object-hash-1.4.2.tgz#385833d85b229902b75826224f6077be969a9e94"
3144+
integrity sha512-UdS4swXs85fCGWWf6t6DMGgpN/vnlKeSGEQ7hJcrs7PBFoxoKLmibc3QRb7fwiYsjdL7PX8iI/TMSlZ90dgHhQ==
3145+
31123146
node-pre-gyp@^0.12.0:
31133147
version "0.12.0"
31143148
resolved "https://registry.yarnpkg.com/node-pre-gyp/-/node-pre-gyp-0.12.0.tgz#39ba4bb1439da030295f899e3b520b7785766149"
@@ -4295,10 +4329,10 @@ shebang-regex@^1.0.0:
42954329
resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-1.0.0.tgz#da42f49740c0b42db2ca9728571cb190c98efea3"
42964330
integrity sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=
42974331

4298-
signal-exit@^3.0.0:
4299-
version "3.0.2"
4300-
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"
4301-
integrity sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=
4332+
signal-exit@^3.0.0, signal-exit@^3.0.2:
4333+
version "3.0.4"
4334+
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.4.tgz#366a4684d175b9cab2081e3681fda3747b6c51d7"
4335+
integrity sha512-rqYhcAnZ6d/vTPGghdrw7iumdcbXpsk1b8IG/rz+VWV51DM0p7XCtMoJ3qhPLIbp3tvyt3pKRbaaEMZYpHto8Q==
43024336

43034337
simple-swizzle@^0.2.2:
43044338
version "0.2.2"
@@ -4342,6 +4376,13 @@ snapdragon@^0.8.1:
43424376
source-map-resolve "^0.5.0"
43434377
use "^3.1.0"
43444378

4379+
sort-keys@^2.0.0:
4380+
version "2.0.0"
4381+
resolved "https://registry.yarnpkg.com/sort-keys/-/sort-keys-2.0.0.tgz#658535584861ec97d730d6cf41822e1f56684128"
4382+
integrity sha1-ZYU1WEhh7JfXMNbPQYIuH1ZoQSg=
4383+
dependencies:
4384+
is-plain-obj "^1.0.0"
4385+
43454386
source-list-map@^2.0.0:
43464387
version "2.0.1"
43474388
resolved "https://registry.yarnpkg.com/source-list-map/-/source-list-map-2.0.1.tgz#3993bd873bfc48479cca9ea3a547835c7c154b34"
@@ -4601,7 +4642,7 @@ tailwindcss@^1.1.2:
46014642
pretty-hrtime "^1.0.3"
46024643
reduce-css-calc "^2.1.6"
46034644

4604-
tapable@^1.0.0:
4645+
tapable@^1.0.0, tapable@^1.0.0-beta.5:
46054646
version "1.1.3"
46064647
resolved "https://registry.yarnpkg.com/tapable/-/tapable-1.1.3.tgz#a1fccc06b58db61fd7a45da2da44f5f3a3e67ba2"
46074648
integrity sha512-4WK/bYZmj8xLr+HUCODHGF1ZFzsYffasLUgEiMBY4fgtltdO6B4WJtlSbPaDTLpYTcGVwM2qLnFTICEcNxs3kA==
@@ -4976,6 +5017,27 @@ wrappy@1:
49765017
resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"
49775018
integrity sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=
49785019

5020+
write-file-atomic@^2.0.0:
5021+
version "2.4.3"
5022+
resolved "https://registry.yarnpkg.com/write-file-atomic/-/write-file-atomic-2.4.3.tgz#1fd2e9ae1df3e75b8d8c367443c692d4ca81f481"
5023+
integrity sha512-GaETH5wwsX+GcnzhPgKcKjJ6M2Cq3/iZp1WyY/X1CSqrW+jVNM9Y7D8EC2sM4ZG/V8wZlSniJnCKWPmBYAucRQ==
5024+
dependencies:
5025+
graceful-fs "^4.1.11"
5026+
imurmurhash "^0.1.4"
5027+
signal-exit "^3.0.2"
5028+
5029+
write-json-file@^2.3.0:
5030+
version "2.3.0"
5031+
resolved "https://registry.yarnpkg.com/write-json-file/-/write-json-file-2.3.0.tgz#2b64c8a33004d54b8698c76d585a77ceb61da32f"
5032+
integrity sha1-K2TIozAE1UuGmMdtWFp3zrYdoy8=
5033+
dependencies:
5034+
detect-indent "^5.0.0"
5035+
graceful-fs "^4.1.2"
5036+
make-dir "^1.0.0"
5037+
pify "^3.0.0"
5038+
sort-keys "^2.0.0"
5039+
write-file-atomic "^2.0.0"
5040+
49795041
xtend@^4.0.0, xtend@~4.0.1:
49805042
version "4.0.2"
49815043
resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.2.tgz#bb72779f5fa465186b1f438f674fa347fdb5db54"

config/config.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use Mix.Config
1111
config :elixir_console, ElixirConsoleWeb.Endpoint,
1212
url: [host: "localhost"],
1313
secret_key_base: "xkn0Oy0t0ydkJkKxKwFVJ36lc5MX7kHtdo+4vtEVqGrBNN/Kv4a9GIGqbx6CHlVw",
14-
render_errors: [view: ElixirConsoleWeb.ErrorView, accepts: ~w(html json)],
14+
render_errors: [view: ElixirConsoleWeb.ErrorView, accepts: ~w(html json), layout: false],
1515
pubsub_server: ElixirConsole.PubSub,
1616
live_view: [signing_salt: "7vohZO+j"]
1717

config/dev.exs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,8 @@ config :elixir_console, ElixirConsoleWeb.Endpoint,
5050
live_reload: [
5151
patterns: [
5252
~r"priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$",
53-
~r"priv/gettext/.*(po)$",
54-
~r"lib/elixir_console_web/{live,views}/.*(ex)$",
55-
~r"lib/elixir_console_web/templates/.*(eex)$",
56-
~r{lib/live_view/live/.*(ex)$}
53+
~r"lib/elixir_console_web/(live|views)/.*(ex)$",
54+
~r"lib/elixir_console_web/templates/.*(eex)$"
5755
]
5856
]
5957

0 commit comments

Comments
 (0)