工程配置
nuxt.config.js
/**
* Nuxt工程配置文件
* 修改该配置文件后,需重启工程才能生效
*/
const package = require('./package.json')
// --------------------------------------------------
// 当前环境变量
const env = process.env
// 基础路由(二级路由)
const BASE_ROUTE = '/test-front-template-b'
// 开发过程的接口域名
const SERVER_URL = 'http://pai.flyrise.cn'
// 接口前缀
const REQUEST_BASE_URL = env.NODE_ENV === 'development' ? '/api' : ``
// const SERVER_URL_IOT = 'http://jetlinks-api.pai.flyrise.cn'
// const REQUEST_BASE_URL_IOT = env.NODE_ENV === 'development'?'/api-3rd/jetlinks-api':`${BASE_ROUTE}/api-3rd/jetlinks-api`
// --------------------------------------------------
/* Mock配置(生产环境无效,数据文件/server/mock.json)*/
// 是否开启Mock
env.MOCK_ENABLE = false
// 调试类型(json/server)
// json:指向文件./server/mock.json
// server:指向服务./server/mockserver.js
env.MOCK_TYPE = 'server'
// Mock服务IP
env.MOCK_SERVER_ADDRESS = 'http://127.0.0.1'
// Mock服务端口
env.MOCK_SERVER_PORT = '3001'
// Mock服务地址
env.MOCK_SERVER_URL = ''
if (env.NODE_ENV === 'development' && env.MOCK_ENABLE === 'true') {
env.MOCK_SERVER_URL = `${env.MOCK_SERVER_ADDRESS}:${env.MOCK_SERVER_PORT}`
}
// --------------------------------------------------
// 是否开启代码检查
const isEslint = false
// 小组件相关
if (env.NODE_ENV === 'development') {
require('pai-build-widget/build-widget/widget-server')
}
// --------------------------------------------------
module.exports = {
telemetry: false,
mode: 'spa',
env: {
// 开发过程的接口域名
SERVER_URL,
// 接口前缀
REQUEST_BASE_URL,
// REQUEST_BASE_URL,
// REQUEST_BASE_URL_IOT,
// 存储token到cookie的key
TOKEN_KEY: `${package.name}-token`,
// 基础路由
BASE_ROUTE,
// 业务参数
version: 'v1', // 版本
isOss: false, // 是否开启OSS-需要后端业务接口对接OSS,请修改/api/user.js
isAuth: true, // 是否开启登录验证
},
proxy: {
// 业务接口代理
'/api/': {
target: env.MOCK_SERVER_URL || SERVER_URL, // 后端接口请求地址,或Mock模拟接口地址
changeOrigin: true, // 是否跨域
pathRewrite: {
'^/api': '' // 把 /api 替换
}
// disableHostCheck: true
},
// '/api-3rd/jetlinks-api/': {
// target: env.MOCK_SERVER_URL || SERVER_URL_IOT, // 后端接口请求地址,或Mock模拟接口地址
// changeOrigin: true, // 是否跨域
// pathRewrite: {
// '^/api-3rd/jetlinks-api': '' // 把 /api-3rd 替换
// }
// // disableHostCheck: true
// }
},
/*
** Axios module configuration
** See https://axios.nuxtjs.org/options
*/
axios: {
debug: process.env.NODE_ENV !== 'production',
proxy: true, // 开启代理
credentials: true // 跨域请求时是否需要凭证
},
/*
** Headers of the page
*/
head: {
title: 'Loading...',
meta: [
{ charset: 'utf-8' },
{
name: 'viewport',
content: 'width=device-width, initial-scale=1'
},
{
hid: 'description',
name: 'description',
content: process.env.npm_package_description || ''
}
],
link: [
{
rel: 'icon',
type: 'image/x-icon',
href: BASE_ROUTE + '/favicon.ico'
}
]
},
router: {
// middleware: ['auth']
base: BASE_ROUTE // 多级目录修改这里
},
/*
** Customize the progress-bar color
*/
loading: { color: 'red' },
/*
** Global CSS
*/
// css: ['element-ui/lib/theme-chalk/index.css'],
/*
** Plugins to load before mounting the App
*/
plugins: [
'@/plugins/vant-ui', // vant-ui 移动端组件
'@/plugins/element-ui',
'@/plugins/pai-ui', // paiui组件
'@/plugins/components', // 全局组件
'@/plugins/vue-inject', // 注册vue实例函数
'@/plugins/global-func', // 挂载全局函数
'@/plugins/auth-router', // 路由鉴权
{ src: '@/plugins/widget-preview', ssr: false } // 预览小组件
],
/*
** Nuxt.js dev-modules
*/
buildModules: isEslint
? [
// Doc: https://github.com/nuxt-community/eslint-module
'@nuxtjs/eslint-module'
]
: [],
/*
** Nuxt.js modules
*/
modules: [
// Doc: https://axios.nuxtjs.org/usage
'@nuxtjs/axios',
'@nuxtjs/style-resources' // 注入全局less
],
styleResources: {
less: ['./style/variables.less']
},
generate: {
dir: 'dist',
fallback: true,
mode: 'spa',
interval: 150
// subFolders: false //按路由生存
},
/*
** Build configuration
*/
build: {
transpile: [/^element-ui/],
/*
** You can extend webpack config here
*/
extend(config, ctx) {},
vendor: ['axios'], // 防止重复打包
// postcss插件 -zheng
postcss: {
// 添加插件名称作为键,参数作为值
// 使用npm或yarn安装它们
// plugins: {
// // 通过传递 false 来禁用插件
// 'postcss-url': false,
// 'postcss-nested': {},
// 'postcss-responsive-type': {},
// 'postcss-hexrgba': {}
// },
preset: {
// 更改postcss-preset-env 设置
autoprefixer: {
overrideBrowserslist: [
'Android 4.1',
'iOS 7.1',
'Chrome > 31',
'ff > 31',
'ie >= 8'
],
grid: false
}
}
}
}
}
npm 镜像配置
打开 <工程>/.npmrc,添加下面的 npm 镜像配置,可以解决安装依赖失败的问题:
sass_binary_site=https://npm.taobao.org/mirrors/node-sass/
phantomjs_cdnurl=https://npm.taobao.org/mirrors/phantomjs/
electron_mirror=https://npm.taobao.org/mirrors/electron/
registry=https://registry.npm.taobao.org
更多参考
registry=https://registry.npmmirror.com/
disturl=https://npmmirror.com/mirrors/node
chromedriver-cdnurl=https://npmmirror.com/mirrors/chromedriver
couchbase-binary-host-mirror=https://npmmirror.com/mirrors/couchbase/v{version}
debug-binary-host-mirror=https://npmmirror.com/mirrors/node-inspector
flow-bin-binary-host-mirror=https://npmmirror.com/mirrors/flow/v{version}
fse-binary-host-mirror=https://npmmirror.com/mirrors/fsevents
fuse-bindings-binary-host-mirror=https://npmmirror.com/mirrors/fuse-bindings/v{version}
git4win-mirror=https://npmmirror.com/mirrors/git-for-windows
gl-binary-host-mirror=https://npmmirror.com/mirrors/gl/v{version}
grpc-node-binary-host-mirror=https://npmmirror.com/mirrors
hackrf-binary-host-mirror=https://npmmirror.com/mirrors/hackrf/v{version}
leveldown-binary-host-mirror=https://npmmirror.com/mirrors/leveldown/v{version}
leveldown-hyper-binary-host-mirror=https://npmmirror.com/mirrors/leveldown-hyper/v{version}
mknod-binary-host-mirror=https://npmmirror.com/mirrors/mknod/v{version}
node-sqlite3-binary-host-mirror=https://npmmirror.com/mirrors
node-tk5-binary-host-mirror=https://npmmirror.com/mirrors/node-tk5/v{version}
nodegit-binary-host-mirror=https://npmmirror.com/mirrors/nodegit/v{version}/
operadriver-cdnurl=https://npmmirror.com/mirrors/operadriver
phantomjs-cdnurl=https://npmmirror.com/mirrors/phantomjs
profiler-binary-host-mirror=https://npmmirror.com/mirrors/node-inspector/
python-mirror=https://npmmirror.com/mirrors/python
rabin-binary-host-mirror=https://npmmirror.com/mirrors/rabin/v{version}
sass-binary-site=https://npmmirror.com/mirrors/node-sass
sodium-prebuilt-binary-host-mirror=https://npmmirror.com/mirrors/sodium-prebuilt/v{version}
sqlite3-binary-site=https://npmmirror.com/mirrors/sqlite3
utf-8-validate-binary-host-mirror=https://npmmirror.com/mirrors/utf-8-validate/v{version}
utp-native-binary-host-mirror=https://npmmirror.com/mirrors/utp-native/v{version}
zmq-prebuilt-binary-host-mirror=https://npmmirror.com/mirrors/zmq-prebuilt/v{version}
bin-mirrors-prefix=https://npmmirror.com/mirrors
canvas_binary_host_mirror=https://npmmirror.com/mirrors/canvas
electron-mirror=https://npmmirror.com/mirrors/electron/
electron_custom_dir={{ version }}
electron_builder_binaries_mirror=https://registry.npmmirror.com/-/binary/electron-builder-binaries/
文档更新时间: 2023-09-21 14:22 作者:管理员