From b5d7dcd7cc4021534b40d697137ec8932f0e88eb Mon Sep 17 00:00:00 2001 From: zhongjianfei Date: Thu, 2 Sep 2021 11:16:25 +0800 Subject: [PATCH] zhongjianfei@huawei.com Signed-off-by: zhongjianfei Change-Id: I462079c2ccf6ee400fd630d731a1a5c21185c745 --- src/loader.js | 11 +++++++++-- src/script.js | 3 +-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/loader.js b/src/loader.js index 8240bc5..1ca9b4d 100644 --- a/src/loader.js +++ b/src/loader.js @@ -141,7 +141,7 @@ function scriptLoaderString (loaders, config, customLoader) { name: defaultLoaders.resourceReferenceScript }) } - if (config.app) { + if (config.app && process.env.abilityType === 'page') { loaders.push({ name: defaultLoaders.manifest, query: { @@ -194,10 +194,17 @@ function loader (source) { return output } +function checkApp(_this) { + return ["app.js", "data.js", "service.js"].some(item => { + const type = item === "app.js" ? "page" : item === "data.js" ? "data" : item === "service.js" ? "service" : item; + return _this.resourcePath.indexOf(item) > 0 && process.env.abilityType === type + }) +} + function loadApp (_this, name, isEntry, customLang) { let output = '' let extcss = false - if (_this.resourcePath.indexOf('app.js') > 0) { + if (checkApp(_this)) { const filename = _this.resourcePath.replace(path.extname(_this.resourcePath).toString(), '') // find css const cssFileName = filename + '.css' diff --git a/src/script.js b/src/script.js index a8f911f..5410b72 100644 --- a/src/script.js +++ b/src/script.js @@ -32,7 +32,6 @@ const { DEVICE_LEVEL } = require('./lite/lite-enum') module.exports = function (source, map) { this.cacheable && this.cacheable() const callback = this.async() - parseScript(source, this.resourcePath) .then(({ parsed, log @@ -42,7 +41,7 @@ module.exports = function (source, map) { } parsed = parseRequireModule(parsed) if (process.env.DEVICE_LEVEL === DEVICE_LEVEL.RICH) { - if (path.basename(this.resourcePath) !== 'app.js') { + if (!["app.js","data.js","service.js"].includes(path.basename(this.resourcePath))) { parsed += `\nvar moduleOwn = exports.default || module.exports;\nvar accessors = ['public', 'protected', 'private']; if (moduleOwn.data && accessors.some(function (acc) { return moduleOwn[acc]; -- Gitee