I've been noticing a strange problem in my dockerised development environment, where the javascript assets result in a 404 error as the webpacker manifest.json is pointing to a pack that does not exist.
(我一直在dockerized开发环境中注意到一个奇怪的问题,因为webpacker manifest.json指向一个不存在的包,因此javascript资产导致404错误。)
I've documented the problem which arises after a rebuild of the Docker container.
(我已经记录了重建Docker容器后出现的问题。)
In all cases below I am referring to the hashed version of admin.js
(在下面的所有情况下,我指的是admin.js
的哈希版本)
Initial state with javascript assets loading as expected:
(符合预期的javascript资产载入状态:)
public/packs/manifest.json
"admin.js": "/packs/admin-xxxxxxc629.js",
the file ending c629.js
is present in public/packs
(在public/packs
存在以c629.js
结尾的文件)
If I now rebuild Docker containers with docker-compose up --build
(如果我现在使用docker-compose up --build
重建Docker容器)
I get the following output in the logs:
(我在日志中得到以下输出:)
With the hash now ending e105
and the manifest.json updated accordingly
(随着哈希现在结束, e105
并相应地更新了manifest.json)
public/packs/manifest.json
"admin.js": "/packs/admin-xxxxxxe105.js",
the file ending e105.js
is NOT present in public/packs
and so when I refresh the browser I get a 404 error for the admin-xxxxxxe105.js file.
(public/packs
不存在以e105.js
结尾的文件,因此当我刷新浏览器时,admin-xxxxxxe105.js文件出现404错误。)
This section may be a red herring or may be a clue:
(本节可能是红色鲱鱼,也可能是线索:)
I feel that my normal webpacker flow is a bit odd as changes to the original admin.js file result in webpacker compilation that updates the manifest.json but does not create the corresponding file in public/packs
(我觉得我的正常webpacker流程有点奇怪,因为对原始admin.js文件的更改导致webpacker编译会更新manifest.json,但不会在public / packs中创建相应的文件)
This doesn't cause a problem as when I refresh the browser it triggers another compile that then refreshes manifest.json with a new hashed version and also creates the file in public/packs
(这不会造成问题,因为当我刷新浏览器时,它会触发另一个编译,然后使用新的哈希版本刷新manifest.json并在public / packs中创建文件)
I'm only left with the stranded e105.js after a docker rebuild.
(码头工人重建后,我只剩下滞留的e105.js.)
Here's my docker-compose.yml
file
(这是我docker-compose.yml
文件)
version: '3'
services:
webpacker:
build: .
environment:
- WEBPACKER_DEV_SERVER_PUBLIC=localhost:3035
- WEBPACKER_DEV_SERVER_HOST=localhost
command: ./bin/webpack-dev-server --inline true
volumes:
- .:/myapp
ports:
- '3035:3035'
db:
image: postgres
ports:
- "5433:5432"
volumes:
- ./tmp/db:/var/lib/postgresql/data
web:
build: .
environment:
- RAILS_ENV=development
- NODE_ENV=development
command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
volumes:
- .:/myapp
ports:
- "3000:3000"
depends_on:
- db
- redis
- webpacker
#- elasticsearch
redis:
image: redis:alpine
and here is my Dockerfile:
(这是我的Dockerfile:)
FROM ruby:2.3.7
ENV BUNDLER_VERSION=1.17.3
RUN gem install bundler -v "$BUNDLER_VERSION" --no-document
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash -
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
RUN apt-get update -qq && apt-get install -y nodejs yarn build-essential libpq-dev postgresql-client
RUN mkdir /myapp
WORKDIR /myapp
COPY Gemfile /myapp/Gemfile
COPY Gemfile.lock /myapp/Gemfile.lock
ENV RAILS_ENV docker
ENV WEBPACKER_DEV_SERVER_PUBLIC localhost:3035
ENV WEBPACKER_DEV_SERVER_HOST localhost
RUN git config --global url."https://github.com/".insteadOf git@github.com:
RUN git config --global url."https://".insteadOf git://
COPY package.json *yarn* ./
RUN bundle install
RUN yarn install
COPY . /myapp
# Add a script to be executed every time the container starts.
COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
EXPOSE 3000
# Start the main process.
CMD ["rails", "server", "-b", "0.0.0.0"]
and this is docker section of my webpacker.yml:
(这是我的webpacker.yml的docker部分:)
docker:
<<: *default
compile: true
# Verifies that versions and hashed value of the package contents in the project's package.json
check_yarn_integrity: false
# Reference: https://webpack.js.org/configuration/dev-server/
dev_server:
https: false
host: webpacker
port: 3035
public: localhost:3035
hmr: true
# Inline should be set to true if using HMR
inline: true
overlay: true
compress: true
disable_host_check: true
use_local_ip: false
quiet: false
headers:
'Access-Control-Allow-Origin': '*'
watch_options:
ignored: /node_modules/
I've got no idea how my Docker container keeps holding on to this reference to admin-xxxxxxe105.js
and would ideally like to fix my dev environment so that I don't have to force a change to admin.js everytime I rebuild a container.
(我不知道我的Docker容器如何继续保持对admin-xxxxxxe105.js
引用,并且理想情况下是要修复我的开发环境,这样我每次重建A时都不必强制更改admin.js。容器。)
ask by whatapalaver translate from so