-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.babel.js
84 lines (78 loc) · 1.86 KB
/
webpack.config.babel.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
const { resolve } = require('path');
const webpack = require('webpack');
const { name } = require('./package.json');
const getMyIp = require('get-my-ip');
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
const isDemo = process.env.REACT_DEMO && process.env.REACT_DEMO !== 'false';
const PROJECT_PATH = __dirname;
const inProject = (...args) => resolve(PROJECT_PATH, ...args);
const inSrc = inProject.bind(null, 'src');
const inTest = inProject.bind(null, 'test');
const inDemo = inProject.bind(null, 'demo');
const srcDir = inSrc();
const testDir = inTest();
const demoDir = inDemo();
module.exports = (webpackEnv = {}) => {
const { minify } = webpackEnv;
const config = {
devtool: 'source-map',
module: {
rules: [
{
test: /\.js$/,
include: [srcDir, testDir, demoDir],
loader: 'babel-loader',
options: {
presets: [['es2015', { modules: false }], 'react', 'stage-0'],
cacheDirectory: true,
babelrc: false,
},
},
],
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
}),
],
resolve: {
modules: [srcDir, 'node_modules'],
extensions: ['.js'],
},
mode: process.env.NODE_ENV,
optimization: {
minimize: !!minify,
},
devServer: {
contentBase: demoDir,
port: 3000,
host: getMyIp(),
},
};
if (isDemo) {
config.entry = './demo';
config.output = {
filename: 'bundle.js',
path: resolve(__dirname, 'demo'),
};
config.module.rules.push({
test: /\.css$/,
include: demoDir,
use: ['style-loader', 'css-loader'],
});
}
else {
config.entry = './src';
config.output = {
filename: `${name}${minify ? '.min' : ''}.js`,
path: resolve(__dirname, 'dist'),
library: 'ReactScrollView',
libraryTarget: 'umd',
};
config.externals = {
react: 'React',
'react-dom': 'ReactDom',
};
}
return config;
};