This repository has been archived by the owner on Aug 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
120 lines (114 loc) · 2.96 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
const path = require("path");
var webpackNotifier = require("webpack-notifier");
var htmlWebpack = require("html-webpack-plugin");
var pkg = require("./package.json");
var webpack = require("webpack");
var DotEnv = require("dotenv-webpack");
const devPlugins = [
new webpackNotifier({ title: pkg.name }),
new webpack.HotModuleReplacementPlugin(),
/**
* @see https://github.com/mrsteele/dotenv-webpack
* @param path ('./.env') - The path to your environment variables.
* @param safe (false) - If false ignore safe-mode, if true load './.env.example', if a string load that file as the sample.
* @param systemvars (false) - Set to true if you would rather load all system variables as well (useful for CI purposes).
* @param silent (false) - If true, all warnings will be surpressed.
*/
new DotEnv({})
];
const buildDir = "built";
const devConfig = {
devServer: {
host: "localhost",
port: 8090,
historyApiFallback: true,
hot: true,
inline: true,
stats: "errors-only"
}
};
const prodConfig = {};
const prodPlugins = [
new webpack.DefinePlugin({
'process.env': {
NLU_TRAINER_API: JSON.stringify(process.env.NLU_TRAINER_API)
}
})
];
module.exports = function(env) {
let otherPlugins = env === "dev" ? devPlugins : prodPlugins;
let otherConf = env === "dev" ? devConfig : prodConfig;
return {
entry: [ "babel-polyfill", path.resolve(__dirname) ],
output: {
path: path.resolve(__dirname, buildDir),
publicPath: "/",
filename: "app.js"
},
performance: {
hints: false
},
mode: env === "dev" ? "development" : "production",
devtool: "source-map",
module: {
rules: [
{
test: /\.(js|jsx|mjs)$/,
loader: "babel-loader",
options: {
cacheDirectory: true
}
},
{
test: /\.tsx?$/,
use: "awesome-typescript-loader"
},
{
test: /\.(png|jpg|jpeg|gif|bmp|svg)$/,
use: [
{
loader: "file-loader",
options: {
name: "images/[hash].[ext]"
}
}
]
},
{
test: /\.(eot|woff2|woff|ttf)$/,
use: [
{
loader: "file-loader",
options: {
name: "fonts/[hash].[ext]"
}
}
]
},
{
test: /\.js$/,
exclude: /node_modules/,
enforce: "pre",
loader: "source-map-loader"
},
{
test: /\.css$/,
exclude: /node_modules/,
use: [{ loader: "style-loader" }, { loader: "css-loader" }]
}
]
},
resolve: {
extensions: [".ts", ".tsx", ".js", ".jsx", ".json"]
},
plugins: [
new htmlWebpack({
title: pkg.description,
appMountId: "app",
template: "./index.html"
}),
...otherPlugins
],
...otherConf
};
};