forked from misskey-dev/misskey
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.ts
157 lines (151 loc) Β· 3.73 KB
/
webpack.config.ts
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
/**
* webpack configuration
*/
import * as fs from 'fs';
import * as webpack from 'webpack';
import chalk from 'chalk';
import rndstr from 'rndstr';
const { VueLoaderPlugin } = require('vue-loader');
const WebpackOnBuildPlugin = require('on-build-webpack');
//const HardSourceWebpackPlugin = require('hard-source-webpack-plugin');
const ProgressBarPlugin = require('progress-bar-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const isProduction = process.env.NODE_ENV == 'production';
const constants = require('./src/const.json');
const locales = require('./locales');
const meta = require('./package.json');
const version = isProduction ? meta.clientVersion : meta.clientVersion + '-' + rndstr({ length: 8, chars: '0-9a-z' });
const codename = meta.codename;
const postcss = {
loader: 'postcss-loader',
options: {
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',
test: './src/client/app/test/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
}
}, postcss, {
loader: 'stylus-loader'
}]
}, {
use: [{
loader: 'vue-style-loader'
}, {
loader: 'css-loader'
}, postcss, {
loader: 'stylus-loader'
}]
}]
}, {
test: /\.css$/,
use: [{
loader: 'vue-style-loader'
}, {
loader: 'css-loader'
}, postcss]
}, {
test: /\.(eot|woff|woff2|svg|ttf)([\?]?.*)$/,
loader: 'url-loader'
}, {
test: /\.json5$/,
loader: 'json5-loader'
}, {
test: /\.ts$/,
exclude: /node_modules/,
use: [{
loader: 'ts-loader',
options: {
happyPackMode: true,
configFile: __dirname + '/src/client/app/tsconfig.json',
appendTsSuffixTo: [/\.vue$/]
}
}]
}]
},
plugins: [
//new HardSourceWebpackPlugin(),
new ProgressBarPlugin({
format: chalk` {cyan.bold yes we can} {bold [}:bar{bold ]} {green.bold :percent} {gray (:current/:total)} :elapseds`,
clear: false
}),
new webpack.DefinePlugin({
_COPYRIGHT_: JSON.stringify(constants.copyright),
_VERSION_: JSON.stringify(meta.version),
_CLIENT_VERSION_: JSON.stringify(version),
_CODENAME_: JSON.stringify(codename),
_LANGS_: JSON.stringify(Object.keys(locales).map(l => [l, locales[l].meta.lang])),
_ENV_: JSON.stringify(process.env.NODE_ENV)
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(isProduction ? 'production' : 'development')
}),
new WebpackOnBuildPlugin((stats: any) => {
fs.writeFileSync('./built/client/meta.json', JSON.stringify({
version
}), 'utf-8');
}),
new VueLoaderPlugin(),
new webpack.optimize.ModuleConcatenationPlugin()
],
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'
}
},
resolveLoader: {
modules: ['node_modules']
},
optimization: {
minimizer: [new TerserPlugin()]
},
cache: true,
devtool: false, //'source-map',
mode: isProduction ? 'production' : 'development'
};