-
Notifications
You must be signed in to change notification settings - Fork 13
/
webpack.config.prod.babel.js
82 lines (71 loc) · 2.33 KB
/
webpack.config.prod.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
import path from 'path'
import CopyWebpackPlugin from 'copy-webpack-plugin'
import webpack from 'webpack'
import config from './src/config'
import writeAssets from './src/server/write-assets'
import { loadTranslations } from './src/server/lang'
const assetsPath = path.join(__dirname, 'public')
const supportedLanguages = Object.keys(loadTranslations(path.join(__dirname, './src/assets/lang/')))
module.exports = {
// devtool: "eval", // Transformed code
devtool: 'source-map', // Original code
entry: {
'main': ['babel-polyfill', './src/client.jsx'],
},
output: {
path: assetsPath,
filename: '[name]-[hash].js',
publicPath: config.pathname.endsWith('/') ? config.pathname : `${config.pathname}/`
},
target: 'web',
// yaml-js has a reference to `fs`, this is a workaround
node: {
fs: 'empty'
},
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /(node_modules|public)/,
use: [{
loader: 'babel-loader'
}]
}
]
},
resolve: {
extensions: ['.js', '.jsx'],
},
plugins: [
// set global vars
new webpack.DefinePlugin({
'process.env': {
API_URL: JSON.stringify(config.apiBaseUrl),
CHANGELOG_URL: JSON.stringify(config.changelogUrl),
NODE_ENV: JSON.stringify(process.env.NODE_ENV),
PATHNAME: JSON.stringify(config.pathname),
},
}),
new webpack.ProvidePlugin({
React: 'react', // For babel JSX transformation which generates React.createElement.
}),
new CopyWebpackPlugin([
// 'to' values are relative to the public directory configured by output.path
{from: 'src/assets/style.css', to: '.'},
{from: 'node_modules/bootstrap/dist', to: 'bootstrap'},
{from: 'node_modules/highlight.js/styles/github-gist.css', to: '.'},
{from: 'node_modules/swagger-ui/dist/swagger-ui.css', to: '.'},
]),
// Only load syntax highlighting for Python
new webpack.ContextReplacementPlugin(
/highlight\.js\/lib\/languages$/,
new RegExp('^./(python)$')
),
// Only load locale for supported languages
new webpack.ContextReplacementPlugin(
/react-intl\/locale-data$/,
new RegExp(`^./(${supportedLanguages.join('|')})$`)
),
function() { this.plugin('done', writeAssets(path.resolve(__dirname, 'webpack-assets.json')).bind(this)) },
],
}