-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
166 lines (160 loc) · 5.13 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
154
155
156
157
158
159
160
161
162
163
164
165
166
/*
* Solo - A small and beautiful blogging system written in Java.
* Copyright (c) 2010-present, b3log.org
*
* Solo is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @fileoverview webpack ipfs.
*
* @author <a href="http://vanessa.b3log.org">Liyuan Li</a>
* @version 0.1.0.0, Jan 18, 2020
*/
const path = require('path')
const fs = require('fs')
const TerserPlugin = require('terser-webpack-plugin')
const {CleanWebpackPlugin} = require('clean-webpack-plugin')
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin')
const genSkinsEntries = () => {
const entries = {}
fs.readdirSync('./src/main/resources/skins').forEach(function (file) {
const jsPath = `./src/main/resources/skins/${file}`
try {
fs.statSync(`${jsPath}/js/common.js`)
entries[`skins/${file}/js/common`] = `${jsPath}/js/common.js`
} catch (e) {
}
try {
fs.statSync(`${jsPath}/css/base.scss`)
entries[`dist/${file}/base`] = `${jsPath}/css/base.scss`
} catch (e) {
}
})
return entries
}
module.exports = (env, argv) => {
return {
mode: argv.mode || 'development',
watch: argv.mode !== 'production',
stats: 'minimal',
output: {
filename: '[name].min.js',
path: path.resolve(__dirname, './src/main/resources'),
},
entry: Object.assign(genSkinsEntries(), {
'js/admin/admin': [
'./src/main/resources/js/admin/admin.js',
'./src/main/resources/js/admin/editor.js',
'./src/main/resources/js/admin/tablePaginate.js',
'./src/main/resources/js/admin/article.js',
'./src/main/resources/js/admin/articleList.js',
'./src/main/resources/js/admin/draftList.js',
'./src/main/resources/js/admin/pageList.js',
'./src/main/resources/js/admin/others.js',
'./src/main/resources/js/admin/linkList.js',
'./src/main/resources/js/admin/preference.js',
'./src/main/resources/js/admin/staticsite.js',
'./src/main/resources/js/admin/themeList.js',
'./src/main/resources/js/admin/pluginList.js',
'./src/main/resources/js/admin/userList.js',
'./src/main/resources/js/admin/categoryList.js',
'./src/main/resources/js/admin/plugin.js',
'./src/main/resources/js/admin/main.js',
'./src/main/resources/js/admin/about.js'],
'js/common': './src/main/resources/js/common.js',
'js/page': './src/main/resources/js/page.js',
'dist/admin': './src/main/resources/scss/admin.scss',
'dist/base': './src/main/resources/scss/base.scss',
'dist/start': './src/main/resources/scss/start.scss',
}),
module: {
rules: [
{
test: /\.js/,
include: [
path.resolve(__dirname, './src/main/resources/js'),
path.resolve(__dirname, './src/main/resources/templates/skins'),
],
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
},
},
},
{
test: /\.scss$/,
include: [
path.resolve(__dirname, './src/main/resources'),
],
use: [
{
loader: 'file-loader',
options: {
name (file) {
const skins = file.split('skins')
if (skins.length === 2) {
return `skins/${skins[1].split(path.sep)[1]}/css/[name].css`
} else {
return 'scss/[name].css'
}
},
},
},
{
loader: 'extract-loader',
options: {
url: false,
},
},
{
loader: 'css-loader', // translates CSS into CommonJS
options: {
url: false,
},
},
{
loader: 'postcss-loader',
options: {
ident: 'postcss',
plugins: () => [
require('autoprefixer')({grid: true, remove: false}),
],
},
},
{
loader: 'sass-loader', // compiles Sass to CSS
},
],
},
],
},
optimization: {
minimizer: [
new TerserPlugin({
cache: true,
parallel: true,
terserOptions: {
output: {
comments: false,
},
},
sourceMap: false,
extractComments: false,
}),
new OptimizeCSSAssetsPlugin({}),
],
},
plugins: [
new CleanWebpackPlugin({
cleanOnceBeforeBuildPatterns: [
path.join(__dirname, 'src/main/resources/dist')],
}),
],
}
}