-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwebpack.config.js
75 lines (74 loc) · 1.73 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
const TerserPlugin = require('terser-webpack-plugin');
const path = require('path');
const fs = require('fs');
module.exports = {
entry: {
"js7800.min": "./src/js/index.js"
},
devtool: "source-map",
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'dist'),
library: 'js7800',
libraryTarget: 'umd',
umdNamedDefine: true
},
module: {
rules: [
{
test: /\.css$/i,
use: ['style-loader', 'css-loader'],
},
{
test: /\.(pal)$/i,
use: [
{
loader: 'url-loader',
},
],
},
{
test: /\.(png|jp(e*)g|svg|gif)$/,
use: [{
loader: 'url-loader',
options: {
limit: 8192, // Convert images < 8kb to base64 strings
name: 'images/[hash]-[name].[ext]'
}
}]
}
],
},
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
test: /\.min\.js$/
}),
]
},
devServer: {
contentBase: path.join(__dirname, 'site/deploy'),
publicPath: '/js/',
compress: true,
port: 8000
},
plugins: [
{
apply: compiler => {
compiler.hooks.afterEmit.tap('AfterEmitPlugin', () => {
let src = path.resolve(__dirname, 'dist/js7800.min.js');
let dst = path.resolve(__dirname, 'site/deploy/js/js7800.min.js');
fs.copyFile(src, dst,
err => {
if (!err) {
console.log("Copied to site: " + src);
} else {
throw "Failed copy to site: " + src
}
});
});
}
}
]
};