-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
101 lines (96 loc) · 2.19 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
const path = require("path");
const webpack = require("webpack");
const merge = require("webpack-merge");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const TARGET = process.env.npm_lifecycle_event;
const PATHS = {
src: path.join(__dirname, "src"),
build: path.join(__dirname, "lib"),
example: path.join(__dirname, "example"),
exampleBuild: path.join(__dirname, "example-build")
};
const common = {
entry: {
"fixer": path.resolve(PATHS.src, "fixer")
},
output: {
libraryTarget: "umd",
path: PATHS.build,
filename: "[name].js"
},
module: {
rules: [
{
test: /\.scss$/,
use: ["style-loader", "css-loader", "sass-loader"],
include: [PATHS.src, PATHS.example]
},
{
test: /\.js$/,
loader: "babel-loader",
include: [PATHS.src, PATHS.example],
options: {
presets: ["es2015"]
}
}
]
}
};
if (TARGET === 'start' || !TARGET) {
module.exports = merge(common, {
entry: {
"example": path.resolve(PATHS.example, "index")
},
devtool: "source-map",
devServer: {
contentBase: PATHS.example,
historyApiFallback: true,
hot: false,
inline: true,
stats: "errors-only",
host: process.env.HOST,
port: process.env.PORT || 3000
},
plugins: [
new HtmlWebpackPlugin({
filename: "index.html",
title: "Fixer example",
template: path.join(PATHS.example, "index.ejs"),
inject: false
})
]
});
}
if (TARGET === "build") {
module.exports = merge(common, {
entry: {
"fixer.min": path.resolve(PATHS.src, "fixer")
},
plugins: [
new webpack.optimize.UglifyJsPlugin({
include: /\.min\.js$/,
compress: {
warnings: false
}
})
]
});
}
if (TARGET === "deploy") {
module.exports = merge(common, {
output: {
path: PATHS.exampleBuild
},
entry: {
"example": path.resolve(PATHS.example, "index")
},
plugins: [
new HtmlWebpackPlugin({
filename: "index.html",
title: "Fixer example",
template: path.join(PATHS.example, "index.ejs"),
inject: false
})
]
});
}