@dcloudio/uni-cli-shared
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -38,3 +38,5 @@ const tags = require('./tags') | ||
getPlatformCompiler, | ||
getPlatformCssVars | ||
getPlatformCssVars, | ||
jsPreprocessOptions, | ||
htmlPreprocessOptions | ||
} = require('./platform') | ||
@@ -66,3 +68,5 @@ | ||
parseManifestJson, | ||
convertStaticStyle | ||
convertStaticStyle, | ||
jsPreprocessOptions, | ||
htmlPreprocessOptions | ||
} |
const fs = require('fs') | ||
const path = require('path') | ||
const stripJsonComments = require('strip-json-comments') | ||
const preprocessor = require('@dcloudio/vue-cli-plugin-uni/packages/webpack-preprocess-loader/preprocess') | ||
const { | ||
jsPreprocessOptions | ||
} = require('./platform') | ||
function parseJson (content) { | ||
content = typeof content === 'string' ? JSON.parse(stripJsonComments(content)) : content | ||
function parseJson (content, preprocess = false) { | ||
if (typeof content === 'string') { | ||
if (preprocess) { | ||
content = preprocessor.preprocess(content, jsPreprocessOptions.context, { | ||
type: jsPreprocessOptions.type | ||
}) | ||
} | ||
content = JSON.parse(stripJsonComments(content)) | ||
} | ||
content = JSON.stringify(content) | ||
@@ -15,3 +27,3 @@ .replace(/\u2028/g, '\\u2028') | ||
function getJson (jsonFileName) { | ||
function getJson (jsonFileName, preprocess = false) { | ||
const jsonFilePath = path.resolve(process.env.UNI_INPUT_DIR, jsonFileName) | ||
@@ -22,3 +34,3 @@ if (!fs.existsSync(jsonFilePath)) { | ||
try { | ||
return parseJson(fs.readFileSync(jsonFilePath, 'utf8')) | ||
return parseJson(fs.readFileSync(jsonFilePath, 'utf8'), preprocess) | ||
} catch (e) { | ||
@@ -25,0 +37,0 @@ throw new Error(jsonFileName + ' 解析失败') |
@@ -14,7 +14,7 @@ const fs = require('fs') | ||
function getPagesJson () { | ||
return processPagesJson(getJson('pages.json')) | ||
return processPagesJson(getJson('pages.json', true)) | ||
} | ||
function parsePagesJson (content) { | ||
return processPagesJson(parseJson(content)) | ||
return processPagesJson(parseJson(content, true)) | ||
} | ||
@@ -21,0 +21,0 @@ |
@@ -66,5 +66,26 @@ const fs = require('fs') | ||
const preprocessContext = { | ||
[process.env.UNI_PLATFORM.toUpperCase()]: true | ||
} | ||
if (process.env.UNI_PLATFORM.indexOf('mp-') === 0) { | ||
preprocessContext['MP'] = true | ||
} | ||
if (process.env.UNI_PLATFORM.indexOf('app-') === 0) { | ||
preprocessContext['APP'] = true | ||
} | ||
const isInHBuilderX = fs.existsSync(path.resolve(__dirname, '../../vue-cli-plugin-hbuilderx')) | ||
module.exports = { | ||
isInHBuilderX, | ||
jsPreprocessOptions: { | ||
type: 'js', | ||
context: preprocessContext | ||
}, | ||
htmlPreprocessOptions: { | ||
type: 'html', | ||
context: preprocessContext | ||
}, | ||
getPlatformExts () { | ||
@@ -71,0 +92,0 @@ return EXTS[process.env.UNI_PLATFORM] |
{ | ||
"name": "@dcloudio/uni-cli-shared", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "uni-cli-shared", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26410
520
23