-
Notifications
You must be signed in to change notification settings - Fork 7
/
webpack.config.js
105 lines (96 loc) · 2.39 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
/**
* Created by tdzl2003 on 10/3/16.
*/
/**
* Created by Yun on 2015-11-28.
*/
/* eslint-disable import/no-extraneous-dependencies, no-underscore-dangle */
global.__DEV__ = process.env.NODE_ENV !== 'production';
global.__PLATFORM__ = process.env.RN_PLATFORM || 'ios';
const path = require('path');
const webpack = require('webpack');
const CleanPlugin = require('clean-webpack-plugin');
const {AssetsResolverPlugin, findProvidesModule} = require('react-native-webpack');
const assetsPath = path.join(__dirname,
'build',
__DEV__ ? 'debug' : 'release'
);
const babelLoader = `babel?${JSON.stringify({
presets: ['react-native'],
plugins: [
'syntax-trailing-function-commas',
'transform-flow-strip-types',
require.resolve('react-native-webpack/fixRequireIssuePlugin'),
],
})}`
module.exports = {
context: __dirname,
entry: {
index: [
'react-native-webpack/clients/polyfills.js',
`./index.${__PLATFORM__}.js`,
],
},
output: {
path: assetsPath,
filename: `[name].${__PLATFORM__}.bundle`,
chunkFilename: '[name].chunk.js',
publicPath: '/',
},
module: {
loaders: [
{
test: /\.jsx?$/, loaders: [
babelLoader,
]
},
{ test: /\.json$/, loader: 'json-loader' },
],
},
progress: true,
resolve: {
modulesDirectories: [
'src',
'node_modules',
],
alias: findProvidesModule([
path.resolve(process.cwd(), 'node_modules/react-native'),
]),
extensions: ['', `.${__PLATFORM__}.js`, '.js'],
},
plugins: [
new webpack.DefinePlugin({
__DEV__,
'process.env': {
// Useful to reduce the size of client-side libraries, e.g. react
NODE_ENV: __DEV__ ? JSON.stringify('development') : JSON.stringify('production'),
},
}),
new AssetsResolverPlugin(),
].concat(__DEV__ ? [
] : [
new CleanPlugin([assetsPath]),
new webpack.IgnorePlugin(/\.\/dev/, /\/config$/),
// optimizations
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
},
}),
]),
devServer: {
port: 8081,
quiet: false,
noInfo: true,
lazy: true,
filename: `[name].${__PLATFORM__}.bundle`,
watchOptions: {
aggregateTimeout: 300,
poll: 1000,
},
publicPath: '/',
stats: { colors: true },
},
};