-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
63 lines (56 loc) · 1.73 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
const path = require('path')
const CopyPlugin = require('copy-webpack-plugin')
module.exports = env => {
const isProd = env.prod === true
let type = 'lib'
// eslint-disable-next-line no-console
console.log(`Compiling: ${type} in mode: ${isProd ? 'production' : 'development'}`)
const entries = {
lib: './src/index.ts',
}
const outputPaths = {
lib: path.resolve(__dirname, 'dist'),
}
const plugins = [new CopyPlugin([{ from: 'types', to: './' }])]
const config = {
mode: "production",
entry: entries[type],
output: {
path: outputPaths[type],
filename: 'index.js',
},
devtool: 'source-map',
plugins,
resolve: {
extensions: ['.webpack.js', '.web.js', '.ts', '.tsx', '.js', '.jsx'],
},
module: {
rules: [
{ test: /\.tsx?$/, use: 'awesome-typescript-loader' },
{ test: /\.js$/, use: 'source-map-loader' },
{
test: /\.(js|jsx)$/,
use: 'babel-loader',
exclude: /node_modules/,
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
{
test: /\.svg$/,
loader: 'raw-loader',
},
],
},
}
return {
...config,
output: {
...config.output,
libraryTarget: 'commonjs2',
},
// @see https://github.com/webpack/webpack/issues/603#issuecomment-215547651
externals: /^[^.]/,
}
}