forked from neki-dev/izowave
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
69 lines (65 loc) · 1.73 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
const path = require('path');
const alias = require('alias-reuse');
const CopyPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const webpack = require('webpack');
const tsconfig = require('./tsconfig.json');
module.exports = (_, options) => {
const isDev = options.mode === 'development';
const entryDir = path.resolve(__dirname, 'src');
const outputDir = path.resolve(__dirname, tsconfig.compilerOptions.outDir);
return {
target: 'web',
resolve: {
extensions: ['.js', '.ts', '.tsx'],
alias: alias.fromFile(__dirname, './tsconfig.json').toWebpack(),
},
entry: path.join(entryDir, 'index.ts'),
output: {
path: outputDir,
filename: 'bundle.[fullhash].js',
clean: true,
},
module: {
rules: [{
test: /\.tsx?$/,
exclude: /node_modules/,
use: ['babel-loader', 'ts-loader'],
}],
},
plugins: [
new webpack.DefinePlugin({
IS_DEV_MODE: JSON.stringify(isDev),
}),
new HtmlWebpackPlugin({
template: path.join(entryDir, 'index.html'),
filename: 'index.html',
inject: 'body',
}),
new CopyPlugin({
patterns: [
{ from: path.join(entryDir, 'assets'), to: 'assets' },
],
}),
],
devServer: {
static: {
directory: outputDir,
},
compress: true,
port: 9000,
},
devtool: isDev ? 'inline-source-map' : undefined,
optimization: isDev ? undefined : {
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
output: { comments: false },
},
}),
],
},
};
};