-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwebpack.config.js
85 lines (81 loc) · 2.51 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
const path = require('path');
const {WebpackManifestPlugin} = require('webpack-manifest-plugin');
const DotenvFlow = require('dotenv-flow-webpack');
const Dotenv = require('dotenv')
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const mapFileManifest = (file) => {
if (process.env.NODE_ENV === 'development') {
return file
}
file.path = `${process.env.PUBLIC_URL}/${file.path}`
return file;
}
const serializeManifest = (seed, files, entries) => {
files = files.map(mapFileManifest)
const filesSerialized = {}
for (const file of files) {
filesSerialized[file.name] = file.path;
}
return {
files: filesSerialized,
entrypoints: entries.main
};
}
module.exports = function (env) {
Dotenv.config({path: './.env.' + env.NODE_ENV});
return {
entry: {
main: './src/customJs/index.ts'
},
mode: env.NODE_ENV ? env.NODE_ENV : 'development',
output: {
filename: env.NODE_ENV === 'production'
? 'static/[name].[contenthash].js'
: 'index.js',
path: env.NODE_ENV === 'production'
? path.resolve(__dirname, 'build')
: path.resolve(__dirname, 'public/customJs'),
publicPath: '',
clean: true
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: ['babel-loader'],
},
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
{
test: /\.(png|svg|jpg|jpeg|gif|ico)$/i,
type: 'public/resource',
},
{
test: /\.css$/i,
use: [MiniCssExtractPlugin.loader, "css-loader"],
},
],
},
plugins: [
new MiniCssExtractPlugin({
filename: env.NODE_ENV === 'production'
? "static/[name].[contenthash].css"
: "[name].css"
}),
new WebpackManifestPlugin({
fileName: 'asset-manifest.json',
generate: serializeManifest
}),
new DotenvFlow({
node_env: env.NODE_ENV ? env.NODE_ENV : 'development'
})
],
resolve: {
extensions: ['.tsx', '.ts', '.js'],
}
};
};