• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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');
44
45process.env.watchMode = (process.env.watchMode && process.env.watchMode === 'true') || 'false';
46process.env.compileTool = 'rollup';
47
48getEntryObj();
49if (process.env.appResource) {
50  readAppResource(process.env.appResource);
51}
52initArkConfig(process.env, projectConfig);
53
54const external = [];
55if (projectConfig.compileMode === 'esmodule' && projectConfig.harNameOhmMap) {
56  for (const harName in projectConfig.harNameOhmMap) {
57    external.push(RegExp('^(' + harName + ')($|\/\S+)'));
58  }
59}
60
61const config = {
62  input: projectConfig.entryObj,
63  watch: {
64    buildDelay: 10
65  },
66  output: {
67    dir: path.resolve(__dirname, projectConfig.buildPath),
68    chunkFileNames: '[name].js',
69    format: 'cjs',
70    sourcemap: true
71  },
72  external: external,
73  plugins: [
74    // copyPlugin({targets: setCopyPluginConfig(projectConfig, process.env.appResource)}),
75    resolve({
76      extensions: ['.js', '.ets', '.ts', '.d.ts', '.d.ets'],
77      modulePaths: [
78        path.resolve(projectConfig.projectPath),
79        path.resolve('node_modules'),
80        path.resolve(__dirname, 'node_modules'),
81        ...globalModulePaths,
82        projectConfig.aceModuleJsonPath ?
83          ...getResolveModules(path.resolve(projectConfig.projectPath), false) :
84          ...getResolveModules(path.resolve(projectConfig.projectPath), true)
85      ]
86    }),
87    commonjs(),
88    getBabelOutputPlugin({
89      plugins: [
90        '@babel/plugin-proposal-class-properties'
91      ],
92      compact: false
93    }),
94    watchChangeFiles(),
95    etsChecker(),
96    visualTransform(),
97    apiTransform(),
98    etsTransform(),
99    genAbc(),
100    deletePlugin({
101      targets: getCleanConfig(workerFile),
102      runOnce: true
103    })
104  ]
105};
106
107module.exports = config;
108