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