我有一个nuxt-community/starter-template
最少添加的项目。我package.json
看起来像这样
{
// ...
"scripts": {
"dev": "nuxt",
"build": "nuxt build",
"docker-image": "nuxt build && docker build -t unijobs-www-temp .",
"start": "nuxt start",
"generate": "NODE_ENV=production nuxt generate",
"lint": "eslint --ext .js,.vue --ignore-path .gitignore .",
"precommit": "npm run lint"
},
"dependencies": {
"@fortawesome/fontawesome": "^1.1.8",
"@fortawesome/fontawesome-free-brands": "^5.0.13",
"@fortawesome/fontawesome-free-regular": "^5.0.13",
"@fortawesome/fontawesome-free-solid": "^5.0.13",
"@fortawesome/vue-fontawesome": "0.0.22",
"nuxt": "^1.0.0",
"nuxt-fontawesome": "^0.2.0",
"node-sass": "^4.9.0",
"sass-loader": "^7.0.2"
},
"devDependencies": {
"babel-eslint": "^8.2.1",
"eslint": "^4.15.0",
"eslint-friendly-formatter": "^3.0.0",
"eslint-loader": "^1.7.1",
"eslint-plugin-vue": "^4.0.0"
}
}
本地开发看起来不错,在本地build
也start
可以正常工作。但是,当我构建Docker映像时,一切都朝南。
请注意,这不是Docker的问题,如果我在自己的计算机上的新目录中运行等效步骤,也是如此。
FROM node:stretch
ENV NODE_ENV=production
ENV HOST=0.0.0.0
EXPOSE 3000
RUN npm -g i nuxt
RUN mkdir -p /app
ADD .nuxt /app/.nuxt
ADD static /app/static
WORKDIR /app
CMD ["nuxt", "start"]
这是我在日志中找到的:
2018-06-05T12:27:19.910Z nuxt:render Rendering url /
{ Error: Cannot find module 'core-js/library/fn/promise' from '/app'
at Function.module.exports [as sync] (/usr/local/lib/node_modules/nuxt/node_modules/resolve/lib/sync.js:42:15)
at r (/usr/local/lib/node_modules/nuxt/node_modules/vue-server-renderer/build.js:8332:44)
at Object.<anonymous> (server-bundle.js:1429:18)
at __webpack_require__ (server-bundle.js:27:30)
at Object.module.exports.module.exports (server-bundle.js:105:31)
at __webpack_require__ (server-bundle.js:27:30)
at Object.<anonymous> (server-bundle.js:1218:138)
at __webpack_require__ (server-bundle.js:27:30)
at server-bundle.js:92:18
at Object.<anonymous> (server-bundle.js:95:10)
at evaluateModule (/usr/local/lib/node_modules/nuxt/node_modules/vue-server-renderer/build.js:8338:21)
at /usr/local/lib/node_modules/nuxt/node_modules/vue-server-renderer/build.js:8396:18
at new Promise (<anonymous>)
at /usr/local/lib/node_modules/nuxt/node_modules/vue-server-renderer/build.js:8388:14
at Object.renderToString (/usr/local/lib/node_modules/nuxt/node_modules/vue-server-renderer/build.js:8564:9)
at Renderer.renderRoute (/usr/local/lib/node_modules/nuxt/lib/core/renderer.js:344:41)
code: 'MODULE_NOT_FOUND',
statusCode: 500,
name: 'NuxtServerError' }
然而,这一切,只要我插上消失node_modules
的,旁边.nuxt
和static
目录。似乎某些模块未捆绑在一起。我的nuxt.config.js
档案就像
module.exports = {
head: {
// Skipping noise...
},
modules: [
[ 'nuxt-fontawesome', {
component: 'fa',
imports: [
{ set: '@fortawesome/fontawesome-free-brands' },
]
}],
],
loading: { color: '#3B8070' },
build: {
extend (config, { isDev, isClient }) {
if (isDev && isClient) {
config.module.rules.push({
enforce: 'pre',
test: /\.(js|vue)$/,
loader: 'eslint-loader',
exclude: /(node_modules)/
})
// *** NOTE: In practice, I'm only using FA brands here, not the others ***
config.resolve.alias['@fortawesome/fontawesome-free-brands$'] = '@fortawesome/fontawesome-free-brands/shakable.es.js'
}
}
}
}
难道我做错了什么?
我发现Nuxt构建不会在node_modules中捆绑文件,因此如果要将所有依赖项捆绑到
.nuxt
,则应该使用nuxt build --standalone
。看到这里:https : //github.com/nuxt/nuxt.js/issues/4292
希望对你有帮助 :)