forked from alampros/react-confetti
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
65 lines (62 loc) · 1.61 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
const path = require('path')
/**
* Webpack emits sourcemap paths that have an invalid `webpack://` prefix,
* and which don't match the paths where source files will be installed by
* npm or yarn. This short function replaces all bogus sourcemap paths
* with valid relative paths relative to the folder where the source files
* will be installed when the library is installed.
* */
function devtoolModuleFilenameTemplate(info) {
const resource = info.resource
.replace('webpack://ReactConfetti/', '') // remove bogus webpath prefixes
.replace(/^\.\/node_modules\//, '../../') // at runtime, deps are uncle not sibling to dist
.replace(/^\.\/src\//, '../src/') // source folder is a sibling of dist, not child
return resource
}
const base = {
mode: 'development',
devtool: 'source-map',
entry: {
'react-confetti': ['./src/ReactConfetti.tsx'],
},
output: {
path: path.join(__dirname, 'dist'),
filename: '[name].js',
devtoolModuleFilenameTemplate,
library: 'ReactConfetti',
libraryTarget: 'umd',
libraryExport: 'default',
globalObject: 'typeof self !== "undefined" ? self : this',
},
module: {
rules: [
{
test: /\.tsx?$/,
loaders: ['babel-loader'],
exclude: [/node_modules/],
},
],
},
externals: {
react: {
root: 'React',
commonjs2: 'react',
commonjs: 'react',
amd: 'react',
},
},
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
},
}
module.exports = [
base,
{
...base,
mode: 'production',
output: {
...base.output,
filename: '[name].min.js',
},
},
]