-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebpack.config.js
More file actions
161 lines (148 loc) · 4.54 KB
/
Copy pathwebpack.config.js
File metadata and controls
161 lines (148 loc) · 4.54 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
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
const path = require("path");
const webpack = require("webpack");
const HtmlWebpackPlugin = require("html-webpack-plugin");
// Resolves issues when deploying the project to case sensitive flie systems on liuux
const CaseSensitivePathsPlugin = require("case-sensitive-paths-webpack-plugin");
// Allows one to use directory names for components
const DirectoryNamedWebpackPlugin = require("directory-named-webpack-plugin");
const ExtractTextPlugin = require("extract-text-webpack-plugin");
// Below is to add addtional attributes to the script tag for react
// const ScriptExtHtmlWebpackPlugin = require('script-ext-html-webpack-plugin');
module.exports = {
devtool: "cheap-module-eval-source-map",
mode: "development",
context: path.resolve(__dirname, "src"),
entry: ["@babel/polyfill", "./main.jsx"],
////////////////////////////////////////////
// Output
output: {
path: path.resolve(__dirname, "dist"),
filename: "./bundle.js",
pathinfo: true
},
//////////////////////////////////////////////////////
// Resolves imports - helps make importing less verbose
resolve: {
mainFields: ["browser", "module", "main"],
extensions: [".js", ".jsx", ".scss", ".css"], // resolves imports
modules: [
path.resolve("./src"),
path.resolve("./node_modules"),
path.resolve("./src/components")
],
plugins: [
// Resolves component directory names
new DirectoryNamedWebpackPlugin({
honorIndex: true,
exclude: /node_modules/
})
]
},
//////////////////////////////////////
// Modules Loaders
module: {
rules: [
{
test: /\.(js|jsx)$/,
use: ["babel-loader"],
include: path.join(__dirname, "src")
},
{
test: /\.(css|sass|scss)$/,
////////////////////////////////////////
use: ["css-hot-loader"].concat(
ExtractTextPlugin.extract({
fallback: "style-loader",
use: [
{
loader: "css-loader",
options: {
modules: true,
localIdentName: "[name]--[local]--[hash:base64:5]",
sourceMap: true,
importLoaders: 2
// show original src classname in css
}
},
{
loader: "postcss-loader",
options: {
plugins: [require("autoprefixer")],
sourceMap: true
}
},
{
loader: "sass-loader",
options: {
sourceMap: true,
includePaths: [path.resolve("src", "/styles")]
}
}
]
})
),
////////////////////////////////////////
include: [
path.join(__dirname, "src"),
path.join(__dirname, "/node_modules/normalize.css")
]
},
{
test: /\.(jpg|png|gif|svg|mp3)$/,
loader: "url-loader"
},
{ parser: { amd: false } }
]
},
// ////////////////////////////////////////////
// // Plugins
plugins: [
// new CaseSensitivePathsPlugin({debug: true}),
new CaseSensitivePathsPlugin(),
// prints more readable module names in the browser console on HMR updates
new webpack.NamedModulesPlugin(),
// Generate a new index.html
new HtmlWebpackPlugin({
inject: "body", // inject tags into
filename: "index.html", // file name
template: "./template.html" // template to generate html
}),
new ExtractTextPlugin({
filename: "css/style.css",
disable: false,
allChunks: true
}) // this means dist/css/style.css
],
// ////////////////////////////////////////////
// // This is the config for webpack-dev-server
devServer: {
// Load content from bundle
inline: true,
compress: true,
historyApiFallback: true,
host: "0.0.0.0",
// disableHostCheck: true,
// open: true
///// These options are commented out unless we need
///// to generate HTML on the fly.
contentBase: path.resolve(__dirname, "dist"),
// Slience various log levles
stats: {
colors: true,
hash: false,
version: false,
timings: false,
assets: false,
chunks: false,
modules: false,
children: false,
source: false,
publicPath: false,
warnings: true,
errors: true
}
// should always point to a index.html
// publicPath: '/' // should always match output dir
}
////////////////////////////////////////////
};