-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.config.js
194 lines (179 loc) · 4.53 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
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
const path = require('path');
const CompressionPlugin = require('compression-webpack-plugin');
const ESLintPlugin = require('eslint-webpack-plugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const { VueLoaderPlugin } = require('vue-loader');
const VuetifyLoaderPlugin = require('vuetify-loader/lib/plugin');
const webpack = require('webpack');
const alias = {};
const getAliases = require('./@nextgis/packages/build-tools/lib/aliases.cjs');
Object.assign(alias, getAliases());
Object.assign(
alias,
getAliases(path.resolve(__dirname, '@nextgis_vue2/packages')),
);
const sassLoaderOptions = {
implementation: require('sass'),
sassOptions: {
// fiber: require('fibers'),
// indentedSyntax: true, // optional
},
};
const cssLoader = {
loader: 'css-loader',
options: {
esModule: false,
},
};
module.exports = (env, argv) => {
const isProd = argv.mode === 'production';
const rules = [
{
test: /\.vue$/,
loader: 'vue-loader',
},
{
test: /\.ts$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
},
{
loader: 'ts-loader',
options: {
appendTsSuffixTo: [/\.vue$/],
},
},
],
},
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
},
},
{
test: /\.(png|jpg|gif|svg)$/,
loader: 'file-loader',
options: {
name: '[name].[ext]?[hash]',
},
},
{
test: /\.(png|woff|woff2|eot|ttf)$/,
use: {
loader: 'url-loader',
options: {
limit: 50000,
name: './fonts/[name].[ext]', // Output below ./fonts
},
},
},
{
test: /\.css$/i,
use: [isProd ? MiniCssExtractPlugin.loader : 'style-loader', cssLoader],
},
{
test: /\.sass$/,
use: [
isProd ? MiniCssExtractPlugin.loader : 'vue-style-loader',
cssLoader,
{
loader: 'sass-loader',
// Requires sass-loader@^8.0.0
options: {
...sassLoaderOptions,
// This is the path to your variables
additionalData: "@import '@/style/variables.scss'",
},
},
],
},
// SCSS has different line endings than SASS
// and needs a semicolon after the import.
{
test: /\.scss$/,
use: [
isProd ? MiniCssExtractPlugin.loader : 'vue-style-loader',
cssLoader,
{
loader: 'sass-loader',
// Requires sass-loader@^8.0.0
options: {
...sassLoaderOptions,
// This is the path to your variables
additionalData: "@import '@/style/variables.scss';",
},
},
],
},
];
let plugins = [
new ForkTsCheckerWebpackPlugin(),
new ESLintPlugin({ fix: true, files: ['src/'], extensions: ['ts', 'vue'] }),
new VueLoaderPlugin(),
new HtmlWebpackPlugin({
template: 'index.html',
filename: 'index.html',
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(argv.mode || 'development'),
__BROWSER__: true,
__DEV__: !isProd,
}),
new VuetifyLoaderPlugin(),
];
// const BundleAnalyzerPlugin = require('webpack-bundle-analyzer')
// .BundleAnalyzerPlugin;
// plugins.push(new BundleAnalyzerPlugin());
if (isProd) {
// const zopfli = require('@gfx/zopfli');
plugins = plugins.concat([
new CompressionPlugin(),
new MiniCssExtractPlugin(),
]);
}
const config = {
mode: argv.mode || 'development',
context: path.join(__dirname, './'),
devtool: isProd ? 'source-map' : 'inline-source-map',
entry: './src/index.ts',
output: {
filename: '[name]-[hash:7].js',
path: path.resolve(__dirname, 'dist'),
},
resolve: {
extensions: ['.ts', '.js', '.vue', '.json'],
alias: {
...alias,
vue$: 'vue/dist/vue.esm.js',
'@': path.resolve(__dirname, 'src/'),
},
},
module: {
rules,
},
devServer: {
historyApiFallback: true,
},
plugins,
performance: {
hints: false,
},
target: isProd ? 'browserslist' : 'web',
optimization: {
runtimeChunk: 'single',
usedExports: true,
splitChunks: {
chunks: 'all',
minSize: 10000,
maxSize: 250000,
},
},
};
return config;
};