//@ts-check 'use strict'; const path = require('path'); const CopyWebpackPlugin = require('copy-webpack-plugin'); //@ts-check /** @typedef {import('webpack').Configuration} WebpackConfig **/ /** @type WebpackConfig */ const extensionConfig = { target: 'node', mode: process.env.NODE_ENV === 'production' ? 'production' : 'none', entry: './src/extension.ts', output: { path: path.resolve(__dirname, 'dist'), filename: 'extension.js', libraryTarget: 'commonjs2', clean: true // 自动清理旧文件 }, externals: { vscode: 'commonjs vscode', 'node-notifier': 'commonjs node-notifier' }, resolve: { extensions: ['.ts', '.js'], mainFields: ['module', 'main'] }, module: { rules: [ { test: /\.ts$/, exclude: /node_modules/, use: [ { loader: 'ts-loader', options: { transpileOnly: true, // 加快编译速度 compilerOptions: { sourceMap: true } } } ] } ] }, devtool: process.env.NODE_ENV === 'production' ? 'hidden-source-map' : 'nosources-source-map', infrastructureLogging: { level: "log", }, plugins: [ new CopyWebpackPlugin({ patterns: [ { from: 'src/assets', to: 'assets' } ] }) ], optimization: { minimize: process.env.NODE_ENV === 'production', usedExports: true // Tree Shaking }, performance: { hints: 'warning', maxAssetSize: 2 * 1024 * 1024, // 2MB maxEntrypointSize: 2 * 1024 * 1024 } }; module.exports = [ extensionConfig ];