-
Notifications
You must be signed in to change notification settings - Fork 7
/
webpack.config.js
153 lines (151 loc) · 4.3 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
const path = require('path')
const CopyPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin')
const HtmlReplaceWebpackPlugin = require('html-replace-webpack-plugin')
// const WriteFilePlugin = require('write-file-webpack-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer')
.BundleAnalyzerPlugin
const WorkboxPlugin = require('workbox-webpack-plugin');
const config = (env, argv) => ({
mode: 'development',
entry: {
index: './src/index.js',
},
output: {
filename: 'index.js',
path: path.resolve(__dirname, 'dist'),
library: 'imagej',
libraryTarget: 'umd',
umdNamedDefine: true
},
devServer: {
contentBase: path.resolve(__dirname, 'dist'),
publicPath: '/',
port: 9090,
host: '0.0.0.0',
hot: true,
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
"Access-Control-Allow-Headers": "X-Requested-With, content-type, Authorization"
}
},
plugins: [
// new CleanWebpackPlugin(['dist']),
new CopyPlugin([{
from: path.resolve(__dirname, 'src', 'assets'),
to: path.resolve(__dirname, 'dist', 'assets')
},
{
from: path.resolve(__dirname, 'src', 'CNAME')
},
{
from: path.resolve(__dirname, 'src', 'style.css')
},
{
from: path.resolve(__dirname, 'src', 'service-worker.js')
},
{
from: path.resolve(__dirname, 'src', 'c.html')
},
{
from: path.resolve(__dirname, 'src', 'manifest.webmanifest')
},
{
from: path.resolve(__dirname, 'src', 'imagej-js-chatbot-extension.imjoy.html')
}
]),
new HtmlWebpackPlugin({
filename: 'index.html',
template: path.resolve(__dirname, 'src', 'index.html'),
inject: true
}),
new HtmlWebpackPlugin({
filename: 'chat.html',
template: path.resolve(__dirname, 'src', 'chat.html'),
inject: true
}),
new HtmlReplaceWebpackPlugin([{
pattern: 'IJ_VERSION',
replacement: require("./package.json").version
}]),
new BundleAnalyzerPlugin({
analyzerMode: 'static',
openAnalyzer: false,
}),
// new WorkboxPlugin.GenerateSW({
// // these options encourage the ServiceWorkers to get in there fast
// // and not allow any straggling "old" SWs to hang around
// clientsClaim: true,
// skipWaiting: true,
// runtimeCaching: [
// {
// urlPattern: new RegExp('https://cjrtnc.leaningtech.com/.*'),
// handler: 'CacheFirst'
// },
// {
// urlPattern: new RegExp('https://stackpath.bootstrapcdn.com/font-awesome/.*'),
// handler: 'CacheFirst'
// },
// {
// urlPattern: new RegExp('https://cdnjs.cloudflare.com/.*'),
// handler: 'CacheFirst'
// },
// {
// urlPattern: new RegExp('https://imjoy.io/static/.*'),
// handler: 'NetworkFirst'
// },
// {
// urlPattern: new RegExp('https://static.imjoy.io/.*'),
// handler: 'NetworkFirst'
// },
// {
// urlPattern: new RegExp('/.*'),
// handler: 'NetworkFirst'
// },
// {
// urlPattern: new RegExp('/ij153/.*'),
// handler: 'NetworkFirst'
// },
// {
// // debugging
// urlPattern: new RegExp('/sockjs-node.*'),
// handler: 'NetworkOnly'
// },
// ]
// }),
// new WriteFilePlugin(),
],
module: {
rules: [{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: [
[
'@babel/preset-env',
{
targets: {
browsers: ['last 2 Chrome versions']
},
useBuiltIns: 'entry',
corejs: '3.0.0',
modules: false,
},
],
],
plugins: ['@babel/plugin-syntax-dynamic-import'],
cacheDirectory: true,
},
},
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
],
},
})
module.exports = config