-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.ts
78 lines (76 loc) · 2.83 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
import * as path from 'path';
import * as webpack from 'webpack';
import { Configuration } from 'webpack';
export default function configure(env: any): Array<webpack.Configuration> {
const isDevBuild: boolean = !(env && env.prod);
const mode: Configuration['mode'] =
(process.env.NODE_ENV as Configuration['mode']) || 'development';
const clientBundleOutputDir: string = './'; // './dist';
const clientBundleConfig: webpack.Configuration = {
mode,
stats: { modules: false },
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx']
},
entry: {
'src/client': './src/client.tsx'
},
output: {
filename: '[name].js',
chunkFilename: '[name]-chunk.js',
publicPath: '/dist/',
path: path.join(__dirname, clientBundleOutputDir)
},
module: {
rules: [
{
test: /\.tsx?$/,
include: [/src/, /demo/],
exclude: /node_modules/,
use: 'ts-loader'
}
]
},
plugins: [
// new webpack.NamedModulesPlugin(),
// new webpack.optimize.CommonsChunkPlugin({
// name: "vendor",
// minChunks: Infinity,
// filename: "vendor.bundle.js"
// }),
...(isDevBuild
? [
// Plugins that apply in development builds only
new webpack.SourceMapDevToolPlugin({
filename: '[file].map', // Remove this line if you prefer inline source maps
moduleFilenameTemplate: path.relative(
clientBundleOutputDir,
'[resourcePath]'
)
// Point sourcemap entries to the original file locations on disk
})
]
: [
new webpack.LoaderOptionsPlugin({
minimize: true,
debug: false
}) // , // prod
// new webpack.optimize.UglifyJsPlugin({
// compress: {
// warnings: false
// },
// comments: false,
// sourceMap: false
// }) // prod
]),
new webpack.DefinePlugin({
process: {},
'process.env': {},
'process.env.NODE_ENV': JSON.stringify(mode),
__DEV__: mode === 'development',
__TEST__: (mode as any) === 'test'
}) // prod
]
};
return [clientBundleConfig];
}