-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
67 lines (61 loc) · 1.43 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
'use strict'
const webpack = require('webpack')
const nodeExternals = require('webpack-node-externals')
const path = require('path')
const env = require('yargs').argv.env
process.env.BABEL_ENV = env
process.env.NODE_ENV = env
let libraryName = 'my-awesome-library'
let plugins = [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(process.env.NODE_ENV)
}
}),
new webpack.NamedModulesPlugin()
]
if (env === 'production') {
plugins.push(new webpack.optimize.UglifyJsPlugin({ minimize: true }))
}
const paths = {
libSrc: path.resolve(__dirname, 'src'),
libIndex: path.resolve(__dirname, 'src/index.js'),
libOutputDir: path.resolve(__dirname, 'lib'),
libModules: path.resolve(__dirname, 'node_modules')
}
module.exports = {
entry: paths.libIndex,
devtool: 'source-map',
output: {
path: paths.libOutputDir,
filename: libraryName + '.js',
library: libraryName,
libraryTarget: 'umd',
umdNamedDefine: true
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: ['babel-loader']
},
{
test: /\.(jpe?g|png|gif|svg)$/i,
use: [
'url-loader?limit=10000',
'img-loader'
]
}
]
},
resolve: {
modules: [paths.libModules, paths.libSrc],
extensions: ['.json', '.js', '.jsx']
},
externals: [nodeExternals()],
plugins: plugins,
node: {
fs: 'empty'
}
}