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 globalModulePaths 28} = require('./main'); 29const { 30 getEntryObj, 31 workerFile, 32 setCopyPluginConfig 33} = require('./lib/fast_build/common/process_project_config'); 34const { 35 getResolveModules 36} = require('./lib/utils'); 37const { etsTransform } = require('./lib/fast_build/ets_ui/rollup-plugin-ets-typescript'); 38const { etsChecker } = require('./lib/fast_build/ets_ui/rollup-plugin-ets-checker'); 39const { apiTransform } = require('./lib/fast_build/system_api/rollup-plugin-system-api'); 40const { watchChangeFiles } = require('./lib/fast_build/common/rollup-plugin-watch-change'); 41const { initArkConfig } = require('./lib/fast_build/ark_compiler/common/process_ark_config'); 42const { genAbc } = require('./lib/fast_build/ark_compiler/rollup-plugin-gen-abc'); 43const { visualTransform } = require('./lib/fast_build/visual/rollup-plugin-visual'); 44const { memoryMonitor } = require('./lib/fast_build/meomry_monitor/rollup-plugin-memory-monitor'); 45 46process.env.watchMode = (process.env.watchMode && process.env.watchMode === 'true') || 'false'; 47process.env.compileTool = 'rollup'; 48 49getEntryObj(); 50if (process.env.appResource) { 51 readAppResource(process.env.appResource); 52} 53initArkConfig(process.env, projectConfig); 54 55const external = []; 56if (projectConfig.compileMode === 'esmodule' && projectConfig.harNameOhmMap) { 57 for (const harName in projectConfig.harNameOhmMap) { 58 external.push(RegExp('^(' + harName + ')($|\/\S+)')); 59 } 60} 61 62const config = { 63 input: projectConfig.entryObj, 64 watch: { 65 buildDelay: 10 66 }, 67 output: { 68 dir: path.resolve(__dirname, projectConfig.buildPath), 69 chunkFileNames: '[name].js', 70 format: 'cjs', 71 sourcemap: true 72 }, 73 external: external, 74 plugins: [ 75 // copyPlugin({targets: setCopyPluginConfig(projectConfig, process.env.appResource)}), 76 resolve({ 77 extensions: ['.js', '.ets', '.ts', '.d.ts', '.d.ets'], 78 modulePaths: [ 79 path.resolve(projectConfig.projectPath), 80 path.resolve('node_modules'), 81 path.resolve(__dirname, 'node_modules'), 82 ...globalModulePaths, 83 projectConfig.aceModuleJsonPath ? 84 ...getResolveModules(path.resolve(projectConfig.projectPath), false) : 85 ...getResolveModules(path.resolve(projectConfig.projectPath), true) 86 ] 87 }), 88 commonjs(), 89 getBabelOutputPlugin({ 90 plugins: [ 91 '@babel/plugin-proposal-class-properties' 92 ], 93 compact: false 94 }), 95 memoryMonitor(), 96 watchChangeFiles(), 97 etsChecker(), 98 visualTransform(), 99 apiTransform(), 100 etsTransform(), 101 genAbc(), 102 deletePlugin({ 103 targets: getCleanConfig(workerFile), 104 runOnce: true 105 }) 106 ] 107}; 108 109module.exports = config; 110