Repository navigation
Expand file tree
/
Copy pathwebpack.config.js
More file actions
93 lines (92 loc) · 2.4 KB
/
Copy pathwebpack.config.js
File metadata and controls
93 lines (92 loc) · 2.4 KB
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
const { join, resolve } = require("path");
const webpack = require("webpack");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const HtmlPlugin = require("html-webpack-plugin");
const config = require("./config.json");
module.exports = () => ({
context: resolve(__dirname, config.sourceDirectory),
devServer: {
contentBase: resolve(__dirname, config.outputDirectory),
historyApiFallback: true,
host: process.env.IP || "0.0.0.0",
hot: true,
publicPath: "/",
stats: "minimal"
},
devtool: config.devtool,
entry: {
app: [
"webpack-dev-server/client?http://localhost:8080",
"webpack/hot/only-dev-server",
"./index.js"
]
},
module: {
rules: [
{
include: resolve(__dirname, config.sourceDirectory),
loader: [
"style-loader",
{ loader: "css-loader", options: { importLoaders: 1 } },
{ loader: "postcss-loader" }
],
test: /\.css$/
},
{
include: resolve(__dirname, config.sourceDirectory),
test: /\.(js)$/,
use: [{ loader: "babel-loader" }]
},
{
enforce: "pre",
include: resolve(__dirname, config.sourceDirectory),
test: /\.(js)$/,
use: "eslint-loader"
},
{
test: /.*\.(gif|png|jpe?g|svg)$/i,
use: [
{
loader: "file-loader",
options: { name: "./dist/media/[name].[ext]" }
},
{
loader: "image-webpack-loader",
query: {
interlaced: false,
optimizationLevel: 7,
pngquant: { quality: "85-90", speed: 4 },
progressive: true
}
}
]
}
]
},
output: {
filename: "[name].js",
path: resolve(__dirname, config.outputDirectory),
pathinfo: true,
publicPath: "/"
},
plugins: [
new ExtractTextPlugin({
allChunks: true,
disable: false,
filename: "[name].css"
}),
new CopyWebpackPlugin([
{ from: config.assetsDirectory, to: config.assetsDirectory }
]),
new HtmlPlugin({
filename: "index.html",
template: join(__dirname, config.sourceDirectory, "index.html")
}),
new webpack.HotModuleReplacementPlugin(),
new webpack.NamedModulesPlugin()
],
resolve: {
extensions: [".js", ".json"]
}
});