UNPKG

create-foxglove-extension

Version:
90 lines (89 loc) 3.84 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); const clean_webpack_plugin_1 = require("clean-webpack-plugin"); const path = __importStar(require("path")); exports.default = (extensionPath, entryPoint, env) => { const resolvedExtensionPath = path.resolve(extensionPath); const isDev = env == undefined || env === "development"; const configFile = path.join(resolvedExtensionPath, "tsconfig.json"); const config = { target: "web", mode: isDev ? "development" : "production", context: resolvedExtensionPath, entry: entryPoint, output: { path: path.join(resolvedExtensionPath, "dist"), filename: "extension.js", libraryTarget: "commonjs2", }, // Always use the eval-source-map option so the source map is included in the source file. // Because Foxglove _evals_ the extension script to run it - the source map must be inline with // the source file. Using a separate source map file does not work. devtool: "eval-source-map", externals: { "@foxglove/extension": "@foxglove/extension", }, resolve: { extensions: [".js", ".ts", ".jsx", ".tsx"], // The spirit of our fallback configuration is to do the expected thing when encountering a // native nodejs require. // // i.e. It wouldn't be surprising the `fs` module doesn't work since there's no file system in // extensions but it would be surprising the `path` doesn't work since thats just string // manipulation. fallback: { path: require.resolve("path-browserify"), // Since extensions don't have file-system access we disable any fallback for importing `fs` // This improves the out-of-the-box experience when importing files that require('fs') (i.e. // generated emscripten js loaders) without having to make a custom configuration to disable // fs fallback. fs: false, }, }, module: { rules: [ { test: /\.tsx?$/, exclude: /node_modules/, use: [ { loader: "ts-loader", options: { configFile, }, }, ], }, { test: /\.css$/i, use: ["style-loader", "css-loader"], }, ], }, plugins: [new clean_webpack_plugin_1.CleanWebpackPlugin()], }; return config; };