Skip to content

Commit b3e6fa3

Browse files
Configure webpack to run properly in docker environment
1 parent c53263d commit b3e6fa3

File tree

5 files changed

+39
-8
lines changed

5 files changed

+39
-8
lines changed

.env

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
ASSET_HOST=localhost:3000
1+
ASSET_HOST=localhost:8080
22
APPLICATION_HOST=localhost:3000
33
PORT=3000
44
SECRET_KEY_BASE=development_secret
55
SMTP_ADDRESS=smtp.example.com
66
SMTP_DOMAIN=example.com
77
SMTP_PASSWORD=password
88
SMTP_USERNAME=username
9+
DEV_SERVER_URL=http://locahost:8080
10+
NODE_ENV=development
911

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<title>App</title>
4+
<title><%= yield :title %></title>
55
<%= csrf_meta_tags %>
66

7-
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
8-
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
7+
<%= stylesheet_link_tag 'application', media: 'all' %>
98
</head>
109

1110
<body>
1211
<%= yield %>
12+
<%= javascript_include_tag 'application' %>
13+
<%= javascript_pack_tag 'application' %>
1314
</body>
1415
</html>

config/webpack/configuration.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@ const { env } = require('process')
55
const { safeLoad } = require('js-yaml')
66
const { readFileSync } = require('fs')
77

8+
const defaultPaths = require('./paths');
9+
810
const configPath = resolve('config', 'webpack')
911
const loadersDir = join(__dirname, 'loaders')
10-
const paths = safeLoad(readFileSync(join(configPath, 'paths.yml'), 'utf8'))[env.NODE_ENV]
12+
const customPaths = safeLoad(readFileSync(join(configPath, 'paths.yml'), 'utf8'))[env.NODE_ENV]
13+
const paths = customPaths ? customPaths : defaultPaths
1114
const devServer = safeLoad(readFileSync(join(configPath, 'development.server.yml'), 'utf8'))[env.NODE_ENV]
1215

1316
// Compute public path based on environment and ASSET_HOST in production
1417
const ifHasCDN = env.ASSET_HOST !== undefined && env.NODE_ENV === 'production'
15-
const devServerUrl = `http://${devServer.host}:${devServer.port}/${paths.entry}/`
18+
const defaultServerUrl = devServer ? `http://${devServer.host}:${devServer.port}` : env.DEV_SERVER_URL
19+
const devServerUrl = `${defaultServerUrl}/${paths.entry}/`
1620
const publicUrl = ifHasCDN ? `${env.ASSET_HOST}/${paths.entry}/` : `/${paths.entry}/`
1721
const publicPath = env.NODE_ENV !== 'production' ? devServerUrl : publicUrl
1822

config/webpack/paths.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module.exports = {
2+
config: 'config/webpack',
3+
entry: 'packs',
4+
output: 'public',
5+
manifest: 'manifest.json',
6+
node_modules: 'node_modules',
7+
source: 'app/javascript',
8+
extensions:
9+
[
10+
'.coffee',
11+
'.js',
12+
'.jsx',
13+
'.sass',
14+
'.scss',
15+
'.css',
16+
'.png',
17+
'.svg',
18+
'.gif',
19+
'.jpeg',
20+
'.jpg'
21+
]
22+
}

docker-compose.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ services:
2626

2727
webpack:
2828
image: jmfirth/webpack
29-
command: webpack-dev-server --hot --inline --progress --host 0.0.0.0 --config config/webpack.config.js
29+
command: webpack-dev-server --hot --inline --progress --color --host 0.0.0.0 --config config/webpack/development.js
3030
ports:
31-
- '3808:3808'
31+
- '8080:8080'
3232
volumes:
3333
- .:/app
34+
env_file:
35+
- .env
3436

3537
volumes:
3638
bundle_path:

0 commit comments

Comments
 (0)