-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
120 lines (117 loc) · 2.61 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
/**
* Requires
*/
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const CleanWebpackPlugin = require('clean-webpack-plugin')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const path = require('path')
const merge = require('webpack-merge')
/**
* Variables
*/
const Parts = require('./webpack.parts')
const PATHS = {
src: path.join(__dirname, 'src'),
dist: path.join(__dirname, 'dist')
}
const templatePublicPath = '/templates/simple-web/'
/**
* Common Configuration
*/
const Common = merge([
{
context: PATHS.src,
entry: {
main: './index.js',
},
output: {
filename: 'assets/js/[name].bundle.js',
path: PATHS.dist,
library: '[name]',
publicPath: templatePublicPath,
},
module: {
rules: [
{
// Regex pattern that matches any files with a .js or .jsx
// file extension
test: /\.jsx?$/,
include: [path.join(__dirname, 'src')],
// Exclude the node_modules folder from being transpiled
exclude: /node_modules/,
// Transform all .js and .jsx files to standard ES5 syntax
// using the Babel loader
use: 'babel-loader'
},
{
test: /\.html$/,
use: [
{
loader: 'html-loader',
options: {
name: '[name].[ext]'
}
}
]
},
{
test: /\.(jpg|jpeg|png|svg|gif|woff|woff2|otf|ttf)$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'assets/images/',
publicPath: templatePublicPath,
include: [path.join(__dirname, 'src')]
}
}
]
}
],
},
plugins: [
new HtmlWebpackPlugin({
filename: 'index.html',
template: path.join(PATHS.src, 'index.html') ,
chunks: ['main']
}),
new HtmlWebpackPlugin({
filename: 'users.html',
template: path.join(PATHS.src, 'users.html') ,
chunks: ['main']
}),
new CleanWebpackPlugin(['dist'])
]
}
])
module.exports = function (env) {
/**
* Production Configuration
*/
if (env === 'production') {
return merge([
Common,
Parts.lintJS({ paths: PATHS.src }),
Parts.CSS(env)
])
}
/**
* Develpment Configuration
*/
return merge([
Common,
Parts.devServer({
host: process.env.HOST,
port: process.env.PORT
}),
Parts.lintJS({
paths: PATHS.src,
options: {
emitWarning: true
}
}),
Parts.CSS(env)
])
}