xref: /aosp_15_r20/external/pigweed/pw_ide/ts/pigweed-vscode/webpack.config.js (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1// Copyright 2023 The Pigweed Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License"); you may not
4// use this file except in compliance with the License. You may obtain a copy of
5// the License at
6//
7//     https://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, WITHOUT
11// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12// License for the specific language governing permissions and limitations under
13// the License.
14
15'use strict';
16
17const path = require('path');
18const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');
19const webpack = require('webpack');
20
21/**@type {import('webpack').Configuration}*/
22const config = {
23  // We need access to node APIs, so we can't currently build for webworker.
24  target: 'node',
25
26  // the entry point of this extension, �� ->
27  // https://webpack.js.org/configuration/entry-context/
28  entry: './src/extension.ts',
29
30  output: {
31    // the bundle is stored in the 'dist' folder (check package.json), �� ->
32    // https://webpack.js.org/configuration/output/
33    path: path.resolve(__dirname, 'dist'),
34    filename: 'extension.js',
35    libraryTarget: 'commonjs2',
36    devtoolModuleFilenameTemplate: '../[resource-path]',
37  },
38  devtool: 'source-map',
39  plugins: [new NodePolyfillPlugin()],
40  externals: {
41    // the vscode-module is created on-the-fly and must
42    // be excluded. Add other modules that cannot be
43    // webpack'ed, �� -> https://webpack.js.org/configuration/externals/
44    vscode: 'commonjs vscode',
45  },
46  resolve: {
47    // support reading TypeScript and JavaScript files, �� ->
48    // https://github.com/TypeStrong/ts-loader
49    // look for `browser` entry point in imported node modules
50    mainFields: ['browser', 'module', 'main'],
51    extensions: ['.ts', '.js'],
52    alias: {
53      // provides alternate implementation for node module and source files
54    },
55    fallback: {
56      // Webpack 5 no longer polyfills Node.js core modules automatically.
57      // see https://webpack.js.org/configuration/resolve/#resolvefallback
58      // for the list of Node.js core module polyfills.
59    },
60  },
61  module: {
62    rules: [
63      {
64        test: /\.ts$/,
65        exclude: /node_modules/,
66        use: [{ loader: 'ts-loader' }],
67      },
68    ],
69  },
70};
71module.exports = config;
72