forked from mei23/misskey-v11
-
Notifications
You must be signed in to change notification settings - Fork 5
/
webpack.config.js
181 lines (173 loc) · 4.1 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/**
* webpack configuration
*/
const fs = require('fs');
const webpack = require('webpack');
const rndstr_1 = require('rndstr');
const chalk = require('chalk');
const { VueLoaderPlugin } = require('vue-loader');
const ProgressBarPlugin = require('progress-bar-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
class WebpackOnBuildPlugin {
constructor(callback) {
this.callback = callback;
}
apply(compiler) {
compiler.hooks.done.tap('WebpackOnBuildPlugin', this.callback);
}
}
const isProduction = process.env.NODE_ENV == 'production';
const constants = require('./src/const.json');
const locales = require('./locales');
const meta = require('./package.json');
const codename = meta.codename;
const version = isProduction ? meta.version : meta.version + '-' + (0, rndstr_1.default)({ length: 8, chars: '0-9a-z' });
const postcss = {
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [
require('cssnano')({
preset: 'default'
})
]
},
},
};
module.exports = {
entry: {
desktop: './src/client/app/desktop/script.ts',
mobile: './src/client/app/mobile/script.ts',
dev: './src/client/app/dev/script.ts',
auth: './src/client/app/auth/script.ts',
admin: './src/client/app/admin/script.ts',
sw: './src/client/app/sw.js'
},
module: {
rules: [{
test: /\.vue$/,
exclude: /node_modules/,
use: [{
loader: 'vue-loader',
options: {
cssSourceMap: false,
compilerOptions: {
preserveWhitespace: false
}
}
}, {
loader: 'vue-svg-inline-loader'
}]
}, {
test: /\.styl(us)?$/,
exclude: /node_modules/,
oneOf: [{
resourceQuery: /module/,
use: [{
loader: 'vue-style-loader'
}, {
loader: 'css-loader',
options: {
modules: true,
esModule: false,
url: false,
}
}, postcss, {
loader: 'stylus-loader'
}]
}, {
use: [{
loader: 'vue-style-loader'
}, {
loader: 'css-loader',
options: {
url: false,
esModule: false
}
}, postcss, {
loader: 'stylus-loader'
}]
}]
}, {
test: /\.css$/,
use: [{
loader: 'vue-style-loader'
}, {
loader: 'css-loader',
options: {
esModule: false,
}
}, postcss]
}, {
test: /\.(eot|woff|woff2|svg|ttf)([?]?.*)$/,
type: 'asset/resource'
}, {
test: /\.json5$/,
loader: 'json5-loader',
options: {
esModule: false,
},
type: 'javascript/auto'
}, {
test: /\.ts$/,
exclude: /node_modules/,
use: [{
loader: 'ts-loader',
options: {
happyPackMode: true,
configFile: __dirname + '/src/client/app/tsconfig.json',
appendTsSuffixTo: [/\.vue$/]
}
}]
}]
},
plugins: [
new ProgressBarPlugin({
format: chalk ` {cyan.bold webpack} {bold [}:bar{bold ]} {green.bold :percent} :msg :elapseds`,
clear: false
}),
new webpack.DefinePlugin({
_COPYRIGHT_: JSON.stringify(constants.copyright),
_VERSION_: JSON.stringify(version),
_CODENAME_: JSON.stringify(codename),
_LANGS_: JSON.stringify(Object.entries(locales).map(([k, v]) => [k, v && v.meta && v.meta.lang])),
_ENV_: JSON.stringify(process.env.NODE_ENV)
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(isProduction ? 'production' : 'development')
}),
new WebpackOnBuildPlugin(stats => {
fs.writeFileSync('./built/meta.json', JSON.stringify({ version }), 'utf-8');
fs.mkdirSync('./built/client/assets/locales', { recursive: true });
for (const [lang, locale] of Object.entries(locales))
fs.writeFileSync(`./built/client/assets/locales/${lang}.json`, JSON.stringify(locale), 'utf-8');
}),
new VueLoaderPlugin()
],
output: {
path: __dirname + '/built/client/assets',
filename: `[name].${version}.js`,
publicPath: `/assets/`
},
resolve: {
extensions: [
'.js', '.ts', '.json'
],
alias: {
'const.styl': __dirname + '/src/client/const.styl'
},
fallback: {
'crypto': false
}
},
resolveLoader: {
modules: ['node_modules']
},
optimization: {
minimizer: [new TerserPlugin({
parallel: 1
})]
},
devtool: false, //'source-map',
mode: isProduction ? 'production' : 'development'
};