forked from kiwiirc/kiwiirc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vue.config.js
138 lines (126 loc) · 4.91 KB
/
vue.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
const path = require('path');
const fs = require('fs');
const execSync = require('child_process').execSync;
const DefinePlugin = require('webpack').DefinePlugin;
const CopyWebpackPlugin = require('copy-webpack-plugin');
const StyleLintPlugin = require('stylelint-webpack-plugin');
const pkg = require('./package.json');
const makeSourceMap = process.argv.indexOf('--nomap') === -1;
module.exports = {
publicPath: '',
assetsDir: 'static/',
runtimeCompiler: true,
transpileDependencies: ['irc-framework', 'ip-regex', 'isomorphic-textencoder'],
productionSourceMap: makeSourceMap,
css: {
sourceMap: makeSourceMap,
},
configureWebpack: {
resolve: {
extensions: ['.js', '.vue', '.json'],
alias: {
vue$: 'vue/dist/vue.common.js',
},
// This prevents yarn link modules from getting linted
symlinks: false,
},
performance: {
maxEntrypointSize: 1500000,
maxAssetSize: 1000000,
},
optimization: {
splitChunks: {
cacheGroups: {
// replace the vendors test so it does not chunk css files
vendors: {
name: 'vendor',
test: (m) => /[\\/]node_modules[\\/]/.test(m.context) && m.constructor.name !== 'CssModule',
},
},
},
},
plugins: [
new DefinePlugin({
__VERSION__: JSON.stringify(pkg.version),
__COMMITHASH__: JSON.stringify(getCommitHash()),
}),
new StyleLintPlugin({
files: ['src/**/*.{vue,htm,html,css,sss,less,scss}'],
}),
new CopyWebpackPlugin([
{
from: path.join(__dirname, 'static/'),
to: path.join(__dirname, 'dist/static/'),
toType: 'dir',
ignore: ['.*', 'config.local.json'],
},
]),
],
},
chainWebpack: (config) => {
config.plugin('html').tap((args) => {
args[0].template = path.join(__dirname, 'index.html');
args[0].minify = false;
return args;
});
// add build/ to resolveLoader for exports-loader
config.resolveLoader.modules.add(path.resolve(__dirname, 'build/webpack/'));
// add exports-loader for GobalApi
const vueRule = config.module.rule('vue');
const vueCacheOptions = vueRule.uses.get('cache-loader').get('options');
const vueOptions = vueRule.uses.get('vue-loader').get('options');
vueRule.uses.clear();
vueRule.use('cache-loader').loader('cache-loader').options(vueCacheOptions);
vueRule.use('exports-loader').loader('exports-loader');
vueRule.use('vue-loader').loader('vue-loader').options(vueOptions);
const jsRule = config.module.rule('js');
const jsCacheOptions = jsRule.uses.get('cache-loader').get('options');
jsRule.uses.clear();
jsRule.use('cache-loader').loader('cache-loader').options(jsCacheOptions);
jsRule.use('exports-loader').loader('exports-loader');
jsRule.use('babel-loader').loader('babel-loader');
config.module
.rule('html')
.test(/\.html$/)
.exclude.add(path.join(__dirname, 'index.html')).end()
.use('html-loader')
.loader('html-loader');
// Remove the old 'app' entry
config.entryPoints.delete('app');
// IE11 required by the webpack runtime for async import().
// babel polyfills don't help us here
config.entry('app').add('core-js/features/promise');
// IE11 play nice with vue-virtual-scroller
config.entry('app').add('core-js/features/array/virtual/find-index');
config.entry('app').add('core-js/features/array/virtual/includes');
// Kiwiirc main entry point
config.entry('app').add('./src/main.js');
},
};
// override config.json with config.local.json if it exists
if (process.env.NODE_ENV === 'development') {
let plugins = module.exports.configureWebpack.plugins;
let localConfig = path.resolve(__dirname, 'static/config.local.json');
if (fs.existsSync(localConfig)) {
plugins.push(new CopyWebpackPlugin([
{
from: localConfig,
to: path.join(__dirname, 'dist/static/config.json'),
force: true,
},
]));
}
}
function getCommitHash() {
let commitHash = 'unknown';
try {
commitHash = execSync('git rev-parse --short HEAD').toString().trim();
const modified = execSync('git diff-index --quiet HEAD -- || echo true').toString();
if (modified.trim() === 'true') {
commitHash += '-modified';
}
} catch {
console.error('Failed to get commit hash');
}
return commitHash;
}