fingerprintjs
62 строки · 1.7 Кб
1import { ConfigOptions } from 'webpack-cli'
2import { Configuration as DevServer } from 'webpack-dev-server'
3import * as HtmlWebpackPlugin from 'html-webpack-plugin'
4import * as TerserPlugin from 'terser-webpack-plugin'
5import terserConfig from '../terser.config'
6
7const configurationFactory: ConfigOptions = (_env, { mode = 'development' }) => ({
8entry: './index.ts',
9mode,
10resolve: {
11extensions: ['.ts', '.tsx', '.js', '.jsx'],
12},
13module: {
14rules: [
15{
16test: /\.tsx?$/i,
17loader: 'ts-loader',
18exclude: /node_modules/,
19options: {
20compilerOptions: {
21sourceMap: true,
22},
23},
24},
25{
26test: /\.(jpe?g|png|svg|ico)$/i,
27loader: 'file-loader',
28options: {
29outputPath: 'assets',
30name: '[name].[ext]?[contenthash]',
31},
32},
33],
34},
35optimization: {
36minimizer: [
37new TerserPlugin({
38terserOptions: terserConfig,
39}),
40],
41},
42devtool: mode === 'development' ? 'inline-source-map' : 'source-map',
43output: {
44clean: true,
45filename: '[name].js?[contenthash]',
46},
47devServer: {
48host: '0.0.0.0',
49allowedHosts: 'all',
50} satisfies DevServer,
51plugins: [
52new HtmlWebpackPlugin({
53template: './index.html',
54title: `FingerprintJS ${mode === 'development' ? 'Playground' : 'Demo'}`,
55}),
56],
57// https://stackoverflow.com/a/71739898/1118709
58// Correct (but not worth effort) solutions: build-time macros, custom JSON loader, Rollup instead of Webpack, riot
59ignoreWarnings: [/Should not import the named export 'version' .* from default-exporting module/],
60})
61
62export default configurationFactory
63