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 configForVsCodeExt = { 23 target: ['node', 'es2020'], // Target Node.js environment 24 entry: './src/extension.ts', 25 output: { 26 path: path.resolve(__dirname, 'dist'), 27 filename: 'extension.js', 28 libraryTarget: 'commonjs2', 29 devtoolModuleFilenameTemplate: '../[resource-path]', 30 // clean: true, 31 }, 32 devtool: 'source-map', 33 plugins: [new NodePolyfillPlugin()], 34 externals: { 35 vscode: 'commonjs vscode', 36 }, 37 resolve: { 38 extensions: ['.ts', '.js'], 39 }, 40 module: { 41 rules: [ 42 { 43 test: /\.ts$/, 44 exclude: /node_modules/, 45 use: [ 46 { 47 loader: 'ts-loader', 48 options: { 49 configFile: 'tsconfig.json', 50 }, 51 }, 52 ], 53 }, 54 ], 55 }, 56}; 57 58/**@type {import('webpack').Configuration}*/ 59const configForWebview = { 60 target: 'web', // Target browser environment 61 entry: './src/webview/index.ts', 62 output: { 63 path: path.resolve(__dirname, 'dist'), 64 filename: 'webview.js', 65 libraryTarget: 'umd', // or 'var', depending on your needs 66 globalObject: 'this', // Important for webviews 67 // clean: true, 68 }, 69 devtool: 'source-map', 70 resolve: { 71 mainFields: ['browser', 'module', 'main'], 72 extensions: ['.ts', '.js'], 73 }, 74 module: { 75 rules: [ 76 { 77 test: /\.ts$/, 78 exclude: /node_modules/, 79 use: [ 80 { 81 loader: 'ts-loader', 82 options: { 83 configFile: 'tsconfig.webview.json', 84 }, 85 }, 86 ], 87 }, 88 { 89 test: /\.css$/, 90 use: ['style-loader', 'css-loader'], 91 }, 92 // { 93 // test: /\.(png|jpg|jpeg|gif|ttf|svg)($|\?)/, 94 // loader: "file-loader", 95 // type: 'asset/resource', 96 // options: { 97 // name: "[name].[contenthash].[ext]", 98 // outputPath: "assets", 99 // }, 100 // }, 101 ], 102 }, 103}; 104 105module.exports = [configForVsCodeExt, configForWebview]; 106