Webpack不会生成build.js

我将我的代码库移动到了dockerformat。

我有一个docker-compose文件,命令如下: command: bash -c "rm -rf node_modules && npm install && npm run dev"

和一切工作正常,我使用rm -rf node_modules因为它给我一些丢失包(从我的MAC)的错误。 这样做只是得到重新创build,并在本地主机上正常工作。

我也添加了卷,所以当我改变我的代码中的东西时,它会反映在我的容器中,这也可以正常工作(除了热重载,但这不是什么大不了的)。

现在我通常只是在我的docker-compose文件中注释掉以下command: bash -c "rm -rf node_modules && npm install && npm run dev"行: command: bash -c "rm -rf node_modules && npm install && npm run dev" ,而是添加: command: bash -c "rm -rf node_modules && npm install && npm run build"来build立我的包,所以在生产中我根本没有节点,但是这没有给我任何结果。

我不确定这是否是卷的问题,也就是说,它是在容器中构build的,但是我无法从我的机器上访问它(我不认为这是因为在本地机器中更改代码会反映到我的容器中)或者出于某种原因,它根本就没有build成。

这是command: bash -c "rm -rf node_modules && npm install && npm run build --verbose"的输出command: bash -c "rm -rf node_modules && npm install && npm run build --verbose"

 NODE | npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.1.3 (node_modules/fsevents): NODE | npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.3: 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 npm@5.5.1 NODE | npm info using node@v9.2.0 NODE | npm verb run-script [ 'prebuild', 'build', 'postbuild' ] NODE | npm info lifecycle frontend@1.0.0~prebuild: frontend@1.0.0 NODE | npm info lifecycle frontend@1.0.0~build: frontend@1.0.0 NODE | NODE | > frontend@1.0.0 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 frontend@1.0.0~build: unsafe-perm in lifecycle true NODE | npm verb lifecycle frontend@1.0.0~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 frontend@1.0.0~build: CWD: /code/client NODE | npm info lifecycle frontend@1.0.0~postbuild: frontend@1.0.0 NODE | npm verb exit [ 0, true ] NODE | npm info ok 

而我的webpack conf文件就是这样开始的:

 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' }, 

至less之前工作正常,因为我的应用程序看起来像这样:

 - manage.py - static - dist - others - client - webpack.config.js 

等等

为什么没有build立起来呢?

更新

我使用exec来查看容器内部。 我无法在任何地方findbuild.js。 我也在/ code / static / dist里面运行了touch abc.txt,它也在我的本地主机上创build,也就是说,卷工作正常。它一定是webpack的问题,而不是docker。

更新2

我也尝试了这样的完整path,仍然没有:

 module.exports = { entry: './src/main.js', output: { path: path.resolve(__dirname, '/code/static/dist'), publicPath: '/dist/', filename: 'build.js' }, 

编辑3

我试图寻找build.js我发现这些文件,但我认为这些不是我的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 

您缺lessvarpath声明。 但是webpack应该没有它,所以不知道这是否是原因。

 var path = require('path'); 

尝试从path中删除/dist/ 。 它在我的机器上工作。

 module.exports = { entry: './src/main.js', output: { path: path.resolve(__dirname, '../static'), publicPath: '/dist/', filename: 'build.js' }, 

你的路是错的 您可以从您的项目目录中构build您的build.js文件。

只要改变这个:

path: path.resolve(__dirname, 'static/dist')