-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathvue.config.js
More file actions
124 lines (110 loc) · 2.81 KB
/
vue.config.js
File metadata and controls
124 lines (110 loc) · 2.81 KB
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
const { join } = require('path');
const { env } = require('process');
const { exec } = require('child_process');
// some strange errors when `public` folder not existing
exec('mkdir public');
const CompressionWebpackPlugin = require('compression-webpack-plugin');
const EVENT = env.npm_lifecycle_event;
const IS_PROD = env.NODE_ENV === 'production';
const FOR_WEB = EVENT === 'dev' || EVENT === 'website';
const content = {
entry: 'src/content/index.js',
template: 'src/content/index.html',
};
if (IS_PROD) {
content.filename = join(__dirname, 'tmp/content.html');
}
const index = {
entry: 'src/website/index.js',
template: 'src/website/index.html',
};
const options = {
entry: 'src/website/index.js',
template: 'src/website/options.html',
};
const pages = FOR_WEB ? { index } : { content, options };
const plugins = EVENT === 'website' ? [
new CompressionWebpackPlugin({
filename: '[path].gz[query]',
algorithm: 'gzip',
test: new RegExp('\\.(js|css)$'),
}),
] : [];
module.exports = {
filenameHashing: false,
outputDir: FOR_WEB ? 'public' : 'dist',
// Use VSCode lint instead of eslint-loader
// lintOnSave: false,
productionSourceMap: !IS_PROD,
pages,
css: {
// dev can also hot-reload style changes
extract: env.npm_lifecycle_event !== 'dev',
},
configureWebpack: {
output: {
filename: '[name].js',
chunkFilename: 'js/[name].js',
},
plugins,
},
devServer: {
contentBase: [
join(__dirname, FOR_WEB ? 'public' : 'dist'),
join(__dirname, 'tests'),
],
headers: {
'Access-Control-Allow-Origin': '*',
},
},
chainWebpack: (config) => {
const svgRule = config.module.rule('svg');
svgRule.uses.clear();
svgRule
.use('vue-svg-loader')
.loader('vue-svg-loader');
config
.plugin('define')
.tap((defs) => {
Object.assign(defs[0], { PROXY: JSON.stringify(env.PROXY || null) });
return defs;
});
config.module.rule('md')
.test(/\.md/)
.use('vue-loader')
.loader('vue-loader')
.end()
.use('vue-markdown-loader')
.loader('vue-markdown-loader/lib/markdown-compiler')
.options({
raw: true,
});
if (FOR_WEB) {
config
.plugin('copy')
.tap(() => [[
{
from: 'src/extension/icons/logo-48.png',
to: 'favicon.png',
toType: 'file',
},
]]);
} else {
const extension = {
from: 'src/extension',
toType: 'dir',
};
const xmlFiles = {
from: 'tests/xml',
to: 'xml',
toType: 'dir',
};
config
.plugin('copy')
.tap(() => [
IS_PROD || EVENT === 'watch' ? [extension] : [extension, xmlFiles],
]);
config.optimization.delete('splitChunks');
}
},
};