forked from JetBrains/kotlin-web-site
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
169 lines (152 loc) · 4.46 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
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
const path = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const CleanPlugin = require('clean-webpack-plugin');
const UglifyJsPlugin = require('webpack/lib/optimize/UglifyJsPlugin');
const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin');
module.exports = (params = {}) => {
const isProduction = process.env.NODE_ENV === 'production';
const isDevelopment = !isProduction;
const env = isProduction ? 'production' : 'development';
const isServer = process.argv.toString().includes('webpack-dev-server');
const sourcemaps = params.sourcemaps || isDevelopment;
const siteHost = 'localhost:5000';
const webDemoURL = params['webdemo-url'] || 'http://kotlin-web-demo-cloud.passive.aws.intellij.net';
const indexName = params['index-name'] || 'dev_KOTLINLANG';
const config = {
entry: {
'common': './static/js/page/common.js',
'index': './static/js/page/index/index.js',
'events': './static/js/page/events/index.js',
'videos': './static/js/page/videos.js',
'grammar': './static/js/page/grammar.js',
'community': './static/js/page/community/community.js',
'pdf': './static/js/page/pdf.js',
'api': './static/js/page/api/api.js',
'reference': './static/js/page/reference.js',
'tutorial': './static/js/page/tutorial.js',
'styles': './static/css/styles.scss'
},
output: {
path: path.join(__dirname, '_assets'),
publicPath: '/_assets/',
filename: '[name].js'
},
devtool: sourcemaps ? 'source-map' : false,
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
include: [
path.resolve(__dirname, 'static/js')
]
},
{
test: /\.scss$/,
loader: ExtractTextPlugin.extract({
use: [
'css-loader',
{
loader: 'resolve-url-loader',
options: {
keepQuery: true
}
},
'svg-fill-loader/encodeSharp',
{
loader: 'postcss-loader',
options: {
sourceMap: true
}
},
{
loader: 'sass-loader',
options: {
sourceMap: true
}
}
]
})
},
{
test: /\.twig$/,
loader: 'nunjucks-loader'
},
{
test: /\.monk$/,
loader: 'monkberry-loader'
},
{
test: /\.mustache$/,
loader: 'mustache-loader'
},
{
test: /\.svg/,
use: [
'url-loader',
'svg-fill-loader'
]
},
{
test: /\.(jpe?g|png|gif)$/,
loader: 'url-loader',
options: {
limit: 10000,
name: '[path][name].[ext]'
}
},
{
test: /\.(woff|ttf)$/,
loader: 'file-loader',
options: {
name: '[path][name].[ext]'
}
}
]
},
plugins: [
new ExtractTextPlugin('[name].css'),
new webpack.optimize.CommonsChunkPlugin({
name: 'default',
minChunks: 3
}),
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery',
fetch: 'imports-loader?this=>global!exports-loader?global.fetch!whatwg-fetch',
Promise: 'imports-loader?this=>global!exports-loader?global.Promise!core-js/es6/promise'
}),
new webpack.DefinePlugin({
webDemoURL: JSON.stringify(webDemoURL),
indexName: JSON.stringify(indexName),
'process.env.NODE_ENV': JSON.stringify(env)
})
],
stats: 'errors-only',
devServer: {
port: 9000,
stats: 'errors-only',
proxy: {
'/**': {
target: `http://${siteHost}`,
bypass: function (req) {
req.headers.host = siteHost;
}
}
}
}
};
const plugins = config.plugins;
if (!isServer) {
plugins.push(new CleanPlugin(['_assets']))
}
if (isProduction) {
const minimizePlugin = new UglifyJsPlugin({ sourceMap: sourcemaps });
const minimizeLoaderOptionPlugin = new LoaderOptionsPlugin({ minimize: true });
plugins.push(minimizePlugin);
plugins.push(minimizeLoaderOptionPlugin);
}
return config;
};