webpack.base.js
2.34 KB
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
const CopyPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const WebpackBar = require('webpackbar');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');
const process = require('process');
const path = require('path');
const cwd = process.cwd();
module.exports = {
output: {
filename: './js/[name]-[contenthash].js',
libraryTarget: 'umd',
clean: true,
},
entry: path.resolve(cwd, './src/index.tsx'),
module: {
rules: [
{
test: /\.(js|jsx|ts|tsx)$/,
exclude: /node_modules/,
use: [
'thread-loader',
{
loader: 'babel-loader',
options: {
presets: [
'@babel/preset-env',
'@babel/preset-react',
'@babel/preset-typescript',
],
},
},
],
},
{
test: /\.(png|jpeg|jpg)(\?[a-z0-9=&.]+)?$/,
use: {
loader: 'file-loader',
options: {
name: './public/imgs/[name].[ext]',
},
},
},
{
test: /\.(ttf|eot|woff(2)?)(\?[a-z0-9=&.]+)?$/,
use: {
loader: 'file-loader',
options: {
name: './public/fonts/[name].[ext]',
},
},
},
{
test: /\.less$/i,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
{
loader: 'less-loader',
options: {
additionalData: `@import '@/styles/variable.less';`,
},
},
],
},
{
test: /\.css$/i,
use: [MiniCssExtractPlugin.loader, 'css-loader'],
},
{
test: /\.svg$/,
use: ['@svgr/webpack', 'url-loader'],
},
],
},
resolve: {
extensions: ['.json', '.jsx', '.js', '.ts', '.tsx'],
alias: {
'@': path.resolve(cwd, './src/'),
'@/src': path.resolve(cwd, './src/'),
},
},
plugins: [
new HtmlWebpackPlugin({
template: path.resolve(cwd, './src/public/index.html'),
}),
new CopyPlugin({
patterns: [
{
from: path.resolve(cwd, './static'),
to: 'static',
},
],
}),
new WebpackBar(),
new NodePolyfillPlugin()
],
};