forked from segmentio/analytics-next
-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.config.js
101 lines (96 loc) · 2.4 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
const path = require('path')
const webpack = require('webpack')
const TerserPlugin = require('terser-webpack-plugin')
const CompressionPlugin = require('compression-webpack-plugin')
const BundleAnalyzerPlugin =
require('webpack-bundle-analyzer').BundleAnalyzerPlugin
const CircularDependencyPlugin = require('circular-dependency-plugin')
const isProd = process.env.NODE_ENV === 'production'
const ASSET_PATH = isProd
? 'https://cdn.june.so/analytics-next/bundles/'
: '/dist/umd/'
const plugins = [
new CompressionPlugin({}),
new webpack.EnvironmentPlugin({
ASSET_PATH,
}),
new CircularDependencyPlugin({
failOnError: true,
}),
]
if (process.env.ANALYZE) {
plugins.push(new BundleAnalyzerPlugin())
}
/** @type { import('webpack').Configuration } */
const config = {
stats: process.env.WATCH === 'true' ? 'errors-warnings' : 'normal',
node: {
global: false, // do not polyfill global object, we can use getGlobal function if needed.
},
mode: process.env.NODE_ENV || 'development',
devtool: 'source-map',
entry: {
index: {
import: path.resolve(__dirname, 'src/browser/browser-umd.ts'),
library: {
name: 'AnalyticsNext',
type: 'umd',
},
},
standalone: {
import: path.resolve(__dirname, 'src/browser/standalone.ts'),
library: {
name: 'AnalyticsNext',
type: 'window',
},
},
},
output: {
publicPath: '', // Hack - we're overriding publicPath but IE needs this set or it won't load.
filename: '[name].js',
path: path.resolve(__dirname, 'dist/umd'),
chunkFilename: '[name].bundle.[contenthash].js',
},
target: ['web', 'es5'],
module: {
rules: [
{
test: /\.tsx?$/,
use: [
{
loader: 'ts-loader',
options: {
configFile: 'tsconfig.build.json',
transpileOnly: true,
},
},
],
},
],
},
resolve: {
extensions: ['.ts', '.js'],
},
devServer: {
contentBase: path.resolve(__dirname, 'dist/umd'),
},
optimization: {
moduleIds: 'deterministic',
minimize: isProd,
minimizer: [
new TerserPlugin({
extractComments: false,
terserOptions: {
ecma: '2015',
mangle: true,
compress: true,
output: {
comments: false,
},
},
}),
],
},
plugins,
}
module.exports = config