-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.js
106 lines (104 loc) · 2 KB
/
build.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
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack');
function webpackErrorHandler(err, stats){
if (err) {
console.error(err.stack || err);
if (err.details) {
console.error(err.details);
}
process.exit(1);
}
const info = stats.toJson();
if (stats.hasErrors()) {
console.error(info.errors);
process.exit(1);
}
if (stats.hasWarnings()) {
console.warn(info.warnings);
}
}
webpack({
mode: 'production',
target: "node",
entry: {
index: __dirname + '/data/index.js',
},
output: {
path: __dirname,
filename: 'gendata.temp.js',
library: 'gendata',
libraryTarget: 'umd',
},
optimization: {
minimize: false,
},
}, (err, stats) => {
webpackErrorHandler(err, stats);
var gendata = require('./gendata.temp').default();
webpack({
mode: 'production',
entry: {
preload: './app/preload.js',
index: './app/index.js',
},
output: {
path: __dirname,
filename: '[name].min.js',
},
module: {
rules: [
{
test: /(\.jsx|\.js)$/,
use: {
loader: "babel-loader",
options: {
presets: ["@babel/preset-env"]
}
},
exclude: /node_modules/
},
{
test: /\.less$/,
use: [
{
loader:"raw-loader"
},
{
loader:"postcss-loader",
options: {
postcssOptions:{
plugins: {
'cssnano': {}
}
}
}
},
{
loader:"less-loader"
}
]
}
],
},
plugins: [
new HtmlWebpackPlugin({
filename: path.resolve(__dirname,'index.html'),
template: path.resolve(__dirname,'app/index.ejs'),
inject: false
}),
new HtmlWebpackPlugin({
filename: path.resolve(__dirname,'kanji-reading.html'),
template: path.resolve(__dirname,'app/index.ejs'),
inject: false,
meta:{
fromLocal:true
}
}),
new webpack.DefinePlugin({
'READINGS_DATA': '\"'+gendata.r+'\"',
'VARIANTS_DATA': '\"'+gendata.v+'\"'
}),
],
}, webpackErrorHandler);
});