@dcloudio/uni-cli-shared 3.0.0-alpha-3021320211118002 → 3.0.0-alpha-3021320211122001

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,3 +1,5 @@
1
1
  import type { Formatter } from '../logs/format';
2
2
  export declare function initModuleAlias(): void;
3
+ export declare function installHBuilderXPlugin(plugin: string): void;
3
4
  export declare const moduleAliasFormatter: Formatter;
5
+ export declare function formatInstallHBuilderXPluginTips(lang: string, preprocessor: string): string;
package/dist/hbx/alias.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.moduleAliasFormatter = exports.initModuleAlias = void 0;
6
+ exports.formatInstallHBuilderXPluginTips = exports.moduleAliasFormatter = exports.installHBuilderXPlugin = exports.initModuleAlias = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const module_alias_1 = __importDefault(require("module-alias"));
9
9
  const env_1 = require("./env");
@@ -25,9 +25,13 @@ exports.initModuleAlias = initModuleAlias;
25
25
  function supportAutoInstallPlugin() {
26
26
  return true;
27
27
  }
28
- function sendSignal(lang) {
29
- return console.error(`%HXRunUniAPPPluginName%${lang}%HXRunUniAPPPluginName%`);
28
+ function installHBuilderXPlugin(plugin) {
29
+ if (!supportAutoInstallPlugin()) {
30
+ return;
31
+ }
32
+ return console.error(`%HXRunUniAPPPluginName%${plugin}%HXRunUniAPPPluginName%`);
30
33
  }
34
+ exports.installHBuilderXPlugin = installHBuilderXPlugin;
31
35
  exports.moduleAliasFormatter = {
32
36
  test(msg) {
33
37
  return msg.includes('Preprocessor dependency');
@@ -48,11 +52,14 @@ exports.moduleAliasFormatter = {
48
52
  preprocessor = 'compile-stylus';
49
53
  }
50
54
  if (lang) {
51
- const autoInstall = supportAutoInstallPlugin();
52
- autoInstall && sendSignal(preprocessor);
53
- return `预编译器错误:代码使用了${lang}语言,但未安装相应的编译器插件,${autoInstall ? '正在从' : '请前往'}插件市场安装该插件:
54
- https://ext.dcloud.net.cn/plugin?name=${preprocessor}`;
55
+ installHBuilderXPlugin(preprocessor);
56
+ return formatInstallHBuilderXPluginTips(lang, preprocessor);
55
57
  }
56
58
  return msg;
57
59
  },
58
60
  };
61
+ function formatInstallHBuilderXPluginTips(lang, preprocessor) {
62
+ return `预编译器错误:代码使用了${lang}语言,但未安装相应的编译器插件,${supportAutoInstallPlugin() ? '正在从' : '请前往'}插件市场安装该插件:
63
+ https://ext.dcloud.net.cn/plugin?name=${preprocessor}`;
64
+ }
65
+ exports.formatInstallHBuilderXPluginTips = formatInstallHBuilderXPluginTips;
@@ -1,2 +1,2 @@
1
1
  export * from './env';
2
- export { initModuleAlias } from './alias';
2
+ export { initModuleAlias, installHBuilderXPlugin, formatInstallHBuilderXPluginTips, } from './alias';
package/dist/hbx/index.js CHANGED
@@ -10,7 +10,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
10
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.initModuleAlias = void 0;
13
+ exports.formatInstallHBuilderXPluginTips = exports.installHBuilderXPlugin = exports.initModuleAlias = void 0;
14
14
  __exportStar(require("./env"), exports);
15
15
  var alias_1 = require("./alias");
16
16
  Object.defineProperty(exports, "initModuleAlias", { enumerable: true, get: function () { return alias_1.initModuleAlias; } });
17
+ Object.defineProperty(exports, "installHBuilderXPlugin", { enumerable: true, get: function () { return alias_1.installHBuilderXPlugin; } });
18
+ Object.defineProperty(exports, "formatInstallHBuilderXPluginTips", { enumerable: true, get: function () { return alias_1.formatInstallHBuilderXPluginTips; } });
package/dist/index.d.ts CHANGED
@@ -16,6 +16,7 @@ export * from './preprocess';
16
16
  export * from './postcss';
17
17
  export * from './filter';
18
18
  export * from './esbuild';
19
+ export * from './resolve';
19
20
  export { M } from './messages';
20
21
  export * from './exports';
21
22
  export { checkUpdate } from './checkUpdate';
package/dist/index.js CHANGED
@@ -29,6 +29,7 @@ __exportStar(require("./preprocess"), exports);
29
29
  __exportStar(require("./postcss"), exports);
30
30
  __exportStar(require("./filter"), exports);
31
31
  __exportStar(require("./esbuild"), exports);
32
+ __exportStar(require("./resolve"), exports);
32
33
  var messages_1 = require("./messages");
33
34
  Object.defineProperty(exports, "M", { enumerable: true, get: function () { return messages_1.M; } });
34
35
  __exportStar(require("./exports"), exports);
@@ -1 +1,5 @@
1
1
  export declare function initSplashscreen(manifestJson: Record<string, any>, userManifestJson: Record<string, any>): void;
2
+ export declare function getSplashscreen(manifestJson: Record<string, any>): {
3
+ autoclose: boolean;
4
+ alwaysShowBeforeRender: boolean;
5
+ };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.initSplashscreen = void 0;
3
+ exports.getSplashscreen = exports.initSplashscreen = void 0;
4
4
  const shared_1 = require("@vue/shared");
5
5
  function initSplashscreen(manifestJson, userManifestJson) {
6
6
  if (!manifestJson.plus.splashscreen) {
@@ -21,8 +21,6 @@ function initSplashscreen(manifestJson, userManifestJson) {
21
21
  }
22
22
  manifestJson.plus.splashscreen.autoclose = true;
23
23
  manifestJson.plus.splashscreen.delay = 0;
24
- // 简单起见,直接设置环境变量,这样生成uniConfig时,直接读取判断
25
- process.env.UNI_SPLASHSCREEN_ALWAYSSHOWBEFORERENDER = 'true';
26
24
  }
27
25
  else {
28
26
  // 不启用白屏检测
@@ -30,10 +28,17 @@ function initSplashscreen(manifestJson, userManifestJson) {
30
28
  if (manifestJson.plus.splashscreen.autoclose) {
31
29
  // 启用 uni-app 框架关闭 splash
32
30
  manifestJson.plus.splashscreen.autoclose = false; // 原 5+ autoclose 改为 false
33
- // 简单起见,直接设置环境变量,这样生成uniConfig时,直接读取判断
34
- process.env.UNI_SPLASHSCREEN_AUTOCLOSE = 'true';
35
31
  }
36
32
  }
37
33
  delete manifestJson.plus.splashscreen.alwaysShowBeforeRender;
38
34
  }
39
35
  exports.initSplashscreen = initSplashscreen;
36
+ function getSplashscreen(manifestJson) {
37
+ var _a;
38
+ const splashscreenOptions = (_a = manifestJson['app-plus']) === null || _a === void 0 ? void 0 : _a.splashscreen;
39
+ return {
40
+ autoclose: splashscreenOptions.autoclose !== false,
41
+ alwaysShowBeforeRender: splashscreenOptions.alwaysShowBeforeRender !== false,
42
+ };
43
+ }
44
+ exports.getSplashscreen = getSplashscreen;
@@ -8,8 +8,10 @@ const path_1 = __importDefault(require("path"));
8
8
  const i18n_1 = require("../../../i18n");
9
9
  const manifest_1 = require("../../manifest");
10
10
  const manifest_2 = require("../manifest");
11
+ const splashscreen_1 = require("../manifest/splashscreen");
11
12
  function normalizeAppUniConfig(pagesJson, manifestJson) {
12
13
  var _a;
14
+ const { autoclose, alwaysShowBeforeRender } = (0, splashscreen_1.getSplashscreen)(manifestJson);
13
15
  const config = {
14
16
  pages: [],
15
17
  globalStyle: pagesJson.globalStyle,
@@ -21,11 +23,8 @@ function normalizeAppUniConfig(pagesJson, manifestJson) {
21
23
  renderer: ((_a = manifestJson['app-plus']) === null || _a === void 0 ? void 0 : _a.renderer) === 'native' ? 'native' : 'auto',
22
24
  appname: manifestJson.name || '',
23
25
  splashscreen: {
24
- alwaysShowBeforeRender: process.env
25
- .UNI_SPLASHSCREEN_ALWAYSSHOWBEFORERENDER
26
- ? true
27
- : false,
28
- autoclose: process.env.UNI_SPLASHSCREEN_AUTOCLOSE ? true : false,
26
+ alwaysShowBeforeRender,
27
+ autoclose,
29
28
  },
30
29
  compilerVersion: process.env.UNI_COMPILER_VERSION,
31
30
  entryPagePath: pagesJson.pages[0].path,
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.addMiniProgramUsingComponents = exports.addMiniProgramComponentJson = exports.addMiniProgramPageJson = exports.addMiniProgramAppJson = exports.findChangedJsonFiles = exports.normalizeJsonFilename = exports.hasJsonFile = exports.isPageFile = void 0;
4
4
  const shared_1 = require("@vue/shared");
5
5
  const utils_1 = require("../../utils");
6
+ const resolve_1 = require("../../resolve");
6
7
  let appJsonCache = {};
7
8
  const jsonFilesCache = new Map();
8
9
  const jsonPagesCache = new Map();
@@ -33,7 +34,7 @@ function findChangedJsonFiles() {
33
34
  const usingComponents = newJson.usingComponents;
34
35
  // 格式化为相对路径,这样作为分包也可以直接运行
35
36
  Object.keys(usingComponents).forEach((name) => {
36
- usingComponents[name] = (0, utils_1.relativeFile)(filename, usingComponents[name].slice(1));
37
+ usingComponents[name] = (0, resolve_1.relativeFile)(filename, usingComponents[name].slice(1));
37
38
  });
38
39
  const jsonStr = JSON.stringify(newJson, null, 2);
39
40
  if (jsonFilesCache.get(filename) !== jsonStr) {
@@ -18,6 +18,7 @@ const DEFAULT_KEYS = [
18
18
  'MP_TOUTIAO',
19
19
  'MP_WEIXIN',
20
20
  'MP_KUAISHOU',
21
+ 'MP_JD',
21
22
  'QUICKAPP_NATIVE',
22
23
  'QUICKAPP_WEBVIEW',
23
24
  'QUICKAPP_WEBVIEW_HUAWEI',
@@ -0,0 +1,5 @@
1
+ export declare function relativeFile(from: string, to: string): string;
2
+ export declare const resolveMainPathOnce: (inputDir: string) => string;
3
+ export declare function getBuiltInPaths(): string[];
4
+ export declare function resolveBuiltIn(path: string): string;
5
+ export declare function resolveComponentsLibPath(): string;
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.resolveComponentsLibPath = exports.resolveBuiltIn = exports.getBuiltInPaths = exports.resolveMainPathOnce = exports.relativeFile = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const debug_1 = __importDefault(require("debug"));
10
+ const resolve_1 = __importDefault(require("resolve"));
11
+ const uni_shared_1 = require("@dcloudio/uni-shared");
12
+ const utils_1 = require("./utils");
13
+ const env_1 = require("./hbx/env");
14
+ const DEFAULT_EXTENSIONS = ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json'];
15
+ function resolveWithSymlinks(id, basedir) {
16
+ return resolve_1.default.sync(id, {
17
+ basedir,
18
+ extensions: DEFAULT_EXTENSIONS,
19
+ // necessary to work with pnpm
20
+ preserveSymlinks: true,
21
+ });
22
+ }
23
+ function relativeFile(from, to) {
24
+ const relativePath = (0, utils_1.normalizePath)(path_1.default.relative(path_1.default.dirname(from), to));
25
+ return relativePath.startsWith('.') ? relativePath : './' + relativePath;
26
+ }
27
+ exports.relativeFile = relativeFile;
28
+ exports.resolveMainPathOnce = (0, uni_shared_1.once)((inputDir) => {
29
+ const mainTsPath = path_1.default.resolve(inputDir, 'main.ts');
30
+ if (fs_1.default.existsSync(mainTsPath)) {
31
+ return (0, utils_1.normalizePath)(mainTsPath);
32
+ }
33
+ return (0, utils_1.normalizePath)(path_1.default.resolve(inputDir, 'main.js'));
34
+ });
35
+ const ownerModules = ['@dcloudio/uni-app', '@dcloudio/vite-plugin-uni'];
36
+ const paths = [];
37
+ function resolveNodeModulePath(modulePath) {
38
+ const nodeModulesPaths = [];
39
+ const nodeModulesPath = path_1.default.join(modulePath, 'node_modules');
40
+ if (fs_1.default.existsSync(nodeModulesPath)) {
41
+ nodeModulesPaths.push(nodeModulesPath);
42
+ }
43
+ const index = modulePath.lastIndexOf('node_modules');
44
+ if (index > -1) {
45
+ nodeModulesPaths.push(path_1.default.join(modulePath.substr(0, index), 'node_modules'));
46
+ }
47
+ return nodeModulesPaths;
48
+ }
49
+ function initPaths() {
50
+ const cliContext = process.env.UNI_CLI_CONTEXT;
51
+ if (cliContext) {
52
+ const pathSet = new Set();
53
+ pathSet.add(path_1.default.join(cliContext, 'node_modules'));
54
+ if (!(0, env_1.isInHBuilderX)()) {
55
+ ;
56
+ [`@dcloudio/uni-` + process.env.UNI_PLATFORM, ...ownerModules].forEach((ownerModule) => {
57
+ let pkgPath = '';
58
+ try {
59
+ pkgPath = require.resolve(ownerModule + '/package.json', {
60
+ paths: [cliContext],
61
+ });
62
+ }
63
+ catch (e) { }
64
+ if (pkgPath) {
65
+ resolveNodeModulePath(path_1.default.dirname(pkgPath)).forEach((nodeModulePath) => {
66
+ pathSet.add(nodeModulePath);
67
+ });
68
+ }
69
+ });
70
+ }
71
+ paths.push(...pathSet);
72
+ (0, debug_1.default)('uni-paths')(paths);
73
+ }
74
+ }
75
+ function getBuiltInPaths() {
76
+ if (!paths.length) {
77
+ initPaths();
78
+ }
79
+ return paths;
80
+ }
81
+ exports.getBuiltInPaths = getBuiltInPaths;
82
+ function resolveBuiltIn(path) {
83
+ return require.resolve(path, { paths: getBuiltInPaths() });
84
+ }
85
+ exports.resolveBuiltIn = resolveBuiltIn;
86
+ let componentsLibPath = '';
87
+ function resolveComponentsLibPath() {
88
+ if (!componentsLibPath) {
89
+ if ((0, env_1.isInHBuilderX)()) {
90
+ componentsLibPath = path_1.default.join(resolveBuiltIn('@dcloudio/uni-components/package.json'), '../lib');
91
+ }
92
+ else {
93
+ componentsLibPath = path_1.default.join(resolveWithSymlinks('@dcloudio/uni-components/package.json', process.env.UNI_INPUT_DIR), '../lib');
94
+ }
95
+ }
96
+ return componentsLibPath;
97
+ }
98
+ exports.resolveComponentsLibPath = resolveComponentsLibPath;
package/dist/utils.d.ts CHANGED
@@ -1,14 +1,10 @@
1
1
  export { default as hash } from 'hash-sum';
2
2
  import type { SFCTemplateCompileOptions } from '@vue/compiler-sfc';
3
3
  import { ElementNode, RootNode, TemplateChildNode } from '@vue/compiler-core';
4
+ export declare let isRunningWithYarnPnp: boolean;
4
5
  export declare const isWindows: boolean;
5
6
  export declare function normalizePath(id: string): string;
6
- export declare function relativeFile(from: string, to: string): string;
7
7
  export declare function checkElementNodeTag(node: RootNode | TemplateChildNode | null | undefined, tag: string): node is ElementNode;
8
- export declare const resolveMainPathOnce: (inputDir: string) => string;
9
- export declare function resolveComponentsLibPath(): string;
10
- export declare function getBuiltInPaths(): string[];
11
- export declare function resolveBuiltIn(path: string): string;
12
8
  export declare function normalizeIdentifier(str: string): string;
13
9
  export declare function normalizePagePath(pagePath: string, platform: UniApp.PLATFORM): string | undefined;
14
10
  export declare function removeExt(str: string): string;
package/dist/utils.js CHANGED
@@ -3,92 +3,27 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.createUniVueTransformAssetUrls = exports.normalizeMiniProgramFilename = exports.normalizeNodeModules = exports.removeExt = exports.normalizePagePath = exports.normalizeIdentifier = exports.resolveBuiltIn = exports.getBuiltInPaths = exports.resolveComponentsLibPath = exports.resolveMainPathOnce = exports.checkElementNodeTag = exports.relativeFile = exports.normalizePath = exports.isWindows = exports.hash = void 0;
6
+ exports.createUniVueTransformAssetUrls = exports.normalizeMiniProgramFilename = exports.normalizeNodeModules = exports.removeExt = exports.normalizePagePath = exports.normalizeIdentifier = exports.checkElementNodeTag = exports.normalizePath = exports.isWindows = exports.isRunningWithYarnPnp = exports.hash = void 0;
7
7
  const fs_1 = __importDefault(require("fs"));
8
8
  const os_1 = __importDefault(require("os"));
9
9
  const path_1 = __importDefault(require("path"));
10
10
  const shared_1 = require("@vue/shared");
11
- const uni_shared_1 = require("@dcloudio/uni-shared");
12
11
  var hash_sum_1 = require("hash-sum");
13
12
  Object.defineProperty(exports, "hash", { enumerable: true, get: function () { return __importDefault(hash_sum_1).default; } });
14
- const debug_1 = __importDefault(require("debug"));
15
13
  const constants_1 = require("./constants");
14
+ try {
15
+ exports.isRunningWithYarnPnp = Boolean(require('pnpapi'));
16
+ }
17
+ catch (_a) { }
16
18
  exports.isWindows = os_1.default.platform() === 'win32';
17
19
  function normalizePath(id) {
18
20
  return exports.isWindows ? id.replace(/\\/g, '/') : id;
19
21
  }
20
22
  exports.normalizePath = normalizePath;
21
- function relativeFile(from, to) {
22
- return normalizePath(path_1.default.relative(path_1.default.dirname(from), to));
23
- }
24
- exports.relativeFile = relativeFile;
25
23
  function checkElementNodeTag(node, tag) {
26
24
  return !!node && node.type === 1 /* ELEMENT */ && node.tag === tag;
27
25
  }
28
26
  exports.checkElementNodeTag = checkElementNodeTag;
29
- exports.resolveMainPathOnce = (0, uni_shared_1.once)((inputDir) => {
30
- const mainTsPath = path_1.default.resolve(inputDir, 'main.ts');
31
- if (fs_1.default.existsSync(mainTsPath)) {
32
- return normalizePath(mainTsPath);
33
- }
34
- return normalizePath(path_1.default.resolve(inputDir, 'main.js'));
35
- });
36
- let componentsLibPath = '';
37
- function resolveComponentsLibPath() {
38
- if (!componentsLibPath) {
39
- componentsLibPath = path_1.default.resolve(resolveBuiltIn('@dcloudio/uni-components/package.json'), '../lib');
40
- }
41
- return componentsLibPath;
42
- }
43
- exports.resolveComponentsLibPath = resolveComponentsLibPath;
44
- const ownerModules = ['@dcloudio/uni-app', '@dcloudio/vite-plugin-uni'];
45
- const paths = [];
46
- function resolveNodeModulePath(modulePath) {
47
- const nodeModulesPaths = [];
48
- const nodeModulesPath = path_1.default.join(modulePath, 'node_modules');
49
- if (fs_1.default.existsSync(nodeModulesPath)) {
50
- nodeModulesPaths.push(nodeModulesPath);
51
- }
52
- const index = modulePath.lastIndexOf('node_modules');
53
- if (index > -1) {
54
- nodeModulesPaths.push(path_1.default.join(modulePath.substr(0, index), 'node_modules'));
55
- }
56
- return nodeModulesPaths;
57
- }
58
- function initPaths() {
59
- const cliContext = process.env.UNI_CLI_CONTEXT;
60
- if (cliContext) {
61
- const pathSet = new Set();
62
- pathSet.add(path_1.default.join(cliContext, 'node_modules'));
63
- [`@dcloudio/uni-` + process.env.UNI_PLATFORM, ...ownerModules].forEach((ownerModule) => {
64
- let pkgPath = '';
65
- try {
66
- pkgPath = require.resolve(ownerModule + '/package.json', {
67
- paths: [cliContext],
68
- });
69
- }
70
- catch (e) { }
71
- if (pkgPath) {
72
- resolveNodeModulePath(path_1.default.dirname(pkgPath)).forEach((nodeModulePath) => {
73
- pathSet.add(nodeModulePath);
74
- });
75
- }
76
- });
77
- paths.push(...pathSet);
78
- (0, debug_1.default)('uni-paths')(paths);
79
- }
80
- }
81
- function getBuiltInPaths() {
82
- if (!paths.length) {
83
- initPaths();
84
- }
85
- return paths;
86
- }
87
- exports.getBuiltInPaths = getBuiltInPaths;
88
- function resolveBuiltIn(path) {
89
- return require.resolve(path, { paths: getBuiltInPaths() });
90
- }
91
- exports.resolveBuiltIn = resolveBuiltIn;
92
27
  function normalizeIdentifier(str) {
93
28
  return (0, shared_1.capitalize)((0, shared_1.camelize)(str.replace(/\//g, '-')));
94
29
  }
@@ -44,3 +44,4 @@ export interface StylePreprocessorResults {
44
44
  errors: RollupError[];
45
45
  deps: string[];
46
46
  }
47
+ export declare function preprocessCss(content: string): any;
@@ -22,15 +22,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
22
22
  return (mod && mod.__esModule) ? mod : { "default": mod };
23
23
  };
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.cssUrlRE = exports.cssPostPlugin = exports.cssPlugin = exports.isDirectCSSRequest = exports.isCSSRequest = exports.cssLangRE = void 0;
25
+ exports.preprocessCss = exports.cssUrlRE = exports.cssPostPlugin = exports.cssPlugin = exports.isDirectCSSRequest = exports.isCSSRequest = exports.cssLangRE = void 0;
26
26
  const fs_1 = __importDefault(require("fs"));
27
27
  const path_1 = __importDefault(require("path"));
28
28
  const fast_glob_1 = __importDefault(require("fast-glob"));
29
29
  const chalk_1 = __importDefault(require("chalk"));
30
30
  const postcss_load_config_1 = __importDefault(require("postcss-load-config"));
31
+ const pluginutils_1 = require("@rollup/pluginutils");
31
32
  const utils_1 = require("../utils");
32
33
  const asset_1 = require("./asset");
33
34
  const esbuild_1 = require("esbuild");
35
+ const preprocess_1 = require("../../../../preprocess");
34
36
  const cssLangs = `\\.(css|less|sass|scss|styl|stylus|pcss|postcss)($|\\?)`;
35
37
  exports.cssLangRE = new RegExp(cssLangs);
36
38
  const cssModuleRE = new RegExp(`\\.module${cssLangs}`);
@@ -142,10 +144,12 @@ function cssPostPlugin(config, { chunkCssFilename, chunkCssCode, }) {
142
144
  if (!exports.cssLangRE.test(id) || commonjsProxyRE.test(id)) {
143
145
  return;
144
146
  }
147
+ const modules = cssModulesCache.get(config).get(id);
148
+ const modulesCode = modules && (0, pluginutils_1.dataToEsm)(modules, { namedExports: true, preferConst: true });
145
149
  // build CSS handling ----------------------------------------------------
146
150
  styles.set(id, css);
147
151
  return {
148
- code: '',
152
+ code: modulesCode || '',
149
153
  map: { mappings: '' },
150
154
  // avoid the css module from being tree-shaken so that we can retrieve
151
155
  // it in renderChunk()
@@ -592,24 +596,32 @@ const sass = (source, root, options, aliasResolver) => scss(source, root, {
592
596
  ...options,
593
597
  indentedSyntax: true,
594
598
  }, aliasResolver);
599
+ function preprocessCss(content) {
600
+ if (content.includes('#endif')) {
601
+ return (0, preprocess_1.preCss)(content);
602
+ }
603
+ return content;
604
+ }
605
+ exports.preprocessCss = preprocessCss;
595
606
  /**
596
607
  * relative url() inside \@imported sass and less files must be rebased to use
597
608
  * root file as base.
598
609
  */
599
610
  async function rebaseUrls(file, rootFile, alias) {
600
611
  file = path_1.default.resolve(file); // ensure os-specific flashes
612
+ // 条件编译
613
+ const contents = preprocessCss(fs_1.default.readFileSync(file, 'utf-8'));
601
614
  // in the same dir, no need to rebase
602
615
  const fileDir = path_1.default.dirname(file);
603
616
  const rootDir = path_1.default.dirname(rootFile);
604
617
  if (fileDir === rootDir) {
605
- return { file };
618
+ return { file, contents };
606
619
  }
607
620
  // no url()
608
- const content = fs_1.default.readFileSync(file, 'utf-8');
609
- if (!exports.cssUrlRE.test(content)) {
610
- return { file };
621
+ if (!exports.cssUrlRE.test(contents)) {
622
+ return { file, contents };
611
623
  }
612
- const rebased = await rewriteCssUrls(content, (url) => {
624
+ const rebased = await rewriteCssUrls(contents, (url) => {
613
625
  if (url.startsWith('/'))
614
626
  return url;
615
627
  // match alias, no need to rewrite
@@ -0,0 +1,40 @@
1
+ /// <reference types="node" />
2
+ import { Plugin } from '../plugin';
3
+ import { ResolvedConfig } from '../config';
4
+ import { OutputOptions, PluginContext, RenderedChunk } from 'rollup';
5
+ export declare const assetUrlRE: RegExp;
6
+ export declare const chunkToEmittedAssetsMap: WeakMap<RenderedChunk, Set<string>>;
7
+ /**
8
+ * Also supports loading plain strings with import text from './foo.txt?raw'
9
+ */
10
+ export declare function assetPlugin(config: ResolvedConfig): Plugin;
11
+ export declare function registerAssetToChunk(chunk: RenderedChunk, file: string): void;
12
+ export declare function checkPublicFile(url: string, { publicDir }: ResolvedConfig): string | undefined;
13
+ export declare function fileToUrl(id: string, config: ResolvedConfig, ctx: PluginContext): string | Promise<string>;
14
+ export declare function getAssetFilename(hash: string, config: ResolvedConfig): string | undefined;
15
+ /**
16
+ * converts the source filepath of the asset to the output filename based on the assetFileNames option. \
17
+ * this function imitates the behavior of rollup.js. \
18
+ * https://rollupjs.org/guide/en/#outputassetfilenames
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * const content = Buffer.from('text');
23
+ * const fileName = assetFileNamesToFileName(
24
+ * 'assets/[name].[hash][extname]',
25
+ * '/path/to/file.txt',
26
+ * getAssetHash(content),
27
+ * content
28
+ * )
29
+ * // fileName: 'assets/file.982d9e3e.txt'
30
+ * ```
31
+ *
32
+ * @param assetFileNames filename pattern. e.g. `'assets/[name].[hash][extname]'`
33
+ * @param file filepath of the asset
34
+ * @param contentHash hash of the asset. used for `'[hash]'` placeholder
35
+ * @param content content of the asset. passed to `assetFileNames` if `assetFileNames` is a function
36
+ * @returns output filename
37
+ */
38
+ export declare function assetFileNamesToFileName(assetFileNames: Exclude<OutputOptions['assetFileNames'], undefined>, file: string, contentHash: string, content: string | Buffer): string;
39
+ export declare function getAssetHash(content: Buffer): string;
40
+ export declare function urlToBuiltUrl(url: string, importer: string, config: ResolvedConfig, pluginContext: PluginContext): Promise<string>;