-
Notifications
You must be signed in to change notification settings - Fork 74
/
webpack.config.js
111 lines (100 loc) · 3.19 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
99
100
101
102
103
104
105
106
107
108
109
110
111
const webpack = require('webpack');
const path = require('path');
const package = require('./package.json');
const TerserPlugin = require('terser-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const { VueLoaderPlugin } = require('vue-loader');
const vendorPackages = Object.keys(package.dependencies);
vendorPackages.splice(vendorPackages.indexOf('lodash'), 1);
// Naming and path settings
var entryPoint = {
frontend: './assets/src/frontend/main.js',
admin: './assets/src/admin/main.js',
vendor: vendorPackages,
bootstrap: './assets/src/utils/Bootstrap.js',
wphook: './assets/vendors/wp-hook/index.js',
style: './assets/less/style.less',
};
var exportPath = path.resolve(__dirname, './assets/js');
module.exports = ( env, argv ) => {
let appName = argv.mode === 'development' ? '[name].js' : '[name].min.js';
let appNameCss = argv.mode === 'development' ? '../css/[name].css' : '../css/[name].min.css';
return {
entry: entryPoint,
output: {
path: exportPath,
filename: appName,
},
resolve: {
alias: {
'vue$': 'vue/dist/vue.esm.js',
'@': path.resolve('./assets/src/'),
'frontend': path.resolve('./assets/src/frontend/'),
'admin': path.resolve('./assets/src/admin/'),
}
},
externals: {
_: 'window.wepos._'
},
plugins: [
new MiniCssExtractPlugin(
{
filename: ( { chunk } ) => {
return appNameCss;
},
}
),
new VueLoaderPlugin(),
new webpack.ProvidePlugin({
_: '_'
})
],
module: {
rules: [
{
test: /\.(js|jsx|ts)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
},
},
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
extractCSS: true
}
},
{
test: /\.(le|c)ss$/,
use: [
MiniCssExtractPlugin.loader,
"css-loader",
"less-loader",
],
},
{
test: /\.(png|woff|woff2|eot|ttf|svg)$/,
use: [
{
loader: 'file-loader',
options: {
outputPath: 'fonts',
},
},
],
}
]
},
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
extractComments: false
}),
new CssMinimizerPlugin()
],
},
}
}