-
Notifications
You must be signed in to change notification settings - Fork 4
/
webpack.config.js
105 lines (87 loc) · 2.07 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
var { DefinePlugin } = require("webpack");
var { CleanWebpackPlugin } = require("clean-webpack-plugin");
var CopyWebpackPlugin = require("copy-webpack-plugin");
var HtmlWebpackPlugin = require("html-webpack-plugin");
var MiniCssExtractPlugin = require("mini-css-extract-plugin");
var OptimizeCssAssetsPlugin = require("optimize-css-assets-webpack-plugin");
var WebpackBar = require('webpackbar');
var path = require('path');
var mode = (process.env.NODE_ENV === "production" ? "production" : "development");
var isProduction = (mode == "production");
var plugins = [
new WebpackBar(),
new DefinePlugin({
PRODUCTION: JSON.stringify(isProduction),
}),
new CleanWebpackPlugin(),
new MiniCssExtractPlugin({
filename: "bundle.css"
}),
new CopyWebpackPlugin([
{ from: "robots.txt", to: "" },
{ from: "public/css", to: "css" },
{ from: "public/fonts", to: "fonts" },
{ from: "public/img", to: "img" },
{ from: "public/js", to: "js" }
]),
new HtmlWebpackPlugin({
template: "base.ejs",
inject: false,
title: "MyHomeworkSpace"
})
];
if (isProduction) {
plugins.push(new OptimizeCssAssetsPlugin({}));
}
module.exports = {
entry: './app/main.js',
devtool: 'source-map',
devServer: {
contentBase: "./dist",
disableHostCheck: true, // TODO: this should not be needed
historyApiFallback: true,
port: 9001,
public: "app.myhomework.localhost:80"
},
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist'),
library: "MHSBridge"
},
module: {
rules: [
{
test: /.(js|jsx)$/,
loaders: 'buble-loader',
include: path.join(__dirname, 'app'),
options: {
jsx: "h",
jsxFragment: "Fragment",
objectAssign: "Object.assign"
}
},
{
test: /\.(styl)$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
hmr: isProduction
},
},
"css-loader",
"stylus-loader"
]
},
{ test: /\.(css)$/, use: 'css-loader' }
]
},
plugins: plugins,
resolve: {
modules: [
path.resolve("./app"),
path.resolve("./node_modules")
]
},
stats: 'errors-warnings'
};