1/* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16const path = require('path'); 17const commonjs = require('@rollup/plugin-commonjs'); 18const resolve = require('@rollup/plugin-node-resolve'); 19const copyPlugin = require('rollup-plugin-copy'); 20const deletePlugin = require('rollup-plugin-delete'); 21const { getBabelOutputPlugin } = require('@rollup/plugin-babel'); 22 23const { 24 projectConfig, 25 readAppResource, 26 getCleanConfig 27} = require('./main'); 28const { 29 getEntryObj, 30 workerFile, 31 setCopyPluginConfig 32} = require('./lib/fast_build/common/process_project_config'); 33const { 34 getResolveModules 35} = require('./lib/utils'); 36const { etsTransform } = require('./lib/fast_build/ets_ui/rollup-plugin-ets-typescript'); 37const { etsChecker } = require('./lib/fast_build/ets_ui/rollup-plugin-ets-checker'); 38const { apiTransform } = require('./lib/fast_build/system_api/rollup-plugin-system-api'); 39const { watchChangeFiles } = require('./lib/fast_build/common/rollup-plugin-watch-change'); 40const { initArkConfig } = require('./lib/fast_build/ark_compiler/common/process_ark_config'); 41const { genAbc } = require('./lib/fast_build/ark_compiler/rollup-plugin-gen-abc'); 42const { visualTransform } = require('./lib/fast_build/visual/rollup-plugin-visual'); 43 44process.env.watchMode = (process.env.watchMode && process.env.watchMode === 'true') || 'false'; 45process.env.compileTool = 'rollup'; 46 47getEntryObj(); 48if (process.env.appResource) { 49 readAppResource(process.env.appResource); 50} 51initArkConfig(process.env, projectConfig); 52 53const external = []; 54if (projectConfig.compileMode === 'esmodule' && projectConfig.harNameOhmMap) { 55 for (const harName in projectConfig.harNameOhmMap) { 56 external.push(RegExp('^(' + harName + ')($|\/\S+)')); 57 } 58} 59 60const config = { 61 input: projectConfig.entryObj, 62 watch: { 63 buildDelay: 10 64 }, 65 output: { 66 dir: path.resolve(__dirname, projectConfig.buildPath), 67 chunkFileNames: '[name].js', 68 format: 'cjs', 69 sourcemap: true 70 }, 71 external: external, 72 plugins: [ 73 // copyPlugin({targets: setCopyPluginConfig(projectConfig, process.env.appResource)}), 74 resolve({ 75 extensions: ['.js', '.ets', '.ts', '.d.ts', '.d.ets'], 76 modulePaths: [ 77 path.resolve(projectConfig.projectPath), 78 path.resolve('node_modules'), 79 path.resolve(__dirname, 'node_modules'), 80 path.resolve(__dirname, '../../api'), 81 projectConfig.aceModuleJsonPath ? 82 ...getResolveModules(path.resolve(projectConfig.projectPath), false) : 83 ...getResolveModules(path.resolve(projectConfig.projectPath), true) 84 ] 85 }), 86 commonjs(), 87 getBabelOutputPlugin({ 88 plugins: [ 89 '@babel/plugin-proposal-class-properties' 90 ], 91 compact: false 92 }), 93 watchChangeFiles(), 94 etsChecker(), 95 visualTransform(), 96 apiTransform(), 97 etsTransform(), 98 genAbc(), 99 deletePlugin({ 100 targets: getCleanConfig(workerFile), 101 runOnce: true 102 }) 103 ] 104}; 105 106module.exports = config; 107