forked from webbestmaster/typescript-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
executable file
·126 lines (112 loc) · 3.71 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
const path = require('path');
const nodeExternals = require('webpack-node-externals');
const externals = [nodeExternals()]; // in order to ignore all modules in node_modules folder
const externalsPresets = {node: true}; // in order to ignore built-in modules like path, fs, etc.
const {optimization} = require('./webpack/setting/optimization');
const {rules} = require('./webpack/setting/module/rules');
const {alias} = require('./webpack/setting/resolve/alias');
const {extensions} = require('./webpack/setting/resolve/extensions');
const {plugins} = require('./webpack/setting/plugins');
const {devServer} = require('./webpack/setting/dev-server');
const {watchOptions} = require('./webpack/setting/watch-options');
const {
pathToStaticFileFolder,
isDevelopment,
isProduction,
pathToDist,
cwd,
nodeEnvironment,
isBuildLibrary,
isFront,
isBack,
isServerProdBuild,
} = require('./webpack/config');
const configFront = {
entry: [
'./www/css/root.scss',
'markdown-pro/dist/style.css',
'react-audio-player-pro/dist/style.css',
'./www/root.tsx',
],
output: {
pathinfo: false,
path: path.join(cwd, pathToDist),
publicPath: isDevelopment ? '/' : pathToStaticFileFolder,
filename: isDevelopment ? '[name].js' : 'index.js',
chunkFilename: isDevelopment ? '[name].chunk.js' : '[name].[hash:6].chunk.js',
assetModuleFilename: isDevelopment
? 'build-asset/[name]----[hash:6][ext][query]'
: 'build-asset/[hash:6][ext][query]',
},
mode: nodeEnvironment,
devtool: isDevelopment ? 'source-map' : false,
optimization,
module: {rules},
resolve: {alias, extensions},
plugins,
devServer,
watchOptions,
};
const configBack = {
...configFront,
entry: ['./server/server.tsx'],
optimization: isServerProdBuild ? optimization : {minimize: false},
target: 'node',
devtool: isServerProdBuild ? false : 'source-map',
externalsPresets,
externals,
};
const configLibraryFront = {
entry: ['./www/library/library.ts'],
output: {
pathinfo: false,
path: path.join(cwd, 'dist'),
publicPath: '',
filename: 'index.js',
libraryTarget: 'commonjs2',
},
mode: nodeEnvironment,
devtool: false,
optimization,
module: {rules},
resolve: {alias, extensions},
plugins,
devServer,
externalsPresets,
externals,
watchOptions,
/*
externals: {
// Don't bundle react and react-dom
react: {
commonjs: 'react',
commonjs2: 'react',
amd: 'React',
root: 'React',
},
'react-dom': {
commonjs: 'react-dom',
commonjs2: 'react-dom',
amd: 'ReactDOM',
root: 'ReactDOM',
},
'react-router-dom': {
commonjs: 'react-router-dom',
commonjs2: 'react-router-dom',
amd: 'ReactRouterDOM',
root: 'ReactRouterDOM',
},
},
*/
};
const configLibraryBack = {...configLibraryFront};
let webpackConfigBySide = null;
webpackConfigBySide = isFront ? configFront : webpackConfigBySide;
webpackConfigBySide = isBack ? configBack : webpackConfigBySide;
let webpackConfigBuildLibraryBySide = null;
webpackConfigBuildLibraryBySide = isFront ? configLibraryFront : webpackConfigBuildLibraryBySide;
webpackConfigBuildLibraryBySide = isBack ? configLibraryBack : webpackConfigBuildLibraryBySide;
const webpackConfig = isBuildLibrary ? webpackConfigBuildLibraryBySide : webpackConfigBySide;
// const {BundleAnalyzerPlugin} = require('webpack-bundle-analyzer');
// webpackConfig.plugins.push(new BundleAnalyzerPlugin());
module.exports = webpackConfig;