-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.common.js
157 lines (152 loc) · 4.2 KB
/
webpack.common.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
const webpack = require('webpack');
const path = require('path');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const HtmlPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
//const VueLoaderPlugin = require('vue-loader/lib/plugin');
const { VueLoaderPlugin } = require('vue-loader');
const CopyPlugin = require('copy-webpack-plugin');
const Dotenv = require('dotenv-webpack');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const ESLintPlugin = require('eslint-webpack-plugin');
const myEslintOptions = {
extensions: [`js`, `jsx`, `ts`], //vue
exclude: [`node_modules`],
};
const DEVELOPMENT_MODE = 'development';
const PRODUCTION_MODE = 'production';
const isProduction =
process.argv.indexOf('production') >= 0 || process.env.NODE_ENV === PRODUCTION_MODE;
const SRC_PATH = path.join(__dirname, './src');
const DIST_PATH = path.join(__dirname, './build');
module.exports = {
context: SRC_PATH,
entry: './index.ts',
output: {
// filename: 'js/app.bundle.js',
filename: 'js/[name].bundle.js',
publicPath: isProduction ? '/V3/HTTP/S3/LB/ui/' : '/',
path: DIST_PATH,
},
target: 'web',
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
mainFields: ['module', 'browser', 'main'],
alias: {
vue: '@vue/runtime-dom',
'~': path.resolve(__dirname, SRC_PATH),
},
fallback: {
buffer: false,
},
},
module: {
rules: [
{
test: /\.vue$/,
use: 'vue-loader',
},
{
test: /\.css$/,
use: [{ loader: 'style-loader' }, { loader: 'css-loader' }],
},
{
test: /\.ts$/,
use: [
{
loader: 'ts-loader',
options: { appendTsSuffixTo: [/\.vue$/] },
},
],
},
{
test: /\.scss$/,
use: [
isProduction ? MiniCssExtractPlugin.loader : 'style-loader',
{
loader: 'css-loader',
options: {
modules: {
localIdentName: isProduction ? '[hash:base64:5]' : '[local]__[hash:base64:5]',
},
sourceMap: !isProduction,
importLoaders: 1,
},
},
'sass-loader',
],
},
// {
// test: /\.(ts|vue)$/,
// enforce: 'pre',
// use: [
// {
// loader: 'eslint-loader',
// },
// ],
// exclude: /node_modules/,
// },
{
test: /\.(?:ico|gif|png|jpg|jpeg)$/i,
type: 'asset/resource',
generator: {
filename: 'images/[hash][ext]',
},
},
{
test: /\.(woff(2)?|eot|ttf|otf|svg|)$/,
type: 'asset/inline',
},
],
},
optimization: {
runtimeChunk: 'single',
splitChunks: {
chunks: 'all',
maxInitialRequests: Infinity,
minSize: 1 * 1024 * 1024,
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name(module) {
// get the name. E.g. node_modules/packageName/not/this/part.js
// or node_modules/packageName
const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1];
// npm package names are URL-safe, but some servers don't like @ symbols
return `npm.${packageName.replace('@', '')}`;
},
},
},
},
},
plugins: [
new MiniCssExtractPlugin({
filename: 'css/styles.css',
}),
new BundleAnalyzerPlugin({
analyzerMode: 'disabled',
generateStatsFile: false,
statsOptions: { source: false },
}),
new CleanWebpackPlugin(),
// new webpack.DefinePlugin({
// 'process.env': {
// NODE_ENV: isProduction ? "'production'" : "'development'",
// },
// }),
new HtmlPlugin({
title: 'LogLeads',
//favicon: "./assets/images/favicon.ico",
template: `${__dirname}/template.html`,
filename: 'index.html',
}),
new CopyPlugin({
patterns: [{ from: './assets/images/favicon.ico', to: 'images/favicon.ico' }],
}),
new VueLoaderPlugin(),
new Dotenv({
systemvars: true,
safe: true,
}),
],
};