This repository has been archived by the owner on Feb 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathwebpack.config.ts
132 lines (122 loc) · 4.12 KB
/
webpack.config.ts
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
const cssnano = require('cssnano');
import * as fs from 'fs';
const OpenBrowserPlugin = require('open-browser-webpack-plugin');
import * as path from 'path';
import * as webpack from 'webpack';
// noinspection ES6UnusedImports
const webpackDevServer = require('webpack-dev-server');
import { IS_DEV, SERVER_PORT, WEBPACK_PORT } from './server/config';
const ManifestPlugin = require('webpack-manifest-plugin');
// Fix for TsconfigPathsPlugin
process.env.TS_NODE_PROJECT = '';
import { TsconfigPathsPlugin } from 'tsconfig-paths-webpack-plugin';
const plugins = [new ManifestPlugin()];
const lessToJs = require('less-vars-to-js');
const themeVariables = lessToJs(fs.readFileSync(path.join(__dirname, './ant-theme-vars.less'), 'utf8'));
// import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
// plugins.push(new BundleAnalyzerPlugin());
if (IS_DEV) {
plugins.push(new OpenBrowserPlugin({url: `http://localhost:${SERVER_PORT}`}));
}
const nodeModulesPath = path.resolve(__dirname, 'node_modules');
const config: webpack.Configuration = {
mode: IS_DEV ? 'development' : 'production',
devtool: IS_DEV ? 'inline-source-map' : false,
entry: ['@babel/polyfill', './client/client'],
output: {
path: path.join(__dirname, 'dist', 'statics'),
filename: `[name]-[hash:8]-bundle.js`,
publicPath: '/statics/',
},
resolve: {
alias: {'react-dom': '@hot-loader/react-dom'},
extensions: ['.js', '.ts', '.tsx'],
plugins: [
new TsconfigPathsPlugin({ configFile: path.join(__dirname, 'client', 'tsconfig.client.json') })
]
},
optimization: {
splitChunks: {
cacheGroups: {
commons: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'all',
},
},
},
},
module: {
rules: [
{
test: /\.tsx?$/,
loaders: ['babel-loader'],
exclude: [/node_modules/, nodeModulesPath],
},
{
test: /\.less$/,
exclude: /node_modules/,
use: [
{
loader: 'style-loader',
},
{
loader: 'css-loader',
options: {
modules: true,
camelCase: true,
sourceMap: IS_DEV,
},
},
{
loader: 'less-loader',
options: {
javascriptEnabled: true,
// modifyVars: themeVariables,
}
},
{
loader: 'postcss-loader',
options: {
sourceMap: IS_DEV,
plugins: IS_DEV ? [cssnano()] : [],
},
},
],
},
{
test: /node_modules\/.*\.less$/,
use: [
{
loader: 'style-loader',
},
{
loader: 'css-loader',
options: {
sourceMap: true,
},
},
{
loader: 'less-loader',
options: {
javascriptEnabled: true,
sourceMap: true,
// modifyVars: themeVariables,
// root: path.resolve(__dirname, './')
}
},
]
},
{
test: /.jpe?g$|.gif$|.png$|.svg$|.woff$|.woff2$|.ttf$|.eot$/,
use: 'url-loader?limit=10000',
},
],
},
devServer: {
port: WEBPACK_PORT,
},
plugins,
externals: {},
};
export default config;