I moved my codebase to a dockerformat.
I have a docker-compose file with the command:
command: bash -c "rm -rf node_modules && npm install && npm run dev"
and everything works fine, I use rm -rf node_modules
because it gives me some errors of missing packages (from my MAC). Doing that it just gets recreated and it works ok on localhost.
I've also added volumes, so when I change something in my code it gets reflected in my container, this also works fine (apart of the hot-reload, but that's not a big deal).
Now I usually just comment out the line: command: bash -c "rm -rf node_modules && npm install && npm run dev"
on my docker-compose file and instead I add:
command: bash -c "rm -rf node_modules && npm install && npm run build"
to build my bundle, so that in production I don't have node at all, however this gives me no results.
I'm not sure if it's a problem with volumes, i.e. it gets built in the container but I can't access it from my machine (which I don't think because changing code in my local machine does get reflected in my container) or it doesn't get built at all for some reason.
This is the output of command: bash -c "rm -rf node_modules && npm install && npm run build --verbose"
NODE | npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
NODE | npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
NODE |
NODE | added 115 packages in 11.036s
NODE | npm info it worked if it ends with ok
NODE | npm verb cli [ '/usr/local/bin/node',
NODE | npm verb cli '/usr/local/bin/npm',
NODE | npm verb cli 'run',
NODE | npm verb cli 'build',
NODE | npm verb cli '--verbose' ]
NODE | npm info using [email protected]
NODE | npm info using [email protected]
NODE | npm verb run-script [ 'prebuild', 'build', 'postbuild' ]
NODE | npm info lifecycle [email protected]~prebuild: [email protected]
NODE | npm info lifecycle [email protected]~build: [email protected]
NODE |
NODE | > [email protected] build /code/client
NODE | > cross-env NODE_ENV=production webpack --progress --hide-modules
NODE |
NODE | Hash: cda5e46c2c7f4ba2903b
NODE | Version: webpack 3.9.1
NODE | Time: 27298ms
NODE | Asset Size Chunks Chunk Names
NODE | build.js 1.29 MB 0 [emitted] [big] main
NODE | build.js.map 7.65 MB 0 [emitted] main
NODE | npm verb lifecycle [email protected]~build: unsafe-perm in lifecycle true
NODE | npm verb lifecycle [email protected]~build: PATH: /usr/local/lib/node_modules/npm/bin/node-gyp-bin:/code/client/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
NODE | npm verb lifecycle [email protected]~build: CWD: /code/client
NODE | npm info lifecycle [email protected]~postbuild: [email protected]
NODE | npm verb exit [ 0, true ]
NODE | npm info ok
And my webpack conf file starts like this:
var path = require('path')
var webpack = require('webpack')
module.exports = {
entry: './src/main.js',
output: {
path: path.resolve(__dirname, '../static/dist/'),
publicPath: '/dist/',
filename: 'build.js'
},
Which at least before worked fine since my app looks like this:
- manage.py
- static
- dist
- others
- client
- webpack.config.js
etc
Why nothing gets build in dist?
I used exec to look inside the container. I can't find the build.js anywhere. I also run touch abc.txt inside /code/static/dist and it gets also created on my localhost, i.e. the volumes work fine.It must be a problem of webpack and not docker.
I've also tried the full path like this, still nothing:
module.exports = {
entry: './src/main.js',
output: {
path: path.resolve(__dirname, '/code/static/dist'),
publicPath: '/dist/',
filename: 'build.js'
},
I've tried to look for build.js I found these files, but I think that those are not my build.js:
root@0xxxxxx:/code# find . -name build.js
./client/node_modules/node-forge/nodejs/build.js
./client/node_modules/errno/build.js
./client/node_modules/vue-template-compiler/build.js
./client/node_modules/builtin-status-codes/build.js
./client/node_modules/webpack-dev-middleware/node_modules/mime/src/build.js
./client/node_modules/node-gyp/lib/build.js
./client/node_modules/node-sass/scripts/build.js
./client/node_modules/mime/build/build.js
./client/node_modules/npm/node_modules/node-gyp/lib/build.js
./client/node_modules/npm/node_modules/sorted-union-stream/node_modules/from2/node_modules/readable-stream/node_modules/isarray/build/build.js
./client/node_modules/npm/lib/install/action/build.js
./client/node_modules/npm/lib/build.js
Your path is wrong. You build your build.js
file out of your project directory.
Just change to this:
path: path.resolve(__dirname, 'static/dist')
I managed to solve this. I was trying hundreds of things, so I'm not entirely sure if this made the trick, but creating a new file and posting my docker-compose on it made it work. I think its possibly related to file permissions. Check those if you get this error.
You are missing var path declaration. But webpack should be crushing without it, so not sure if that's the reason.
var path = require('path');
Try removing /dist/
from path. It works on my machine.
module.exports = {
entry: './src/main.js',
output: {
path: path.resolve(__dirname, '../static'),
publicPath: '/dist/',
filename: 'build.js'
},
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With