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 TerserPlugin = require('terser-webpack-plugin');
18const webpack = require('webpack');
19const packageInfo = require('./package.json');
20
21module.exports = (env, argv) => {
22  const config = {
23    name: 'JSDoc formatter plugin',
24    target: 'node',
25    mode: 'none',
26    entry: './src/main.ts',
27    module: {
28      rules: [
29        {
30          test: /\.ts$/,
31          include: path.resolve(__dirname, 'src'),
32          exclude: [
33            /node_modules/,
34            /test/
35          ],
36          loader: 'ts-loader',
37          options: {
38            onlyCompileBundledFiles: true,
39          },
40        },
41        {
42          test: /build\.json$/,
43          use: [
44            {
45              loader: path.resolve(__dirname, 'loader/flavor.js'),
46            }
47          ],
48        }
49      ],
50    },
51    resolve: {
52      extensions: ['.js', '.ts', '.json'],
53    },
54    output: {
55      filename: 'bundle.js',
56      path: path.resolve(__dirname, './build'),
57    },
58    optimization: {
59      minimize: true,
60      minimizer: [new TerserPlugin({ extractComments: false })],
61    },
62    plugins: [
63      new webpack.BannerPlugin({
64        banner: `version:${packageInfo.version}`,
65        raw: false,
66        entryOnly: true,
67      })
68    ],
69  };
70  return config;
71};