-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
135 lines (127 loc) · 4.32 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
const path = require('path');
const glob = require('glob');
const CompressionPlugin = require('compression-webpack-plugin');
const FileManagerPlugin = require('filemanager-webpack-plugin');
const ManifestPlugin = require('webpack-manifest-plugin');
const angularJson = require('./angular');
const appName = angularJson.defaultProject;
const targetPath = (appendPath) => {
if (!appendPath) appendPath = '';
return path.resolve(__dirname, 'dist', appendPath);
};
const assetsRootPath = () => {
return appName + '/';
};
const assetsStaticPath = (appendPath) => {
if(!appendPath) appendPath = '';
return (assetsRootPath() + '/static/' + appendPath).replace(/(\/+){2,}/g, '/');
};
const originalPackagePath = targetPath(appName);
const newPackagingRootPath = targetPath('packaging');
const newPackagingTempPath = targetPath('packaging/tmp');
const newPackageAppPath = targetPath('packaging/' + appName + '/database');
console.log('');
console.log('Original angular package path: ', originalPackagePath);
console.log('New packaging root path: ', newPackagingRootPath);
console.log('New packaging temp path: ', newPackagingTempPath);
console.log('New packaging app path: ', newPackageAppPath);
console.log('');
module.exports = {
mode: 'production',
entry: [
...glob.sync(originalPackagePath + '/*.*'),
...glob.sync(originalPackagePath + '/static/assets/*.*'),
],
output: {
path: newPackagingTempPath,
filename: '[name]'
},
module: {
rules: [
{
test: /.*/,
exclude: [/\.html/],
use: [{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: assetsStaticPath('assets')
}
}]
},
{
test: /\.html/,
use: [{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: assetsRootPath()
}
}]
}
]
},
plugins: [
new CompressionPlugin({
test: /\.(js|css|woff|woff2|ttf|svg|eot)$/,
minRatio: 0.8,
threshold: 20000 // in bytes = 20kb
}),
new ManifestPlugin({
/**
* https://github.com/danethurber/webpack-manifest-plugin/blob/1.x/README.md#hooks-options
* {
* path: string,
* chunk: Chunk,
* name: string|null,
* isInitial: boolean,
* isAsset: boolean,
* isModuleAsset: boolean
* }
*/
map: (data) => {
return {
path: data.path.replace(/^strongbox-database-ui/i, '/database').replace('/index.html', ''),
name: path.basename(data.name),
isInitial: data.isInitial,
isChunk: data.chunk,
isAsset: data.isAsset,
isModuleAsset: data.isModuleAsset
}
},
filter: (data) => {
return data.name !== 'main.main'
}
}),
new FileManagerPlugin({
onStart: {
mkdir: [
newPackageAppPath
]
},
onEnd: {
move: [
{
source: newPackagingTempPath + "/" + appName,
destination: newPackageAppPath
},
{
source: newPackagingTempPath + "/manifest.json",
destination: newPackageAppPath + "/assets-manifest.json"
}
],
delete: [newPackagingTempPath],
archive: [{
source: newPackageAppPath + '/../', // we need to have the `./database` path in the zip.
destination: newPackagingRootPath + '/' + appName + '.zip',
format: 'zip',
options: {
zlib: {
level: 9
}
}
}]
}
})
]
};