-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
41 lines (38 loc) · 1.1 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
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const fs = require('fs')
const path = require('path')
// const webpack = require('webpack')
const nodeModules = {}
fs.readdirSync(path.resolve(__dirname, 'node_modules'))
.filter(x => ['.bin'].indexOf(x) === -1)
.forEach(mod => { nodeModules[mod] = `commonjs ${mod}` })
// es5 style alternative
/* fs.readdirSync(path.resolve(__dirname, 'node_modules'))
.filter(function(x) {
return ['.bin'].indexOf(x) === -1
}).forEach(function(mod) {
nodeModules[mod] = 'commonjs ' + mod
}) */
// https://webpack.js.org/guides/code-splitting/
const outputDirectory = 'lib'
module.exports = {
mode: 'production',
entry: './src/index.js',
output: {
path: path.resolve(__dirname, outputDirectory),
filename: 'index.js',
libraryTarget: 'commonjs2'
},
externals: nodeModules,
module: {
rules: [{
test: /\.js?$/,
include: path.resolve(__dirname, 'src'),
exclude: [/(node_modules)/, /\.test.jsx?$/],
use: 'babel-loader'
}]
},
plugins: [
new CleanWebpackPlugin({ outputPath: outputDirectory })
]
}