Uncaught ReferenceError: ROUTES is not defined

- 发布:2022-02-21 12:44
- 更新:2023-09-13 16:47
- 阅读:4621
Uncaught ReferenceError: ROUTES is not defined

膨胀的木鱼 - 嚣张的小毛驴
const TransformPages = require('uni-read-pages')
const {
webpack
} = new TransformPages()
let pluginsDev = new webpack.DefinePlugin({
ROUTES: webpack.DefinePlugin.runtimeValue(() => {
const tfPages = new TransformPages({
includes: ['path', 'name', 'aliasPath']
});
return JSON.stringify(tfPages.routes)
}, true)
})
let publicPath = './'
module.exports = {
transpileDependencies: ['uview-ui'],
configureWebpack: {
resolve: {
alias: {
'/': '@',
}
},
},
publicPath: publicPath,
lintOnSave: true,
// 配置转发代理
devServer: {
proxy: {
'/admin': {
target: url,
changeOrigin: true, //允许跨域
pathRewrite: {
'^/admin': '/'
}
}
// v2.7.0 不需在配置前端代理
}
},
productionSourceMap: false, // 生产打包时不输出map文件,增加打包速度
configureWebpack: config => {
devtool: 'cheap-module-eval-source-map'
if (process.env.NODE_ENV === 'production') {
config.optimization.minimizer[0].options.terserOptions.compress.warnings = false
config.optimization.minimizer[0].options.terserOptions.compress.drop_console = true
config.optimization.minimizer[0].options.terserOptions.compress.drop_debugger = true
config.optimization.minimizer[0].options.terserOptions.compress.pure_funcs = ['console.log']
}
///////////////////////////////////超级注释 , 看这里 解决方法如下
config.plugins.push(pluginsDev)
}
}

需要配置vue.config.js。
附上源码
const TransformPages = require('uni-read-pages')
const {webpack} = new TransformPages()
module.exports = {
configureWebpack: {
plugins: [
new webpack.DefinePlugin({
ROUTES: webpack.DefinePlugin.runtimeValue(() => {
const tfPages = new TransformPages({
includes: ['path', 'name', 'meta','aliasPath']
});
return JSON.stringify(tfPages.routes)
}, true )
})
]
}
}

我就想知道,有人成功了的吗?
router.js:6 Uncaught ReferenceError: ROUTES is not defined
router.js:6 Uncaught ReferenceError: ROUTES is not defined
router.js:6 Uncaught ReferenceError: ROUTES is not defined
router.js:6 Uncaught ReferenceError: ROUTES is not defined
router.js:6 Uncaught ReferenceError: ROUTES is not defined
router.js:6 Uncaught ReferenceError: ROUTES is not defined
router.js:6 Uncaught ReferenceError: ROUTES is not defined
router.js:6 Uncaught ReferenceError: ROUTES is not defined
router.js:6 Uncaught ReferenceError: ROUTES is not defined
router.js:6 Uncaught ReferenceError: ROUTES is not defined
router.js:6 Uncaught ReferenceError: ROUTES is not defined

是插件缺失问题。uni-read-pages插件是在vue.config.js文件中配置的,外面的编译环境不能直接加载内部vue.config.js文件。
可以添加日志来确认该文件有没有在编译时执行。
可以将该文件复制到编译目录下然后安装uni-read-pages的依赖包,之后即可打包。请路过高手弄一个灵活加载然后@我

是 vue.config.js这个没有写
//vue.config.js
const TransformPages = require('uni-read-pages')
const {webpack} = new TransformPages()
module.exports = {
configureWebpack: {
plugins: [
new webpack.DefinePlugin({
ROUTES: webpack.DefinePlugin.runtimeValue(() => {
const tfPages = new TransformPages({
includes: ['path', 'name', 'aliasPath']
});
return JSON.stringify(tfPages.routes)
}, true )
})
]
}
}
或者写了 名字错了 (vue.config.js)就叫这个名字,或者位置错了(放在项目的根目录下)
cwdnb
看这位老哥的,不会改配置的直接把这坨代码复制粘贴到vue.config.js
2022-08-19 15:24