/* * Copyright (c) 2020 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 CopyPlugin = require('copy-webpack-plugin'); const { CleanWebpackPlugin } = require('clean-webpack-plugin'); const Webpack = require('webpack'); const { GenAbcPlugin } = require('./lib/gen_abc_plugin'); const buildPipeServer = require('./server/build_pipe_server'); const { projectConfig, loadEntryObj, readAppResource, loadWorker, abilityConfig, readWorkerFile, checkAppResourcePath, addSDKBuildDependencies } = require('./main'); const { ResultStates } = require('./lib/compile_info'); const { processUISyntax } = require('./lib/process_ui_syntax'); const { IGNORE_ERROR_CODE } = require('./lib/utils'); const { BUILD_SHARE_PATH } = require('./lib/pre_define'); process.env.watchMode = (process.env.watchMode && process.env.watchMode === 'true') || 'false'; function initConfig(config) { const projectPath = path.resolve(projectConfig.projectPath); Object.assign(config, { entry: projectConfig.entryObj, watch: process.env.watchMode === 'true', watchOptions: { aggregateTimeout: 10, poll: false, ignored: /node_modules/ }, output: { path: path.resolve(__dirname, projectConfig.buildPath), filename: '[name].js', devtoolModuleFilenameTemplate: 'webpack:///[absolute-resource-path]', globalObject: 'globalThis' }, devtool: 'nosources-source-map', mode: 'development', module: { rules: [ { test:/\.(jpg|png|gif|jpeg|mp3|mp4|svg)$/, use:{ loader:'url-loader' } }, { test: /\.d\.ts/, loader: 'ignore-loader' }, { test: /(? { const config = {}; setProjectConfig(env); loadEntryObj(projectConfig); initConfig(config); const workerFile = readWorkerFile(); setOptimizationConfig(config, workerFile); setCopyPluginConfig(config); setCleanWebpackPlugin(workerFile, config); if (env.isPreview !== "true") { loadWorker(projectConfig, workerFile); if (env.compilerType && env.compilerType === 'ark') { 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')); if (env.buildMode === 'release') { config.output.path = path.join(projectConfig.cachePath, 'releaseAssets', path.basename(projectConfig.buildPath)) } } } else { projectConfig.isPreview = true; projectConfig.checkEntry = env.checkEntry; let port; process.argv.forEach((val, index) => { if(val.startsWith('port=')){ port = val.split('=')[1]; } }); if (port) { buildPipeServer.init(port); } } if (env.sourceMap === 'none') { config.devtool = false; } if (env.buildMode === 'release') { setReleaseConfig(config); } const appResourcePath = env.appResource || process.env.appResource; checkAppResourcePath(appResourcePath, config); addSDKBuildDependencies(config); config.output.library = projectConfig.hashProjectPath; return config; }