diff --git a/src/loader.js b/src/loader.js index 8240bc5cdf49c44cb361064129f2a1f1d701c66a..1ca9b4d8be20140aeacca796930a8bc54a1ca3a9 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 a8f911f19ca3fe15deb9264e6ab5ded1574c585e..5410b72d7c874d365fd079269b8df3565579e4ea 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];