-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
72 lines (66 loc) · 1.82 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
const path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const ReplaceInFileWebpackPlugin = require('replace-in-file-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const glob = require('glob');
const VERSION = require('./package.json').version;
const GitRevisionPlugin = require('git-revision-webpack-plugin');
const gitRevisionPlugin = new GitRevisionPlugin({
versionCommand: 'rev-list HEAD --count --no-merges',
});
function resolve(dir) {
return path.join(__dirname, dir);
}
function getEntry(rootSrc, pattern) {
const files = glob.sync(path.resolve(rootSrc, pattern));
return files.reduce((res, file) => {
const info = path.parse(file);
const key = `${info.dir.slice(rootSrc.length + 1)}/${info.name}`;
res[key] = path.resolve(file);
return res;
}, {});
}
const appEntry = { main: resolve('./src/utils/index.js') };
const pagesEntry = getEntry(resolve('./src'), 'pages/**/main.js');
const entry = Object.assign({}, appEntry, pagesEntry);
module.exports = {
entry: entry,
output: {
path: resolve('dist'),
filename: '[name].js',
},
module: {
rules: [
{
test: /^main.js$/,
loader: 'babel-loader',
},
],
},
resolve: {
extensions: ['.js', '.vue', '.json'],
alias: {
vue: 'mpvue',
'@': resolve('src'),
},
symlinks: false,
},
plugins: [
new CleanWebpackPlugin(resolve('dist')),
new CopyWebpackPlugin([{
from: resolve('./src'), to: resolve('./dist'), toType: 'dir', force: true,
}]),
new ReplaceInFileWebpackPlugin([{
dir: 'dist',
files: ['./utils/settings.js'],
rules: [{
search: '$GIT_COUNT',
replace: gitRevisionPlugin.version(),
},
{
search: '$VERSION',
replace: VERSION,
}],
}]),
],
};