-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
137 lines (132 loc) · 3.74 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
const path = require('path');
const webpack = require('webpack');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const eslintFormatterFriendly = require('eslint-formatter-friendly');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const VERSION = require('./package.json').version;
const basePath = __dirname;
const distDir = path.join(basePath, 'dist');
const devServerPort = (process.env.PORT) ? Number(process.env.PORT) : 8000;
module.exports = (env) => {
const buildEnv = env || 'development';
const isProd = (buildEnv === 'production');
return {
mode: (isProd) ? 'production' : 'development',
context: path.join(basePath, 'src/lex-web-ui-loader/js'),
entry: {
'lex-web-ui-loader': './index.js',
},
output: {
path: distDir,
filename: (isProd) ? '[name].min.js' : '[name].js',
library: 'ChatBotUiLoader',
libraryExport: 'ChatBotUiLoader',
libraryTarget: 'umd',
},
module: {
rules: [
/* TODO pending clean-up to re-enable
{
test: /\.js$/,
exclude: /[\\/]node_modules[\\/]/,
enforce: 'pre',
loader: 'eslint-loader',
options: {
formatter: eslintFormatterFriendly,
},
},
*/
{
test: /\.js$/,
exclude: /[\\/]node_modules[\\/]/,
loader: 'babel-loader',
},
{
test: /\.css$/,
use: (isProd) ? [
{
loader: MiniCssExtractPlugin.loader,
},
'css-loader',
'postcss-loader',
] : [
{
loader: MiniCssExtractPlugin.loader,
options: {
hmr: true,
},
},
'css-loader',
],
},
],
},
devtool: (isProd) ? 'source-map' : 'cheap-module-source-map',
devServer: {
contentBase: [
path.join(__dirname, 'src/config'),
path.join(__dirname, 'src/website'),
distDir,
],
clientLogLevel: 'warning',
hot: true,
port: devServerPort,
overlay: { warnings: false, errors: true },
stats: 'errors-only',
},
stats: {
modules: false,
},
plugins: [
new HtmlWebpackPlugin({
filename: 'index.html',
template: path.join(basePath, 'src/website/index.html'),
// script is included in template
inject: false,
}),
new HtmlWebpackPlugin({
filename: 'parent.html',
template: path.join(basePath, 'src/website/parent.html'),
// script is included in template
inject: false,
}),
isProd && new webpack.BannerPlugin({
banner: `/*!
* lex-web-ui v${VERSION}
* (c) 2017-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Released under the Amazon Software License.
*/ `,
raw: true,
entryOnly: true,
exclude: /[\\/]node_modules[\\/]/,
}),
new MiniCssExtractPlugin({
filename: (isProd) ? '[name].min.css' : '[name].css',
}),
new CopyPlugin([
// copy parent page
{
from: path.join(basePath, 'src/website/parent.html'),
to: distDir,
},
// copy custom css
{
from: path.join(basePath, 'src/website/custom-chatbot-style.css'),
to: distDir,
},
// copy lex-web-ui library
{
from: path.join(basePath, 'lex-web-ui/dist/bundle/lex-web-ui.*'),
to: distDir,
flatten: true,
},
{
from: path.join(basePath, 'lex-web-ui/dist/bundle/wav-worker.*'),
to: distDir,
flatten: true,
},
]),
].filter(Boolean),
};
};