-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathwebpack.config.es6.js
123 lines (111 loc) · 3.23 KB
/
webpack.config.es6.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
import path from 'path'
import dotenv from 'dotenv'
import StringReplacePlugin from 'string-replace-webpack-plugin'
import { resources } from 'lambda-comments-utils/src/cloudFormation'
import { DefinePlugin, NormalModuleReplacementPlugin } from 'webpack'
dotenv.config()
const nodeModulesDir = path.normalize(`${__dirname}/../../node_modules`)
const lambdas = [
'QueueComment',
'Worker'
]
const lambdaDirNames = lambdas.reduce((lookupTable, logicalResourceId) => {
const resource = resources[`${logicalResourceId}LambdaFunction`]
const lambdaDirName = resource.PhysicalResourceId.replace(/^[^-]+-/, '')
return {
[logicalResourceId]: lambdaDirName,
...lookupTable
}
}, {})
const defines = {
'global.GENTLY': false,
'process.env.BLOG': `'${process.env.BLOG}'`,
'process.env.REGION': `'${process.env.REGION}'`,
'process.env.STAGE': `'${process.env.STAGE}'`,
}
if (process.env.AKISMET) {
defines['process.env.AKISMET'] = `'${process.env.AKISMET}'`
}
if (process.env.SLACK) {
defines['process.env.SLACK'] = `'${process.env.SLACK}'`
}
if (process.env.REQEMAIL) {
defines['process.env.REQEMAIL'] = `'${process.env.REQEMAIL}'`
}
if (process.env.REQNAME) {
defines['process.env.REQNAME'] = `'${process.env.REQNAME}'`
}
if (process.env.SIZELIMIT) {
defines['process.env.SIZELIMIT'] = `'${process.env.SIZELIMIT}'`
}
if (process.env.DISALLOW_EMPTY) {
defines['process.env.DISALLOW_EMPTY'] = `'${process.env.DISALLOW_EMPTY}'`
}
export default {
entry: {
[lambdaDirNames['QueueComment']]: [
'babel-polyfill',
'./packages/lambda/src/queueComment/index.js'
],
[lambdaDirNames['Worker']]: [
'babel-polyfill',
'./packages/lambda/src/worker/index.js'
]
},
output: {
path: "./build/apex/functions",
library: "[name]",
libraryTarget: "commonjs2",
filename: "[name]/index.js"
},
target: "node",
externals: { 'aws-sdk': 'commonjs aws-sdk' },
module: {
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel',
query: {
presets: [ 'es2015', 'stage-0' ]
}
},
{
test: /\.json$/,
loader: 'json'
},
{
test: /validate.js$/,
include: /node_modules\/json-schema/,
loader: StringReplacePlugin.replace({ // from the 'string-replace-webpack-plugin'
replacements: [{
pattern: /\(\{define:typeof define!="undefined"\?define:function\(deps, factory\)\{module\.exports = factory\(\);\}\}\)\./ig,
replacement: function(match, p1, offset, string) {
return false;
}
}]
})
}
]
},
plugins: [
// https://github.com/andris9/encoding/issues/16
new NormalModuleReplacementPlugin(/\/iconv-loader$/, 'node-noop'),
new StringReplacePlugin(),
// https://github.com/visionmedia/superagent/wiki/Superagent-for-Webpack
new DefinePlugin(defines),
],
// From: https://github.com/webpack/webpack/issues/784
// for modules
resolve: {
fallback: [ nodeModulesDir ]
},
// same issue, for loaders like babel
resolveLoader: {
fallback: [ nodeModulesDir ]
},
/* node: {
// https://github.com/visionmedia/superagent/wiki/Superagent-for-Webpack
__dirname: true,
} */
}