/** * uni-app Vue2 CLI 工程配置 * * 作用:把 pages.json 的所有页面路由通过 DefinePlugin 注入为全局常量 ROUTES。 * 该常量由 uni-simple-router 内部使用(见 core/router/uni-simple-router.js), * 缺失会在运行时抛 `ReferenceError: ROUTES is not defined`。 * * 注意:这里把 TransformPages 的构造放在 runtimeValue 回调里惰性执行, * 因为 vue.config.js 被 require 时 vue-cli-plugin-uni 还没设置 UNI_INPUT_DIR。 */ const webpack = require('webpack') const TransformPages = require('uni-read-pages') module.exports = { configureWebpack: { plugins: [ new webpack.DefinePlugin({ ROUTES: webpack.DefinePlugin.runtimeValue(() => { const tfPages = new TransformPages({ includes: ['path', 'name', 'aliasPath', 'meta'] }) return JSON.stringify(tfPages.routes) }, true) }) ] } }