提交 1d3f7ba5 编写于 作者: fxy060608's avatar fxy060608

fix(cli): preprocess pages.json

上级 5ec7a426
import fs from 'fs' import fs from 'fs'
import path from 'path' import path from 'path'
import slash from 'slash' import slash from 'slash'
import { parse } from 'jsonc-parser'
import { import {
CreateUniViteFilterPlugin, CreateUniViteFilterPlugin,
UniViteFilterPluginOptions, UniViteFilterPluginOptions,
...@@ -52,7 +51,7 @@ function createDefineJsonJsPlugin(name: 'pages.json' | 'manifest.json') { ...@@ -52,7 +51,7 @@ function createDefineJsonJsPlugin(name: 'pages.json' | 'manifest.json') {
if (!opts.filter(id)) { if (!opts.filter(id)) {
return return
} }
return JSON.stringify(parse(fs.readFileSync(jsonPath, 'utf8'))) return fs.readFileSync(jsonPath, 'utf8')
} }
return plugin return plugin
} }
......
...@@ -23,7 +23,7 @@ function uniManifestJsonPlugin() { ...@@ -23,7 +23,7 @@ function uniManifestJsonPlugin() {
if (!opts.filter(id)) { if (!opts.filter(id)) {
return; return;
} }
const manifest = JSON.parse(code); const manifest = uni_cli_shared_1.parseJson(code);
const { debug, h5 } = manifest; const { debug, h5 } = manifest;
const appid = (manifest.appid || '').replace('__UNI__', ''); const appid = (manifest.appid || '').replace('__UNI__', '');
const router = Object.assign(Object.assign({}, defaultRouter), ((h5 && h5.router) || {})); const router = Object.assign(Object.assign({}, defaultRouter), ((h5 && h5.router) || {}));
......
...@@ -3,6 +3,7 @@ import { Plugin } from 'vite' ...@@ -3,6 +3,7 @@ import { Plugin } from 'vite'
import { import {
defineUniManifestJsonPlugin, defineUniManifestJsonPlugin,
normalizeNetworkTimeout, normalizeNetworkTimeout,
parseJson,
} from '@dcloudio/uni-cli-shared' } from '@dcloudio/uni-cli-shared'
const defaultRouter = { const defaultRouter = {
...@@ -29,7 +30,7 @@ export function uniManifestJsonPlugin(): Plugin { ...@@ -29,7 +30,7 @@ export function uniManifestJsonPlugin(): Plugin {
if (!opts.filter(id)) { if (!opts.filter(id)) {
return return
} }
const manifest = JSON.parse(code) const manifest = parseJson(code)
const { debug, h5 } = manifest const { debug, h5 } = manifest
const appid = (manifest.appid || '').replace('__UNI__', '') const appid = (manifest.appid || '').replace('__UNI__', '')
const router = { ...defaultRouter, ...((h5 && h5.router) || {}) } const router = { ...defaultRouter, ...((h5 && h5.router) || {}) }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册