-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwallper.config.js
156 lines (148 loc) · 4.57 KB
/
wallper.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
154
155
156
const HtmlWebpackPlugin = require('html-webpack-plugin'); // installed via npm
const path = require('path');
const fs = require('fs');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const ProcessControlPlugin = require('./ProcessControlPlugin');
const ParallelUglifyPlugin = require('webpack-parallel-uglify-plugin');
const CopyPlugin = require('copy-webpack-plugin');
console.log('Build process is starting');
// try {
// fs.unlinkSync('outputDir/index.html')
// //file removed
// } catch(err) {
// console.error(err)
// }
let modelOBJ = {};
let modelArr = fs.readdirSync('./model');
modelArr.map((filename, idx) => {
// 模型转 base64
if(filename === 'test'){return false};
var buff = fs.readFileSync(`./model/${filename}`);
var base64data = buff.toString('base64');
modelOBJ[filename.substr(0, filename.lastIndexOf('.'))] = base64data;
//console.log(base64data);
});
console.log('\n模型转换完毕...\n');
let mp3OBJ = {};
let mp3Arr = fs.readdirSync('./music');
mp3Arr.map((filename, idx) => {
// 模型转 base64
var buff = fs.readFileSync(`./music/${filename}`);
var base64data = buff.toString('base64');
mp3OBJ[filename.substr(0, filename.lastIndexOf('.'))] = base64data;
// console.log(base64data);
});
console.log('\n音频转换完毕...\n');
// image -> base64
let imgOBJ = {};
let imgArr = fs.readdirSync('./imgs');
imgArr.map((filename, idx) => {
// 模型转 base64
var buff = fs.readFileSync(`./imgs/${filename}`);
var base64data = Buffer.from(buff, 'binary').toString('base64');
imgOBJ[filename.substr(0, filename.lastIndexOf('.'))] = base64data;
//console.log(base64data);
});
console.log('\n图片转换完毕...开始打包\n');
module.exports = {
entry: './index.js',
output: {
path: path.resolve(__dirname, 'outputDir'),
filename: 'all.bundle.js',
},
mode: 'production',
module: {
rules: [
{
test: /\.(png|jpg|gif|jpeg|svg)$/i,
use: [
{
loader: 'url-loader',
options: {
limit: 99999999999999999,
name: 'images/[name]-[hash:8].[ext]',
},
},
],
},
// {
// test: /\.js$/i,
// loader: "file-loader",
// },
{ test: /\.txt$/, use: 'raw-loader' },
{ test: /\.css$/, use: 'css-loader', exclude: /node_modules/ },
{ test: /\.css$/, use: 'style-loader', exclude: /node_modules/ },
],
},
plugins: [
new ProcessControlPlugin(),
// new ParallelUglifyPlugin({
// cacheDir: "./node_modules/cache/",
// uglifyJS: {
// output: {
// comments: false,
// },
// warnings: false,
// },
// }),
new HtmlWebpackPlugin({
template: './ModelView_WallpaperEngine_template.html',
filename: 'index.html',
title: "it's a template1",
inject: false,
templateParameters: {
model_base64_data: (() => {
let script = '';
for (key in modelOBJ) {
script += `var ${key}_model = "${modelOBJ[key]}";\n`;
}
return script;
})(),
images_base64_data: (() => {
let script = '';
for (key in imgOBJ) {
script += `var ${key}_img = "${imgOBJ[key]}";\n`;
}
return script;
})(),
mp3_base64_data: (() => {
let script = '';
for (key in mp3OBJ) {
script += `var ${key}_mp3 = "${mp3OBJ[key]}";\n`;
}
return script;
})(),
myscript: (() => {
const d = fs.readFileSync(
'outputDir/all.bundle.js',
async (err, data) => {
return data;
}
);
return d;
})(),
},
// minify: {
// //删除html空格
// collapseWhitespace: true,
// //尽可能使用直接Unicode字符
// decodeEntities: true,
// //指定最大行长度。压缩输出将在有效的HTML分割点按换行符分割
// // maxLineLength:30,
// //在样式元素和样式属性中缩小CSS(使用clean-css)
// minifyCSS: true,
// //缩小脚本元素和事件属性中的JavaScript(使用UglifyJS)
// minifyJS: true,
// //尽可能删除属性周围的引号
// removeAttributeQuotes: true,
// //删除内容为空的属性
// removeEmptyAttributes: true,
// },
}),
// new CopyPlugin({
// patterns: [
// {from: './outputDir/index.html', to: './dist/'}
// ]
// }),
],
};