-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
92 lines (88 loc) · 2.27 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
const path = require('path');
const webpack = require('webpack');
const packageJson = require('./package.json');
const repoInfo = require('git-repo-info')();
const { DefinePlugin } = webpack;
const { VueLoaderPlugin } = require('vue-loader');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const buildEnv = process.argv.includes('--mode=production') ? 'production' : 'development';
const devMode = buildEnv === 'development';
module.exports = {
externals: {
jquery: 'jQuery'
},
entry: {
app: [
'./js/main.js'
]
},
resolve: {
alias: {
'@': path.join(__dirname, 'js')
},
extensions: ['.js', '.vue', '.json']
},
output: {
path: path.join(__dirname, 'dist'),
filename: 'assets/bundle.[chunkhash].js',
library: 'ReportCounts'
},
module: {
rules: [
{
test: /\.vue$/,
loader: 'vue-loader'
},
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
},
{
test: /\.css$/,
use: [devMode ? 'style-loader' : MiniCssExtractPlugin.loader, 'css-loader']
},
{
test: /\.(png|svg|jpg|gif)$/,
loader: 'file-loader',
options: {
name: 'assets/[name].[hash].[ext]'
}
}
]
},
devtool: 'cheap-source-map',
plugins: [
new DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(buildEnv),
REPORT_COUNTS_VERSION: JSON.stringify(packageJson.version),
REPORT_COUNTS_GIT_HASH: JSON.stringify(repoInfo.abbreviatedSha)
}),
new VueLoaderPlugin(),
new CopyWebpackPlugin({
patterns: [
'*.md',
'LICENSE',
'index.php',
'ReportCounts.php',
'config.json',
'lib/**/*.php'
]
}),
new HtmlWebpackPlugin({
template: 'lib/main.tmpl',
filename: 'lib/main.php',
hash: false,
inject: false
}),
new MiniCssExtractPlugin({
filename: devMode ? 'assets/report-counts.css' : 'assets/report-counts.[contenthash].css',
chunkFilename: devMode ? '[id].css' : '[id].[hash].css'
})
]
};