-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathwebpack.config.js
106 lines (97 loc) · 2.9 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
import dotenv from 'dotenv'
import { ClientConfig, ServerConfig } from 'react-project/webpack'
import postcssNested from 'postcss-nested'
import { DefinePlugin } from 'webpack'
import 'babel-register'
import { apiKey } from '../../../deploy/state/apiKey.json'
import { getApiUrl, getWebsiteUrl } from
'lambda-comments-utils/src/cloudFormation'
dotenv.config()
dotenv.config({ path: '../../.env' })
const apiUrl = getApiUrl()
const websiteUrl = getWebsiteUrl()
const { REQEMAIL: authorEmailRequired, REQNAME: authorNameRequired } = process.env
const { SIZELIMIT: contentSizeLimit, DISALLOW_EMPTY: disallowEmptyContent } = process.env
function modify (webpackConfig) {
webpackConfig.postcss = () => {
return [ postcssNested ]
}
if (webpackConfig.entry.app) {
webpackConfig.entry.app = [
'babel-polyfill',
webpackConfig.entry.app
]
}
}
function modifyClient (webpackConfig) {
let {
entry,
devtool,
output: {
filename
},
plugins,
module: {
loaders
}
} = webpackConfig
modify(webpackConfig)
if (process.env.NODE_ENV === 'production') {
delete webpackConfig.devtool
console.log('Devtool cleared')
} else {
console.log('Devtool before', devtool)
devtool = devtool.replace(
'cheap-module-eval-source-map',
'cheap-source-map'
)
webpackConfig.devtool = devtool
console.log('Devtool after', devtool)
}
console.log('Entry before', entry)
entry['lambda-comments'] = entry.app
delete entry.app
delete entry._vendor
console.log('Entry after', entry)
console.log('Output filename before', filename)
filename = filename.replace('[chunkHash].js', '[name].js')
webpackConfig.output.filename = filename
console.log('Output filename after', filename)
console.log('Plugins before', plugins)
plugins = plugins.filter(plugin => {
const name = plugin.constructor.name
return name !== 'ExtractTextPlugin' && name !== 'CommonsChunkPlugin'
})
plugins.push(new DefinePlugin({
'__CONFIG__': JSON.stringify({
apiUrl,
websiteUrl,
apiKey,
authorNameRequired,
authorEmailRequired,
contentSizeLimit,
disallowEmptyContent
})
}))
webpackConfig.plugins = plugins
console.log('Plugins after', plugins)
console.log('Loaders before', loaders)
loaders.forEach(loader => {
if (loader.test.source === '\\.css$') {
loader.loader = 'style-loader!css-loader?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]!postcss-loader'
}
})
webpackConfig.module.loaders = loaders
console.log('Loaders after', loaders)
// Fix for: https://github.com/isagalaev/highlight.js/issues/895
webpackConfig.module.noParse = [/autoit.js/]
}
modifyClient(ClientConfig)
modify(ServerConfig)
/*
// Uncomment when adapting webpack config
console.log('\n\n\n')
console.log(JSON.stringify(ClientConfig, null, 2))
process.exit(1)
*/
export { ClientConfig, ServerConfig }