@plugin-light/shared 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
export type ICrossGameStyleOptions = {
|
|
2
|
+
/**
|
|
3
|
+
* 要替换的样式文件名,不含后缀,默认空,即从项目的 config.js 中获取
|
|
4
|
+
*/
|
|
2
5
|
styleName?: string | Array<string>;
|
|
6
|
+
/**
|
|
7
|
+
* 处理的平台,默认全部,即 ['ALL']
|
|
8
|
+
*/
|
|
3
9
|
platforms?: Array<string>;
|
|
10
|
+
/**
|
|
11
|
+
* 要查找的文件后缀,默认 ['scss', 'less']
|
|
12
|
+
*/
|
|
13
|
+
extList?: Array<string>;
|
|
4
14
|
};
|
package/lib/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export { findDependencies, } from './find-dependencies';
|
|
|
11
11
|
export { checkH5, } from './h5';
|
|
12
12
|
export { getLoaderFile, getLoaderProdFile, } from './loader-file';
|
|
13
13
|
export { recordLoaderLog, saveLoaderLog, } from './loader-log';
|
|
14
|
+
export { shouldUseLoader, } from './loader-options';
|
|
14
15
|
export { getWxmlAndWxssPostfix, } from './platform';
|
|
15
16
|
export { getProjectName, getSubProjectName, } from './project-name';
|
|
16
17
|
export { revertManifest, updateManifest, } from './replace-manifest';
|
package/lib/index.js
CHANGED
|
@@ -6,6 +6,7 @@ var fs = require('fs');
|
|
|
6
6
|
var path = require('path');
|
|
7
7
|
var tComm = require('t-comm');
|
|
8
8
|
var path$1 = require('node:path');
|
|
9
|
+
var loaderUtils = require('loader-utils');
|
|
9
10
|
var fs$1 = require('node:fs');
|
|
10
11
|
|
|
11
12
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
@@ -388,6 +389,17 @@ function recordLoaderLog(file, content) {
|
|
|
388
389
|
global[LOG_KEY][file].push(content);
|
|
389
390
|
}
|
|
390
391
|
|
|
392
|
+
function shouldUseLoader(defaultPlatforms = []) {
|
|
393
|
+
const options = loaderUtils.getOptions(this) || {};
|
|
394
|
+
const { platforms = defaultPlatforms } = options;
|
|
395
|
+
const platform = process.env.UNI_PLATFORM || '';
|
|
396
|
+
if (platforms === ALL_PLATFORM
|
|
397
|
+
|| platforms.indexOf(ALL_PLATFORM) > -1) {
|
|
398
|
+
return true;
|
|
399
|
+
}
|
|
400
|
+
return platforms.includes(platform);
|
|
401
|
+
}
|
|
402
|
+
|
|
391
403
|
function getWxmlAndWxssPostfix() {
|
|
392
404
|
const map = Object.keys(PLATFORM_MAP).reduce((acc, item) => {
|
|
393
405
|
acc[PLATFORM_MAP[item]] = item;
|
|
@@ -500,6 +512,10 @@ const isQuickappUnion = () => getPlatform() === 'quickapp-webview-union';
|
|
|
500
512
|
const isQuickappHuawei = () => getPlatform() === 'quickapp-webview-huawei';
|
|
501
513
|
|
|
502
514
|
const TIP_STYLE_NAME = '@TIP_STYLE_NAME';
|
|
515
|
+
const DEFAULT_EXT_LIST = [
|
|
516
|
+
'scss',
|
|
517
|
+
'less',
|
|
518
|
+
];
|
|
503
519
|
|
|
504
520
|
function getAppDir() {
|
|
505
521
|
if (process.env.VUE_APP_DIR) {
|
|
@@ -535,10 +551,20 @@ function tryRemoveImport(source, removeImport = false) {
|
|
|
535
551
|
}
|
|
536
552
|
return res;
|
|
537
553
|
}
|
|
554
|
+
function findValidFile(fileName, extList) {
|
|
555
|
+
for (const ext of extList) {
|
|
556
|
+
const file = `${fileName}.${ext}`;
|
|
557
|
+
if (fs__namespace.existsSync(file)) {
|
|
558
|
+
return [ext, file];
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
return [];
|
|
562
|
+
}
|
|
538
563
|
function crossGameStyle({ source, options, dir, removeImport = false, }) {
|
|
539
564
|
if (!source.includes(TIP_STYLE_NAME)) {
|
|
540
565
|
return source;
|
|
541
566
|
}
|
|
567
|
+
const extList = options?.extList || DEFAULT_EXT_LIST;
|
|
542
568
|
let styleName = '';
|
|
543
569
|
// 使用 env.local 的样式 VUE_APP_DIR = module/ingame-nba,即为 nba
|
|
544
570
|
if (options?.styleName) {
|
|
@@ -566,11 +592,12 @@ function crossGameStyle({ source, options, dir, removeImport = false, }) {
|
|
|
566
592
|
}
|
|
567
593
|
styleName = styleName[0] || '';
|
|
568
594
|
}
|
|
569
|
-
const cssPath = `./css/${styleName}
|
|
570
|
-
const cssAbsolutePath = `${dir}/css/${styleName}
|
|
571
|
-
const
|
|
572
|
-
if (
|
|
573
|
-
|
|
595
|
+
const cssPath = `./css/${styleName}`;
|
|
596
|
+
const cssAbsolutePath = `${dir}/css/${styleName}`;
|
|
597
|
+
const found = findValidFile(cssAbsolutePath, extList);
|
|
598
|
+
if (found.length) {
|
|
599
|
+
const [ext] = found;
|
|
600
|
+
return source.replace(TIP_STYLE_NAME, `${cssPath}.${ext}`);
|
|
574
601
|
}
|
|
575
602
|
return tryRemoveImport(source, removeImport);
|
|
576
603
|
}
|
|
@@ -909,6 +936,7 @@ exports.revertManifest = revertManifest;
|
|
|
909
936
|
exports.saveJsonToLog = saveJsonToLog;
|
|
910
937
|
exports.saveLoaderLog = saveLoaderLog;
|
|
911
938
|
exports.scssLogger = scssLogger;
|
|
939
|
+
exports.shouldUseLoader = shouldUseLoader;
|
|
912
940
|
exports.updateAssetSource = updateAssetSource;
|
|
913
941
|
exports.updateManifest = updateManifest;
|
|
914
942
|
exports.vLazyCore = vLazyCore;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function shouldUseLoader(this: any, defaultPlatforms?: Array<string>): boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plugin-light/shared",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"homepage": "https://novlan1.github.io/docs/plugin-light/zh/plugin-light-shared.html",
|
|
5
5
|
"bugs": {
|
|
6
6
|
"url": "https://github.com/novlan1/plugin-light/issues"
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
"lib/"
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"
|
|
19
|
+
"loader-utils": "^2.0.4",
|
|
20
|
+
"t-comm": "^3.0.22"
|
|
20
21
|
},
|
|
21
22
|
"scripts": {
|
|
22
23
|
"build": "rm -rf lib && rollup -c",
|