1/* 2 * Copyright (c) 2022 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 CleanWebpackPlugin = require('clean-webpack-plugin'); 18 19// the path(s) that should be cleaned 20let pathsToClean = ['dist']; 21 22// the clean options to use 23let cleanOptions = { 24 root: path.resolve(__dirname), 25 verbose: true, 26 dry: false, 27}; 28 29function initConfig(config, envArgs) { 30 console.log(envArgs.buildMode); 31 Object.assign(config, { 32 optimization: { 33 minimize: envArgs.buildMode !== 'debug' 34 }, 35 resolve: { 36 extensions: ['.js', '.ts'], 37 }, 38 devtool: 'source-map', 39 mode: 'development', 40 entry: { 41 'index': './src/index.ts', 42 }, 43 output: { 44 filename: '[name].js', 45 path: path.resolve(__dirname, 'dist/src'), 46 libraryTarget: 'commonjs', 47 }, 48 module: { 49 rules: [ 50 { 51 test: /\.tsx?$/, 52 use: [ 53 { 54 loader: 'ts-loader', 55 options: { 56 configFile: path.resolve(__dirname, './tsconfig.json'), 57 }, 58 }, 59 ], 60 exclude: /node_modules/, 61 }, 62 ], 63 }, 64 plugins: [new CleanWebpackPlugin(pathsToClean, cleanOptions)], 65 target: 'node', 66 node:{ 67 __dirname: false, 68 __filename: false, 69 global: false 70 } 71 }); 72} 73 74module.exports = (env, argv) => { 75 const config = {}; 76 initConfig(config, env) 77 return config; 78}; 79