forked from joeypi/webpack-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
executable file
·157 lines (144 loc) · 4.26 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
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
var webpack = require('webpack');
var path = require('path');
var glob = require('glob');
var BrowserSyncPlugin = require('browser-sync-webpack-plugin');
var ExtractTextPlugin = require("extract-text-webpack-plugin");
// clean the cache on each new build
var CleanWebpackPlugin = require('clean-webpack-plugin');
//manifest for assets, helps get hashed files through json
var ManifestPlugin = require('webpack-manifest-plugin');
var OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var inProduction = (process.env.NODE_ENV === 'production');
module.exports = {
// ------------------------------------
// Entry Points
// ------------------------------------
entry: {
custom: [
'./build/js/custom.js',
'./build/sass/main.scss'
],
vendor: [
'wowjs',
'slick-carousel',
'bootstrap',
'jquery-smooth-scroll',
'jquery.scrollto',
'popper.js'
]
},
// ------------------------------------
// Output
// ------------------------------------
output: {
path: path.resolve(__dirname, './assets'),
filename: 'js/[name].js'
},
// ------------------------------------
// Devtool
// ------------------------------------
devtool: "source-map",
// ------------------------------------
// Module
// ------------------------------------
module: {
rules: [
{
test: /\.s[ac]ss$/,
use: ExtractTextPlugin.extract({
use: [
'css-loader',
'resolve-url-loader',
'sass-loader?sourceMap'
],
fallback: 'style-loader',
publicPath: './../'
})
},
{
test: /\.(eot|ttf|woff|woff2)$/,
loaders: [
{
loader: 'file-loader',
options: {
name: 'fonts/[name].[ext]'
}
}
],
},
{
test: /\.(svg)$/,
loaders: [
{
loader: 'file-loader',
options: {
name: 'svg/[name].[ext]'
}
}
],
},
{
test: /\.(png|jpe?g|gif)$/,
loaders: [
{
loader: 'file-loader',
options: {
name: 'images/[name].[ext]'
}
},
'image-webpack-loader'
],
},
{
test: /\.js$/,
exclude: /node_modules/,
loader: "babel-loader"
}
]
},
// ------------------------------------
// Plugins
// ------------------------------------
plugins: [
new CleanWebpackPlugin(['assets'], {
root: __dirname,
verbose: true,
dry: false,
}),
new webpack.ProvidePlugin({
jQuery: 'jquery',
Popper: [
'popper.js',
'default'
],
}),
new ExtractTextPlugin('css/style.css'),
]
};
// ------------------------------------
// Production Settings
// ------------------------------------
if (inProduction) {
module.exports.plugins.push(
new webpack.optimize.UglifyJsPlugin()
);
module.exports.plugins.push(
new OptimizeCssAssetsPlugin({
assetNameRegExp: /\.css$/,
cssProcessorOptions: { discardComments: { removeAll: true } }
})
);
} else {
module.exports.plugins.push(
// change target to your local development url
new BrowserSyncPlugin({
host: '127.0.0.1',
port: 3000,
// proxy: {
// target: 'http://yourLocalDomain.local/',
// },
server: { baseDir: ['./'] }
})
);
}