-
Notifications
You must be signed in to change notification settings - Fork 6
/
webpack.conf.js
executable file
·198 lines (186 loc) · 4.74 KB
/
webpack.conf.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
import webpack from 'webpack';
import path from 'path';
import HtmlWebpackPlugin from 'html-webpack-plugin';
export const WEBPACK_HOST = process.env.HOST || 'localhost'
export const WEBPACK_PORT = process.env.PORT || 3003;
export const PATHS = {
SRC: path.resolve(__dirname, 'src'),
DEMO: path.resolve(__dirname, 'demo'),
UTILS: path.resolve(__dirname, 'utils'),
DIST: path.resolve(__dirname, 'dist'),
NODE_MODULES: path.resolve(__dirname, 'node_modules'),
PUBLIC: '/'
};
const AUTOPREFIXER_CONF = [
'{browsers:["last 5 version"]}'
].join('&');
const SASS_LOADER_CONF = [
`includePaths[]=${PATHS.SRC}`
].join('&');
const RESOLVE = {
extensions: ['', '.js', '.jsx', '.css', '.scss', '.json'],
modulesDirectories: ['node_modules', 'web_modules'],
alias: {
utils: PATHS.UTILS
}
};
const EXTERNALS = {
'react': {
root: 'React',
commonjs2: 'react',
commonjs: 'react',
amd: 'react',
umd: 'react'
},
'react-dom': {
root: 'ReactDOM',
commonjs2: 'react-dom',
commonjs: 'react-dom',
amd: 'react-dom',
umd: 'react-dom'
},
'react-addons-transition-group': {
root: 'ReactTransitionGroup',
commonjs2: 'react-addons-transition-group',
commonjs: 'react-addons-transition-group',
amd: 'react-addons-transition-group',
umd: 'react-addons-transition-group'
}
};
const CSS_MODULES_CONF = 'modules&localIdentName=[name]__[local]___[hash:base64:5]';
export const build = {
entry: {
src: path.resolve(PATHS.SRC, 'deck.js')
},
resolve: RESOLVE,
output: {
path: PATHS.DIST,
filename: 'deck.js',
publicPath: PATHS.PUBLIC,
sourceMapFilename: 'deck.map.json',
library: 'ReactDeck',
libraryTarget: 'umd'
},
module: {
loaders: [{
test: /\.jsx?$/,
loader: 'babel',
include: [PATHS.SRC, PATHS.UTILS]
}, {
test: /\.(css|scss)$/,
loader: `style!css?importLoaders=2&${CSS_MODULES_CONF}!autoprefixer?${AUTOPREFIXER_CONF}!sass`,
include: [PATHS.SRC]
}, {
test: /\.(png|woff|woff2|eot|ttf|svg)(\?t=[0-9]+)?$/,
loader: `url?limit=100000000`
}]
},
devtool: 'sourcemap',
externals: EXTERNALS,
};
export const demo = {
entry: {
demo: [
'webpack-dev-server/client?http://' + WEBPACK_HOST + ':' + WEBPACK_PORT,
'webpack/hot/only-dev-server',
path.resolve(PATHS.DEMO, 'index.js')
]
},
resolve: RESOLVE,
output: {
path: PATHS.DIST,
filename: 'index.js',
publicPath: PATHS.PUBLIC,
sourceMapFilename: 'index.map.json',
libraryTarget: 'umd'
},
module: {
loaders: [{
test: /\.jsx?$/,
loaders: ['react-hot', `babel`],
include: [PATHS.SRC, PATHS.DEMO, PATHS.DIST, PATHS.UTILS]
}, {
test: /\.(css|scss)$/,
loader: `style!css?importLoaders=2&${CSS_MODULES_CONF}!autoprefixer?${AUTOPREFIXER_CONF}!sass`,
include: [PATHS.SRC]
}, {
test: /\.(css|scss)$/,
loader: `style!css?importLoaders=2!autoprefixer?${AUTOPREFIXER_CONF}!sass`,
include: [PATHS.DEMO]
}, {
test: /\.(png|woff|woff2|eot|ttf|svg)(\?t=[0-9]+)?$/,
loader: `url?limit=100000000`,
}]
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('development')
}
}),
new webpack.HotModuleReplacementPlugin(),
new HtmlWebpackPlugin({
inject: 'body',
hash: true,
template: path.resolve(PATHS.DEMO, 'index.html'),
title: 'Demo',
filename: 'index.html'
})
]
}
export const devServerConf = {
contentBase: PATHS.DIST,
publicPath: '/',
historyApiFallback: true,
hot: true,
stats: {
colors: true
}
};
export const githubPagesConf = {
entry: {
ghpages: [
path.resolve(PATHS.DEMO, 'index.js')
]
},
resolve: RESOLVE,
output: {
path: __dirname,
filename: 'index.js',
publicPath: './',
sourceMapFilename: 'index.map.json',
libraryTarget: 'umd'
},
module: {
loaders: [{
test: /\.jsx?$/,
loaders: ['babel'],
include: [PATHS.SRC, PATHS.DEMO, PATHS.DIST, PATHS.UTILS]
}, {
test: /\.(css|scss)$/,
loader: `style!css?importLoaders=2&${CSS_MODULES_CONF}!autoprefixer?${AUTOPREFIXER_CONF}!sass`,
include: [PATHS.SRC]
}, {
test: /\.(css|scss)$/,
loader: `style!css?importLoaders=2!autoprefixer?${AUTOPREFIXER_CONF}!sass`,
include: [PATHS.DEMO]
}, {
test: /\.(png|woff|woff2|eot|ttf|svg)(\?t=[0-9]+)?$/,
loader: `url?limit=100000000`,
}]
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production')
}
}),
new HtmlWebpackPlugin({
inject: 'body',
hash: false,
template: path.resolve(PATHS.DEMO, 'index.html'),
title: 'Demo',
filename: 'index.html'
})
]
};