-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
114 lines (107 loc) · 2.52 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
102
103
104
105
106
107
108
109
110
111
112
113
114
const cloneDeep = require('lodash.clonedeep');
const fs = require('fs');
const get = require('lodash.get');
const path = require('path');
const set = require('lodash.set');
const Webpack = require('webpack');
const WebpackNodeExternals = require('webpack-node-externals');
// $FlowFixMe
const getRevision = (projectDir) => {
const gitDir = path.join(path.resolve(projectDir || '.'), '.git');
const headFile = path.join(gitDir, 'HEAD');
if (fs.existsSync(headFile)) {
const rev = fs.readFileSync(headFile).toString().split('\n')[0];
if (rev && (rev.indexOf(':') === -1)) {
return rev;
}
const revFile = path.join(gitDir, rev.substring(5));
if (fs.existsSync(revFile)) {
return fs.readFileSync(revFile).toString() || null;
}
}
return null;
};
const makeMin = (config) => {
const resConfig = cloneDeep(config);
set(resConfig, 'optimization.minimize', true);
const fnParts = get(resConfig, 'output.filename', 'index.js').split('.');
set(
resConfig,
'output.filename',
[...(fnParts.slice(0, -1)), 'min', fnParts[fnParts.length - 1]].join('.'),
);
return resConfig;
};
const ubiqConf = {
plugins: [
// For flexible nodejs/browser switch
new Webpack.DefinePlugin({
'process.env.NPYZ_VERSION': fs.readFileSync('./package.json').version,
'process.env.NPYZ_GIT_REVISION': getRevision('.'),
}),
],
target: 'node',
resolve: {
extensions: ['.webpack.js', '.web.js', '.js', '.jsx'],
modules: [
__dirname,
'node_modules',
],
},
entry: {
index: [
'@babel/polyfill',
'./src/index.js',
],
},
module: {
rules: [
{
test: /.jsx?$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
babelrc: true,
},
},
},
{
test: /\.jsx?$/,
enforce: 'pre',
use: ['remove-flow-types-loader'],
include: path.join(__dirname, 'src'),
},
],
},
devtool: 'source-map',
mode: 'production',
};
/*
const nodeConfig = {
...ubiqConf,
target: 'node',
output: {
path: path.resolve(__dirname, 'lib'),
filename: 'anymetrica-utils.js',
},
};
*/
const webConfig = {
...ubiqConf,
target: 'web',
entry: './src/stream.js',
output: {
path: path.resolve(__dirname, 'dist'),
library: 'npyz',
libraryTarget: 'umd',
globalObject: 'this',
filename: 'npyz.js',
},
optimization: {
minimize: false,
},
};
module.exports = [
webConfig, makeMin(webConfig),
];