-
Notifications
You must be signed in to change notification settings - Fork 2
/
webpack.config.js
53 lines (46 loc) · 1.14 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
const webpack = require('webpack')
const { execSync } = require('child_process')
const path = require('path')
let hash = execSync('git rev-parse --short HEAD').toString().trim()
let lang = process.env.ESP_LANG || 'en'
let plugins = []
let devtool = 'source-map'
if (process.env.ESP_PROD) {
// ignore demo
plugins.push(new webpack.IgnorePlugin(/(term|\.)\/demo(?:\.js)?$/))
// no source maps
devtool = ''
}
plugins.push(new webpack.optimize.UglifyJsPlugin({
sourceMap: devtool === 'source-map'
}))
// replace "locale-data" with path to locale data
let locale = process.env.ESP_LANG || 'en'
plugins.push(new webpack.NormalModuleReplacementPlugin(
/^locale-data$/,
path.resolve(`lang/${locale}.php`)
))
module.exports = {
entry: './js',
output: {
path: path.resolve(__dirname, 'out', 'js'),
filename: `app.${hash}-${lang}.js`
},
module: {
rules: [
{
test: /\.js$/,
exclude: [
path.resolve(__dirname, 'node_modules')
],
loader: 'babel-loader'
},
{
test: /lang\/.+?\.php$/,
loader: './lang/_js-lang-loader.js'
}
]
},
devtool,
plugins
}