-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.babel.js
92 lines (70 loc) · 2.35 KB
/
webpack.config.babel.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
require('dotenv').config();
import path from 'path';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import HtmlWebpackHarddiskPlugin from 'html-webpack-harddisk-plugin';
const isHot = process.argv.indexOf('--hot') !== -1; // detect --hot
const isDev = process.argv.indexOf('development') !== -1; // detect --mode development
console.info("Webpack " + (isHot ? "running hot-reload sever" : "building output") + " in " + (isDev ? "DEVELOPMENT" : "PRODUCTION") + " mode");
const app = {
context: path.resolve('.'),
entry: {
app: "./src/js/index.js"
},
output: {
path: path.resolve(__dirname, './dist'),
publicPath: isDev ? "http://" + process.env.HOST + ":8080/dist" : "/wp-content/themes/" + path.basename(__dirname) + "/dist/",
filename: isDev ? '[name].js' : '[name].[chunkhash].js',
chunkFilename: isDev ? '[name].js' : '[name].[chunkhash].js'
},
resolve: {
modules: [path.resolve(__dirname, "src"), "node_modules"]
},
devServer: {
overlay: true,
contentBase: path.join(__dirname),
compress: true,
host: process.env.HOST,
port: 8080,
disableHostCheck: true,
allowedHosts: [process.env.HOST],
headers: {'Access-Control-Allow-Origin': '*'}
},
// @see https://webpack.js.org/configuration/devtool/
// in DEVELOPMENT mode is set to eval by default but we need maps also...
devtool: isDev ? "cheap-eval-source-map" : false,
module: {
rules: [
// JS
{
test: /\.js$/,
exclude: /(node_modules)/,
use: {loader: "babel-loader"},
},
// CSS
{
test: /\.css$/,
use: isHot ? ["style-loader", "postcss-loader"] : [MiniCssExtractPlugin.loader, "css-loader", "postcss-loader"]
},
// images & fonts loader
{
test: /\.(jpe?g|png|gif|webp|eot|ttf|woff|woff2|svg|)$/i,
use: [
{loader: "url-loader", options: {limit: 1000, name: "assets/[name].[hash].[ext]"}}
]
}
]
},
plugins: [
new HtmlWebpackPlugin({inject: "header", title: '', minify: {collapseWhitespace: true}, alwaysWriteToDisk: true}),
// Always write HTML to disc
new HtmlWebpackHarddiskPlugin(),
].concat(isHot ? [] : [
// Extract CSS to file when is not HMR mode...
new MiniCssExtractPlugin({
filename: isDev ? 'css/[name].css' : 'css/[name].[hash].css',
chunkFilename: isDev ? 'css/[id].css' : 'css/[id].[hash].css'
})
]),
};
module.exports = app;