-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.babel.js
236 lines (201 loc) · 5.97 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
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
'use strict';
import path from 'path';
import fse from 'fs-extra';
import webpack from 'webpack';
import nodeBourbon from 'node-bourbon';
import nodeNeat from 'node-neat';
import moment from 'moment';
import StaticFilesPlugin from 'static-files-plugin';
import StaticSiteGeneratorPlugin from 'static-site-generator-webpack-plugin';
import config from './config.jsx';
import autoprefixer from 'autoprefixer';
// Just some setup stuff
var appPath = __dirname;
var compiledPath = path.join(appPath, '_compiled');
// Static Files Plugin setup
var staticModuleName = '_public';
var staticSourceDir = path.join(appPath, 'public');
// Remove existing compiled assets
fse.removeSync(compiledPath);
// Prepare to block out node_modules for the server compile
var nodeModules = {};
{
fse.readdirSync(path.join(appPath, 'node_modules'))
.filter(function(x) {
return ['.bin'].indexOf(x) === -1;
})
.forEach(function(mod) {
nodeModules[mod] = 'commonjs ' + mod;
});
}
// Track the compile time of the app
var compileTime = moment().utcOffset(0).format('YYYYMMDDThhmmssSSZZ');
// Figure out which paths to precompile
var paths = config.precompile.paths.map(function(pathToFile){
return path.join('public', pathToFile);
});
// This is the resolve command for all compile paths
var resolve = {
alias: {
'config':'./config.jsx'
},
modulesDirectories:
[
'source',
'node_modules'
],
extensions:
[
"",
".webpack.js",
".web.js",
".js",
".jsx"
]
}
// Webpack Module
module.exports =
[
// -- Server
// The server compiles just like the client and precomple so we know that everyone
// is running the same compiled version of the code
{
name: 'Server',
target: 'node',
devtool: 'inline-source-map',
externals: nodeModules,
entry:
{
'server': path.join(appPath, 'app.server.jsx')
},
output:
{
path: compiledPath,
filename: '[name].js'
},
module:
{
loaders:
[
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel'
}
]
},
plugins:
[
new webpack.BannerPlugin(
'require("source-map-support").install();',
{ raw: true, entryOnly: false }
),
new webpack.DefinePlugin({
COMPILE_TIME: `"${compileTime}"`
})
],
resolve: resolve
},
// -- Precompiled react files
// The application supports precompiling all react router paths into static files
// this is awesome for situations where we want to serve this application on a static
// file service.
{
name: 'Precompiled react router',
target: 'node',
devtool: 'inline-source-map',
externals: nodeModules,
entry:
{
'renderer': path.join(appPath, 'source', 'precompileTools', 'webpackEntrypoint.jsx')
},
output:
{
path: compiledPath,
filename: '[name].js',
libraryTarget: 'umd'
},
module:
{
loaders:
[
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel'
}
]
},
plugins:
[
new StaticSiteGeneratorPlugin(
'renderer',
paths,
{}
)
],
resolve: resolve
},
// -- Precompiled static assets
// The server compiles static assets (jsx, scss, nunj) into static files and copies everything
// else to the compiled directory. That way we can serve these files statically.
{
name: 'Precompiled static assets',
devtool: 'inline-source-map',
//entry: see the plugins for StaticFilesPlugin
output:
{
path: compiledPath,
filename: '[name].js'
},
module:
{
loaders:
[
{
test: /\.jsx$/,
exclude: /node_modules/,
loader: 'babel'
},
{
test: /\.scss$/,
loader: 'file?context=' + appPath + '&name=[path][name].css!postcss!sass?' +
JSON.stringify({
'outputStyle':'expanded', //'expanded' is your alternative,
'includePaths':
nodeNeat.includePaths
.concat([
path.join(appPath, 'source'),
path.join(appPath, 'node_modules'),
path.join(appPath, 'node_modules', 'react-foundation-apps', 'bower_components', 'foundation-apps', 'scss')
])
})
},
{
test: /\.(?=[^.]*$)(?!(jsx|scss)).*$/, //catch all remaining
exclude: /node_modules/,
loader: 'file?context=' + appPath + '&name=[path][name].[ext]'
}
]
},
postcss: function () {
return [
autoprefixer({
browsers: ['last 2 versions', 'ie 10']
})
];
},
plugins: [
new webpack.DefinePlugin({
COMPILE_TIME: `"${compileTime}"`
}),
new StaticFilesPlugin(
staticSourceDir,
appPath,
staticModuleName,
null
)
],
resolve: resolve
}
];