forked from ravihamsa/react-starter-components
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
202 lines (167 loc) · 5.84 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/**
* Created by ravi.hamsa on 6/22/16.
*/
var path = require('path');
var fs = require('fs');
var webpack = require('webpack');
var nodeModulesPath = path.resolve(__dirname, 'node_modules');
var buildPath = path.resolve(__dirname, 'public', 'dist');
var buildPathNode = path.resolve(__dirname, 'lib');
var mainPath = path.resolve(__dirname, 'app', 'main.js');
const DEBUG = process.env.NODE_ENV !== 'production';
const AUTOPREFIXER_BROWSERS = [
'Android 2.3',
'Android >= 4',
'Chrome >= 35',
'Firefox >= 31',
'Explorer >= 9',
'iOS >= 7',
'Opera >= 12',
'Safari >= 7.1',
];
var config = {
entry: ['./src/main.js'],
devtool: DEBUG ? 'cheap-module-eval-source-map' : false,
output: {
// We need to give Webpack a path. It does not actually need it,
// because files are kept in memory in webpack-dev-server, but an
// error will occur if nothing is specified. We use the buildPath
// as that points to where the files will eventually be bundled
// in production
path: buildPath,
filename: 'bundle.js',
// Everything related to Webpack should go through a build path,
// localhost:3000/build. That makes proxying easier to handle
publicPath: '/build/'
},
externals: {
// Use external version of React
"react": "React",
"react-dom": "ReactDOM",
"moment":"moment"
},
module: {
loaders: [
// I highly recommend using the babel-loader as it gives you
// ES6/7 syntax and JSX transpiling out of the box
{
test: /\.js$/,
loaders: ['babel'],
exclude: [nodeModulesPath]
},
{
test: /\.scss$/,
loaders: [
'isomorphic-style-loader',
`css-loader?${JSON.stringify({
sourceMap: DEBUG,
// CSS Modules https://github.com/css-modules/css-modules
modules: true,
localIdentName: DEBUG ? '[name]_[local]_[hash:base64:3]' : '[hash:base64:4]',
// CSS Nano http://cssnano.co/options/
minimize: !DEBUG,
})}`,
'postcss-loader?parser=postcss-scss',
],
},
{
test: /\.(png|jpg|jpeg|gif|svg|woff|woff2)$/,
loader: 'url-loader',
query: {
name: DEBUG ? '[path][name].[ext]?[hash]' : '[hash].[ext]',
limit: 10000,
},
},
]
},
postcss(bundler) {
return [
require('postcss-import')({addDependencyTo: bundler}),
require('precss')(),
require('autoprefixer')({browsers: AUTOPREFIXER_BROWSERS}),
];
},
plugins: DEBUG ? [] : [
new webpack.optimize.UglifyJsPlugin({
compress: {
screw_ie8: true, // jscs:ignore requireCamelCaseOrUpperCaseIdentifiers
warnings: false,
},
})]
}
var nodeModules = {};
fs.readdirSync('node_modules')
.filter(function(x) {
return ['.bin'].indexOf(x) === -1;
})
.forEach(function(mod) {
nodeModules[mod] = 'commonjs ' + mod;
});
var configNode = {
entry: ['./src/index.js'],
devtool: DEBUG ? 'cheap-module-eval-source-map' : false,
target: 'node',
output: {
// We need to give Webpack a path. It does not actually need it,
// because files are kept in memory in webpack-dev-server, but an
// error will occur if nothing is specified. We use the buildPath
// as that points to where the files will eventually be bundled
// in production
path: buildPathNode,
filename: 'index.js',
// Everything related to Webpack should go through a build path,
// localhost:3000/build. That makes proxying easier to handle
publicPath: '/lib/',
libraryTarget: 'commonjs2'
},
externals: nodeModules,
module: {
loaders: [
// I highly recommend using the babel-loader as it gives you
// ES6/7 syntax and JSX transpiling out of the box
{
test: /\.js$/,
loaders: ['babel'],
exclude: [nodeModulesPath]
},
{
test: /\.scss$/,
loaders: [
'isomorphic-style-loader',
`css-loader?${JSON.stringify({
sourceMap: DEBUG,
// CSS Modules https://github.com/css-modules/css-modules
modules: true,
localIdentName: DEBUG ? '[name]_[local]_[hash:base64:3]' : '[hash:base64:4]',
// CSS Nano http://cssnano.co/options/
minimize: !DEBUG,
})}`,
'postcss-loader?parser=postcss-scss',
],
},
{
test: /\.(png|jpg|jpeg|gif|svg|woff|woff2)$/,
loader: 'url-loader',
query: {
name: DEBUG ? '[path][name].[ext]?[hash]' : '[hash].[ext]',
limit: 10000,
},
},
]
},
postcss(bundler) {
return [
require('postcss-import')({addDependencyTo: bundler}),
require('precss')(),
require('autoprefixer')({browsers: AUTOPREFIXER_BROWSERS}),
];
},
plugins: DEBUG ? [] : [
new webpack.optimize.UglifyJsPlugin({
compress: {
screw_ie8: true, // jscs:ignore requireCamelCaseOrUpperCaseIdentifiers
warnings: false,
},
})]
}
module.exports = [config, configNode];