forked from aws-samples/aws-lex-web-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
105 lines (103 loc) · 2.95 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
const path = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const eslintFriendlyFormatter = require('eslint-friendly-formatter');
const basePath = __dirname;
const VERSION = JSON.stringify(require('./package.json').version);
const devServerPort = (process.env.PORT) ? Number(process.env.PORT) : 8000;
module.exports = (env) => {
const buildEnv = env || 'development';
const isProd = (buildEnv === 'production');
return {
context: path.join(basePath, 'src/lex-web-ui-loader/js'),
entry: {
'lex-web-ui-loader': './index.js',
},
output: {
path: path.join(basePath, 'dist'),
filename: (isProd) ? '[name].min.js' : '[name].js',
library: 'ChatBotUiLoader',
libraryExport: 'ChatBotUiLoader',
libraryTarget: 'umd',
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
enforce: 'pre',
loader: 'eslint-loader',
options: {
formatter: eslintFriendlyFormatter,
},
},
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
},
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: (isProd) ?
['css-loader', 'postcss-loader'] :
['css-loader'],
}),
},
],
},
devtool: (isProd) ? 'source-map' : 'cheap-module-source-map',
devServer: {
contentBase: [
path.join(__dirname, 'dist'),
path.join(__dirname, 'src/config'),
path.join(__dirname, 'src/website'),
],
clientLogLevel: 'warning',
hot: true,
port: devServerPort,
overlay: { warnings: false, errors: true },
stats: 'errors-only',
watchOptions: {
poll: true,
},
},
stats: {
modules: false,
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(buildEnv),
}),
new webpack.optimize.ModuleConcatenationPlugin(),
isProd && new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
drop_console: true,
drop_debugger: true,
},
sourceMap: true,
parallel: true,
}),
isProd && new webpack.BannerPlugin({
banner: `/*!
* lex-web-ui v${VERSION}
* (c) 2017-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Released under the Amazon Software License.
*/ `,
raw: true,
entryOnly: true,
}),
new ExtractTextPlugin({
filename: (isProd) ? '[name].min.css' : '[name].css',
}),
// dev plugins
!isProd && new webpack.NamedModulesPlugin(),
!isProd && new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
]
// filter empty items produced by isProd conditionals
.filter(i => !!i),
};
};