!90 适配GN 打包js/ets应用

Merge pull request !90 from zgy-ian/adapt_gn_haps
This commit is contained in:
openharmony_ci
2021-12-22 10:00:50 +00:00
committed by Gitee
3 changed files with 111 additions and 32 deletions
+79 -9
View File
@@ -134,17 +134,19 @@ action("build_ets_sysResource") {
]
}
ets_loader_sources = [
"compiler/main.js",
"compiler/npm-install.js",
"compiler/package-lock.json",
"compiler/package.json",
"compiler/tsconfig.json",
"compiler/webpack.config.js",
ets_loader_component_config_file,
]
ohos_copy("ets_loader") {
deps = [ ":build_ets_loader_library" ]
sources = [
"compiler/main.js",
"compiler/npm-install.js",
"compiler/package-lock.json",
"compiler/package.json",
"compiler/tsconfig.json",
"compiler/webpack.config.js",
ets_loader_component_config_file,
]
sources = ets_loader_sources
if (!is_standard_system) {
deps += [ ":build_ets_sysResource" ]
sources += [ ets_sysResource ]
@@ -192,3 +194,71 @@ ohos_copy("ets_loader_declaration") {
module_source_dir = target_out_dir + "/$target_name"
module_install_name = ""
}
ohos_copy("ets_loader_ark") {
deps = [ ":build_ets_loader_library" ]
sources = ets_loader_sources
if (!is_standard_system) {
deps += [ ":build_ets_sysResource" ]
sources += [ ets_sysResource ]
}
outputs = [ target_out_dir + "/$target_name/{{source_file_part}}" ]
}
ohos_copy("ets_loader_ark_lib") {
deps = [
":build_ets_loader_library",
":ets_loader_ark",
]
sources = [ ets_loader_lib_dir ]
outputs = [ target_out_dir + "/ets_loader_ark/lib" ]
}
ohos_copy("ets_loader_ark_declaration") {
deps = [
":build_ets_loader_library",
":ets_loader_ark",
]
sources = [ ets_loader_declarations_dir ]
outputs = [ target_out_dir + "/ets_loader_ark/declarations" ]
}
ohos_copy("ets_loader_ark_syntax") {
deps = [
":build_ets_loader_library",
":ets_loader_ark",
]
sources = [ ets_loader_syntax_dir ]
outputs = [ target_out_dir + "/ets_loader_ark/syntax_parser/dist" ]
}
ohos_copy("ets_loader_ark_components") {
deps = [
":build_ets_loader_library",
":ets_loader_ark",
]
sources = [ "compiler/components" ]
outputs = [ target_out_dir + "/ets_loader_ark/components" ]
}
ohos_copy("ets_loader_ark_server") {
deps = [
":build_ets_loader_library",
":ets_loader_ark",
]
sources = [ "compiler/server" ]
outputs = [ target_out_dir + "/ets_loader_ark/server" ]
}
ohos_copy("ets_loader_node_modules") {
deps = [
":ets_loader_ark",
":ets_loader_ark_components",
":ets_loader_ark_declaration",
":ets_loader_ark_lib",
":ets_loader_ark_server",
":ets_loader_ark_syntax",
]
sources = [ "//developtools/ace-ets2bundle/compiler/node_modules" ]
outputs = [ target_out_dir + "/ets_loader_ark/node_modules" ]
}
+10 -11
View File
@@ -20,33 +20,32 @@ import * as path from 'path';
import Compiler from 'webpack/lib/Compiler';
import { logger } from './compile_info';
const arkDir: string = path.join(__dirname, '..', 'bin', 'ark');
const firstFileEXT: string = '_.js';
let output: string;
let webpackPath: string;
let isWin: boolean = false;
let isMac: boolean = false;
let isDebug: boolean = false;
let arkDir: string;
let nodeJs: string;
const red: string = '\u001b[31m';
const blue: string = '\u001b[34m';
const reset: string = '\u001b[39m';
export class GenAbcPlugin {
constructor(output_, webpackPath_, isDebug_) {
constructor(output_, arkDir_, nodeJs_, isDebug_) {
output = output_;
webpackPath = webpackPath_;
arkDir = arkDir_;
nodeJs = nodeJs_;
isDebug = isDebug_;
}
apply(compiler: Compiler) {
if (fs.existsSync(path.resolve(webpackPath, 'ark/build-win'))) {
if (fs.existsSync(path.resolve(arkDir, 'build-win'))) {
isWin = true;
} else {
if (fs.existsSync(path.resolve(webpackPath, 'ark/build-mac'))) {
if (fs.existsSync(path.resolve(arkDir, 'build-mac'))) {
isMac = true;
} else {
if (!fs.existsSync(path.resolve(webpackPath, 'ark/build'))) {
if (!fs.existsSync(path.resolve(arkDir, 'build'))) {
logger.error(red, 'ETS:ERROR find build fail', reset);
return;
}
@@ -56,7 +55,7 @@ export class GenAbcPlugin {
compiler.hooks.emit.tap('GenAbcPlugin', (compilation) => {
Object.keys(compilation.assets).forEach(key => {
// choice *.js
if (output && webpackPath && path.extname(key) === '.js') {
if (output && path.extname(key) === '.js') {
const newContent: string = compilation.assets[key].source();
const keyPath: string = key.replace(/\.js$/, firstFileEXT);
writeFileSync(newContent, path.resolve(output, keyPath), key);
@@ -100,7 +99,7 @@ function js2abcFirst(inputPath: string): void {
js2abc = path.join(arkDir, 'build-mac', 'src', 'index.js');
}
const cmd: string = `node --expose-gc "${js2abc}" "${inputPath}" ${param}`;
const cmd: string = `${nodeJs} --expose-gc "${js2abc}" "${inputPath}" ${param}`;
try {
process.execSync(cmd);
+22 -12
View File
@@ -111,7 +111,7 @@ function initConfig(config) {
global: false
},
resolve: {
extensions:['.js', '.ets', '.ts'],
extensions: ['.js', '.ets', '.ts'],
modules: [
projectPath,
path.join(projectPath, '../../../../../'),
@@ -125,11 +125,12 @@ function initConfig(config) {
paths: [
/\.js$/,
/\.d\.ts$/
]}),
]
}),
new CleanWebpackPlugin(),
new ResultStates()
]
})
});
}
function setProjectConfig(envArgs) {
@@ -150,14 +151,14 @@ function setProjectConfig(envArgs) {
function setReleaseConfig(config) {
const TerserPlugin = require('terser-webpack-plugin');
config.mode = 'production';
config.optimization = {
emitOnErrors: true,
usedExports: false,
minimize: true,
minimizer: [ new TerserPlugin() ]
};
config.output.sourceMapFilename = '_releaseMap/[name].js.map';
config.mode = 'production';
config.optimization = {
emitOnErrors: true,
usedExports: false,
minimize: true,
minimizer: [new TerserPlugin()]
};
config.output.sourceMapFilename = '_releaseMap/[name].js.map';
}
function setCopyPluginConfig(config) {
@@ -211,7 +212,16 @@ module.exports = (env, argv) => {
if (env.isPreview !== "true") {
loadWorker(projectConfig);
if (env.compilerType && env.compilerType === 'ark') {
config.plugins.push(new GenAbcPlugin(projectConfig.buildPath, path.join(__dirname, 'bin'), env.buildMode === 'debug'));
let arkDir = path.join(__dirname, 'bin', 'ark');
if (env.arkFrontendDir) {
arkDir = env.arkFrontendDir;
}
let nodeJs = 'node';
if (env.nodeJs) {
nodeJs = env.nodeJs;
}
config.plugins.push(new GenAbcPlugin(projectConfig.buildPath, arkDir, nodeJs,
env.buildMode === 'debug'));
}
} else {
projectConfig.isPreview = true;