我正在尝试在nuxt.js(版本2)项目的server
目录中转换代码。我修改了config.nuxt.js
来在服务器目录中转换.js文件:
const pkg = require('./package')
const util = require('util')
module.exports = {
mode: 'universal',
/*
** Router config
*/
// router: {
// middleware: 'check-auth'
// },
/*
** Headers of the page
*/
head: {
title: pkg.name,
meta: [
{ charset: 'utf-8' },
{
name: 'viewport',
content: 'width=device-width, initial-scale=1, viewport-fit=cover'
},
{ hid: 'description', name: 'description', content: pkg.description },
{ name: 'application-name', content: '' },
{ name: 'msapplication-TileColor', content: '#000000' },
{
name: 'msapplication-TileImage',
content: 'https://www.thejump.tech/mstile-144x144.png'
},
{
name: 'msapplication-square70x70logo',
content: 'https://www.thejump.tech/mstile-70x70.png'
},
{
name: 'msapplication-square150x150logo',
content: 'https://www.thejump.tech/mstile-150x150.png'
},
{
name: 'msapplication-wide310x150logo',
content: 'https://www.thejump.tech/mstile-310x150.png'
},
{
name: 'msapplication-square310x310logo',
content: 'https://www.thejump.tech/mstile-310x310.png'
}
],
link: [
{
rel: 'icon',
type: 'image/x-icon',
href: 'https://www.thejump.tech/favicon.ico'
},
{
rel: 'apple-touch-icon-precomposed',
sizes: '57x57',
href: 'https://www.thejump.tech/apple-touch-icon-57x57.png'
},
{
rel: 'apple-touch-icon-precomposed',
sizes: '114x114',
href: 'https://www.thejump.tech/apple-touch-icon-114x114.png'
},
{
rel: 'apple-touch-icon-precomposed',
sizes: '72x72',
href: 'https://www.thejump.tech/apple-touch-icon-72x72.png'
},
{
rel: 'apple-touch-icon-precomposed',
sizes: '144x144',
href: 'https://www.thejump.tech/apple-touch-icon-144x144.png'
},
{
rel: 'apple-touch-icon-precomposed',
sizes: '60x60',
href: 'https://www.thejump.tech/apple-touch-icon-60x60.png'
},
{
rel: 'apple-touch-icon-precomposed',
sizes: '120x120',
href: 'https://www.thejump.tech/apple-touch-icon-120x120.png'
},
{
rel: 'apple-touch-icon-precomposed',
sizes: '76x76',
href: 'https://www.thejump.tech/apple-touch-icon-76x76.png'
},
{
rel: 'apple-touch-icon-precomposed',
sizes: '152x152',
href: 'https://www.thejump.tech/apple-touch-icon-152x152.png'
},
{
rel: 'icon',
type: 'image/png',
href: 'https://www.thejump.tech/favicon-196x196.png',
sizes: '196x196'
},
{
rel: 'icon',
type: 'image/png',
href: 'https://www.thejump.tech/favicon-96x96.png',
sizes: '96x96'
},
{
rel: 'icon',
type: 'image/png',
href: 'https://www.thejump.tech/favicon-32x32.png',
sizes: '32x32'
},
{
rel: 'icon',
type: 'image/png',
href: 'https://www.thejump.tech/favicon-16x16.png',
sizes: '16x16'
},
{
rel: 'icon',
type: 'image/png',
href: 'https://www.thejump.tech/favicon-128.png',
sizes: '128x128'
},
{
rel: 'stylesheet',
href:
'https://fonts.googleapis.com/css?family=Roboto:300,400,500,700|Material+Icons'
}
]
},
/*
** Customize the progress-bar color
*/
loading: { color: '#fff' },
/*
** Global CSS
*/
css: ['normalize.css', '~/assets/style/app.styl'],
/*
** Plugins to load before mounting the App
*/
plugins: [
'@/plugins/vuetify',
'@/plugins/gmap',
{ src: '@/plugins/vue-awesome-swiper', ssr: false }
],
/*
** Nuxt.js modules
*/
modules: [
// Doc: https://github.com/nuxt-community/axios-module#usage
'@nuxtjs/axios',
'@nuxtjs/dotenv',
'@nuxtjs/apollo',
[
'nuxt-sass-resources-loader',
[
'assets/scss/helpers.scss',
'assets/scss/spacing.scss',
'assets/scss/fonts.scss'
]
]
],
/*
** Axios module configuration
*/
axios: {
// See https://github.com/nuxt-community/axios-module#options
},
/*
** Apollo module configuration (See https://www.npmjs.com/package/@nuxtjs/apollo)
*/
apollo: {
clientConfigs: {
default: {
httpEndpoint: 'http://localhost:4000'
}
}
},
/*
** Build configuration
*/
build: {
/*
** You can extend webpack config here
*/
// babel: {
// presets: ['es2015', 'stage-0']
// },
transpile: [
/^vue2-google-maps($|\/)/,
'/server/**/*.js'
// /^\/?server\/(?:(?!\/)(?:.|\n))*(?:(?!\.js)(?:.|\n))*\.js$/
],
extend(config, ctx) {
config.node = {
fs: 'empty'
}
// Run ESLint on save
if (ctx.isDev && ctx.isClient) {
config.module.rules.push({
enforce: 'pre',
test: /\.(js|vue)$/,
loader: 'eslint-loader',
exclude: /(node_modules)/
})
}
}
}
}
但我不断收到错误消息:
(function (exports, require, module, __filename, __dirname) { import mongoose from 'mongoose'
^^^^^^^^
SyntaxError: Unexpected identifier
at new Script (vm.js:80:7)
at createScript (vm.js:264:10)
at Object.runInThisContext (vm.js:316:10)
at Module._compile (internal/modules/cjs/loader.js:670:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:718:10)
at Module.load (internal/modules/cjs/loader.js:605:32)
at tryModuleLoad (internal/modules/cjs/loader.js:544:12)
at Function.Module._load (internal/modules/cjs/loader.js:536:3)
at Module.require (internal/modules/cjs/loader.js:643:17)
at require (internal/modules/cjs/helpers.js:22:18)
[nodemon] app crashed - waiting for file changes before starting...
...这意味着它没有被编译。
有人知道我在这里干什么吗?