-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathwebpack.widget.config.js
73 lines (71 loc) · 1.9 KB
/
webpack.widget.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
const path = require('path');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const webpack = require('webpack');
const AssetsPlugin = require('assets-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
require('dotenv').config();
module.exports = {
mode: 'development',
entry: './src/widget.js',
output: {
path: path.resolve(__dirname, process.env.APP_ENV === 'production' ? 'public/build' : 'public'),
filename: 'widget.js',
//filename: 'widget_[contenthash:6].js',
publicPath: '/',
},
node: {
fs: "empty"
},
plugins: [
new webpack.DefinePlugin({
API_URL: JSON.stringify(process.env.API_URL),
WIDGET_URL: JSON.stringify(process.env.WIDGET_URL),
SOCKET_HOST: JSON.stringify(process.env.SOCKET_HOST),
}),
new MiniCssExtractPlugin({
filename: '[name].css'
}),
new UglifyJsPlugin({
sourceMap: true,
test: /\.js(\?.*)?$/i,
parallel: 3,
}),
new AssetsPlugin({
path: process.env.APP_ENV === 'production' ? 'public/build' : 'public',
}),
{
apply: compiler => {
// add a hook to run a callback after each compile
compiler.hooks.afterCompile.tap('jest', compilation => {
// run `npm test` using `spawn` to keep the format of the terminal just like you run it manually.
// for more info: https://stackoverflow.com/a/20145153/863110
//console.log(compilation)
});
}
}
],
optimization: {
minimizer: [
new UglifyJsPlugin({
sourceMap: true,
test: /\.js(\?.*)?$/i,
parallel: 3,
})
],
},
module: {
rules: [
{
include: __dirname + "/src/",
exclude: "/node_modules/",
loader: "babel-loader",
options: {
presets: ["es2015"],
plugins: [
"transform-es2015-modules-amd"
]
}
}
]
}
};