-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebpack.prod.js
More file actions
120 lines (114 loc) · 3.32 KB
/
Copy pathwebpack.prod.js
File metadata and controls
120 lines (114 loc) · 3.32 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
const path = require("path");
const webpack = require("webpack");
const CaseSensitivePathsPlugin = require("case-sensitive-paths-webpack-plugin");
const DirectoryNamedWebpackPlugin = require("directory-named-webpack-plugin");
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const outputFolder = "dist";
module.exports = {
devtool: "hidden-source-map",
mode: "production",
context: path.resolve(__dirname, "src"),
entry: ["@babel/polyfill", "./main.jsx"],
target: "web",
output: {
path: path.resolve(__dirname, outputFolder),
filename: "./[name].js"
// Config publicPath to serve html file separately
// publicPath: `./${outputFolder}/`
},
//////////////////////////////////////////////////////
// Resolves imports - helps make importing less verbose
resolve: {
mainFiles: ["index"],
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: ExtractTextPlugin.extract({
fallback: "style-loader",
use: [
{
loader: "css-loader",
options: {
modules: true,
localIdentName: "[name]--[local]--[hash:base64:5]",
sourceMap: true,
importLoaders: 2,
minimize: true
// 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",
options: {
limit: 5000,
name: "assets/[path][name].[hash].[ext]",
publicPath: "dist/"
}
},
{ parser: { amd: false } }
]
},
////////////////////////////////////////////
// Plugins
plugins: [
new ExtractTextPlugin({
filename: "css/style.css",
disable: false,
allChunks: true
}),
new webpack.DefinePlugin({
"process.env.NODE_ENV": JSON.stringify("production")
}),
new webpack.optimize.ModuleConcatenationPlugin(),
new CaseSensitivePathsPlugin(),
new webpack.optimize.AggressiveMergingPlugin(),
new HtmlWebpackPlugin({ template: "./template.html" })
]
};