-
Notifications
You must be signed in to change notification settings - Fork 876
/
webpack.config.js
98 lines (95 loc) · 3.38 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
const path = require('path');
const fs = require('fs-extra');
const cp = require('child_process');
const webpack = require('webpack');
const CleanCSS = require('clean-css');
const UglifyJS = require('uglify-js');
const CopyPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const generate = require('generate-file-webpack-plugin');
const packUtils = require('./scripts/webpack.js');
const GIT_COMMIT_ID = cp.execSync('git rev-parse HEAD').toString().trim();
const STATIC_HASH = GIT_COMMIT_ID.padStart(7, '0').slice(0, 7);
const devVscode = !!process.env.DEV_VSCODE;
const skipMinified = { info: { minimized: true } };
module.exports = (env, argv) => {
const devMode = argv.mode === 'development';
const minifyCSS = (code) => (devMode ? code : new CleanCSS().minify(code).styles);
const minifyJS = (code) => (devMode ? code : UglifyJS.minify(code).code);
return {
mode: env.mode || 'production',
entry: path.resolve(__dirname, 'src/index.ts'),
output: { filename: `static-${STATIC_HASH}/config/bootstrap.js` },
resolve: { extensions: ['.js', '.ts'] },
module: {
rules: [
{ test: /\.tsx?$/, use: 'ts-loader' },
{ test: /\.css?$/, use: ['style-loader', 'css-loader'] },
{ test: /\.svg$/, use: 'file-loader' },
],
},
plugins: [
new CopyPlugin({
patterns: [
{ from: 'public/favicon*', to: '[name][ext]' },
{ from: 'public/manifest.json', to: '[name][ext]' },
{ from: 'public/robots.txt', to: '[name][ext]' },
{
from: 'extensions',
to: `static-${STATIC_HASH}/extensions`,
globOptions: { dot: true, ignore: ['**/node_modules/**'] },
...skipMinified,
},
!devVscode && {
from: 'node_modules/@github1s/vscode-web/dist/vscode',
to: `static-${STATIC_HASH}/vscode`,
globOptions: { ignore: ['**/*.js.map'] },
...skipMinified,
},
!devVscode && {
from: 'node_modules/@github1s/vscode-web/dist/extensions',
to: `static-${STATIC_HASH}/extensions`,
globOptions: { ignore: ['**/*.js.map'] },
...skipMinified,
},
!devVscode && {
from: 'node_modules/@github1s/vscode-web/dist/web-packages',
to: `static-${STATIC_HASH}/web-packages`,
...skipMinified,
},
].filter(Boolean),
}),
new HtmlWebpackPlugin({
inject: false,
template: 'public/index.html',
templateParameters: {
devVscode: devVscode,
staticHash: STATIC_HASH,
spinnerStyle: minifyCSS(fs.readFileSync('./public/spinner.css').toString()),
pageTitleScript: minifyJS(fs.readFileSync('./public/page-title.js').toString()),
analyticsScript: devMode ? '' : minifyJS(fs.readFileSync('./public/analytics.js').toString()),
},
}),
new webpack.DefinePlugin({
STATIC_HASH: JSON.stringify(STATIC_HASH),
GITHUB_ORIGIN: JSON.stringify(process.env.GITHUB_DOMAIN || 'https://github.com'),
GITLAB_ORIGIN: JSON.stringify(process.env.GITLAB_DOMAIN || 'https://gitlab.com'),
}),
generate({
file: `static-${STATIC_HASH}/config/extensions.js`,
content: packUtils.createExtensionsContent(devVscode),
}),
],
performance: false,
devServer: {
port: 8080,
liveReload: false,
allowedHosts: 'all',
client: { overlay: false },
static: path.join(__dirname, 'dist'),
devMiddleware: { writeToDisk: true },
proxy: [packUtils.createVSCodeUnpkgProxy()],
historyApiFallback: { disableDotRule: true },
},
};
};