-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.babel.js
102 lines (94 loc) · 2.15 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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 isExample = process.env.BUILD_EXAMPLE;
const PROJECT_PATH = __dirname;
const inProject = (...args) => resolve(PROJECT_PATH, ...args);
const inSrc = inProject.bind(null, 'src');
const inTest = inProject.bind(null, 'test');
const inExample = inProject.bind(null, 'example');
const srcDir = inSrc();
const testDir = inTest();
const exampleDir = inExample();
module.exports = (webpackEnv = {}) => {
const { minify } = webpackEnv;
const config = {
devtool: 'source-map',
module: {
rules: [
{
test: /\.js$/,
include: [srcDir, testDir, exampleDir],
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'],
},
resolveLoader: {
moduleExtensions: ['-loader'],
},
devServer: {
port: 3000,
host: getMyIp(),
contentBase: exampleDir,
// hot: true,
quiet: false,
noInfo: false,
stats: 'errors-only',
historyApiFallback: {
disableDotRule: true,
},
},
};
if (isExample) {
config.entry = './example';
config.output = {
filename: 'bundle.js',
path: resolve(__dirname, 'example'),
};
config.module.rules.push(
{
test: /\.scss$/,
include: exampleDir,
use: ['style', 'css', 'postcss', 'sass'],
},
{
test: /\.es$/,
include: exampleDir,
use: ['raw'],
},
);
}
else {
config.entry = './src';
config.output = {
filename: `${name}${minify ? '.min' : ''}.js`,
path: resolve(__dirname, 'dist'),
library: 'ReactPanResponder',
libraryTarget: 'umd',
};
config.externals = {
react: 'React',
'react-dom': 'ReactDom',
};
}
if (minify) {
config.plugins.push(new webpack.optimize.UglifyJsPlugin());
}
return config;
};