-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.config.js
125 lines (114 loc) · 2.72 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
121
122
123
124
125
'use strict'
const path = require('path')
const webpack = require('webpack')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const CopyPlugin = require('copy-webpack-plugin')
const ESLintPlugin = require('eslint-webpack-plugin')
const HTMLWebpackPlugin = require('html-webpack-plugin')
const DEVELOPMENT = 'development'
const PRODUCTION = 'production'
const DEV_MODE = process.env.NODE_ENV !== PRODUCTION
const DEV_HOST = 'localhost'
const DEV_PORT = 3000
const DEV_TOOL = DEV_MODE ? 'source-map' : 'cheap-module-source-map'
const BASE_PATH = DEV_MODE ? '/' : '/ultralight/'
const REMOTE_LMS_URL = process.env.LMS_URL
/*############## PLUGINS ##############*/
let plugins = [
new webpack.EnvironmentPlugin(["LMS_URL"]), // bash: export LMS_URL=http://lms_host_ip:9000
new CopyPlugin({patterns: [{from: "src/static"}]}),
new HTMLWebpackPlugin({
filename: 'index.html',
showErrors: !DEV_MODE,
template: 'src/index.html',
inject: 'body',
basePath: BASE_PATH,
}),
new MiniCssExtractPlugin(),
new ESLintPlugin({ failOnWarning: !DEV_MODE }),
]
if (DEV_MODE) {
process.env.LMS_URL = `http://${DEV_HOST}:${DEV_PORT}/lms`
} else {
plugins = plugins.concat([
new webpack.optimize.AggressiveMergingPlugin(),
new webpack.optimize.MinChunkSizePlugin({minChunkSize: 5000}),
])
}
/*############## LOADERS ##############*/
const rules = [
{
test: /\.css$/,
use: [
"style-loader",
"css-loader",
],
},
{
test: /\.styl$/,
use: [
"style-loader",
"css-loader",
"stylus-loader",
],
},
{
test: /\.font\.js$/,
use: [
"style-loader",
"css-loader",
"fontgen-loader",
],
},
{
test: /\.js$/,
use: ["babel-loader"], // see .babelrc for options
include: path.join(__dirname, 'src'),
},
{
test: /\.(woff2?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
type: 'asset/resource',
},
{
test: /\.(gif|jpg|jpeg|png)$/,
type: 'asset/resource',
},
]
/*############## OPTIONS ##############*/
module.exports = {
mode: process.env.NODE_ENV || DEVELOPMENT,
devtool: DEV_TOOL,
devServer: {
host: DEV_HOST,
port: DEV_PORT,
hot: true,
historyApiFallback: {
rewrites: [
{from: /^\/menu/, to: '/'},
],
},
proxy: {
'/lms': {
target: REMOTE_LMS_URL,
pathRewrite: {'^/lms' : ''},
},
'/favicon.ico': REMOTE_LMS_URL,
},
client: {overlay: {errors: true, warnings: false}},
},
target: 'web',
optimization: {
runtimeChunk: {name: "manifest"},
},
output: {
publicPath: BASE_PATH,
},
plugins: plugins,
module: {rules: rules},
resolve: {
modules: [
path.join(__dirname, "src"),
"node_modules",
],
},
}