mirror of
https://github.com/openharmony/developtools_ace-js2bundle.git
synced 2026-07-20 21:59:23 -04:00
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const { Compilation } = require('webpack');
|
||||
|
||||
import { mkDir } from './util';
|
||||
|
||||
const moduleReg = /(@ohos|@system)(\.[a-zA-Z0-9]+)+/g;
|
||||
|
||||
class ModuleCollectionPlugin {
|
||||
constructor() {
|
||||
}
|
||||
|
||||
apply(compiler) {
|
||||
compiler.hooks.thisCompilation.tap('rich', (compilation) => {
|
||||
compilation.hooks.processAssets.tapAsync(
|
||||
{
|
||||
name: 'MyPlugin',
|
||||
stage: Compilation.PROCESS_ASSETS_STAGE_REPOR,
|
||||
},
|
||||
(assets, back) => {
|
||||
const keys = Object.keys(assets);
|
||||
let moduleList = new Set();
|
||||
keys.forEach(key => {
|
||||
const extName = path.extname(key);
|
||||
if (extName === '.js') {
|
||||
const source = assets[key].source();
|
||||
const moduleName = source.match(moduleReg);
|
||||
if (moduleName) {
|
||||
moduleName.forEach(function(item) {
|
||||
moduleList.add(item.replace('@', ''));
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
const moduleCollection = Array.from(moduleList);
|
||||
const moduleContent = moduleCollection.length === 0 ? 'NULL' : moduleCollection.join(',');
|
||||
if (!fs.existsSync(process.env.buildPath)) {
|
||||
mkDir(process.env.buildPath);
|
||||
}
|
||||
fs.writeFileSync(path.resolve(process.env.buildPath, './module_collection.txt'),
|
||||
moduleContent);
|
||||
back && back();
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ModuleCollectionPlugin;
|
||||
@@ -21,7 +21,6 @@ var ResultStates = require('./lib/compile-plugin')
|
||||
var GenBinPlugin = require('./lib/genBin-plugin')
|
||||
var GenAbcPlugin = require('./lib/genAbc-plugin').GenAbcPlugin
|
||||
var AfterEmitPlugin = require('./lib/cardJson-plugin').AfterEmitPlugin
|
||||
var ModuleCollectionPlugin = require('./lib/module-collection-plugin')
|
||||
|
||||
const { PLATFORM }= require('./lib/lite/lite-enum')
|
||||
const util = require('./lib/util')
|
||||
@@ -203,7 +202,6 @@ function setConfigs(env) {
|
||||
}
|
||||
|
||||
function setArkPlugin(env, workerFile) {
|
||||
config.plugins.push(new ModuleCollectionPlugin())
|
||||
if (env.isPreview === "true" || env.compilerType && env.compilerType === 'ark') {
|
||||
let arkDir = path.join(__dirname, 'bin', 'ark');
|
||||
if (env.arkFrontendDir) {
|
||||
|
||||
Reference in New Issue
Block a user