import path from 'path' import { Configuration, EnvironmentPlugin } from 'webpack' import 'webpack-dev-server' import TerserPlugin from 'terser-webpack-plugin' const mode = process.env.NODE_ENV === 'production' ? 'production' : 'development' const config: Configuration = { mode, entry: path.join(__dirname, 'src', 'index.ts'), output: { clean: true, filename: 'js/index.js' }, devtool: mode === 'development' ? 'inline-source-map' : false, module: { rules: [ { test: /\.tsx?$/, use: 'ts-loader', exclude: /node_modules/ } ] }, devServer: { allowedHosts: 'all', open: true, port: 8100 }, resolve: { alias: { '@': path.resolve(__dirname, 'src') }, extensions: ['.ts', '.tsx', '.js'] }, externals: { jquery: 'jQuery', clipboard: 'ClipboardJS' }, optimization: { minimize: true, minimizer: [ new TerserPlugin({ parallel: true, terserOptions: { mangle: true } }) ] }, plugins: [ new EnvironmentPlugin(['npm_package_name', 'npm_package_version']) ] } export default config