-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
53 lines (49 loc) · 1.33 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
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const DotenvPlugin = require('webpack-dotenv-plugin');
const rootDir = path.resolve(__dirname, '.');
const dirs = {
src: path.resolve(rootDir, 'src'),
dist: path.resolve(rootDir, 'dist')
};
const webpackConfig = isProd => {
const config = ({
mode: isProd ? 'production' : 'development',
devtool: 'inline-source-map',
entry: path.resolve(dirs.src, 'app/index.tsx'),
resolve: {
extensions: ['.ts', '.tsx', '.js'],
},
output: {
path: path.resolve(__dirname, 'dist'), // string
filename: 'bundle.js',
libraryTarget: 'umd',
},
module: {
rules: [
// all files with a `.ts` or `.tsx` extension will be handled by `ts-loader`
{ test: /\.tsx?$/, loader: 'ts-loader' },
{ test: /\.css?$/, loader: ['style-loader', 'css-loader'] },
],
},
devServer: {
contentBase: dirs.dist,
compress: true,
port: 9000,
},
plugins: [
new HtmlWebpackPlugin({
template: path.resolve(dirs.src, 'html/index.html'),
}),
new DotenvPlugin({
path: path.resolve(rootDir, '.env'),
sample: path.resolve(rootDir, '.env.sample'),
})
],
});
return config;
}
module.exports = {
webpackConfig,
default: webpackConfig(true),
};