-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.common.js
96 lines (93 loc) · 2.7 KB
/
webpack.common.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
const path = require( 'path' );
const HtmlWebpackPlugin = require( 'html-webpack-plugin' );
const CleanWebpackPlugin = require( 'clean-webpack-plugin' );
const StyleLintPlugin = require( 'stylelint-webpack-plugin' );
const FaviconsWebpackPlugin = require( 'favicons-webpack-plugin' );
const pagesList = [
{
title: 'Home',
filename: 'index'
},
{
title: 'Dashboard',
filename: 'dashboard'
}
];
const getHtmlWebpackPluginInstances = () => {
return Object.values( pagesList ).map( page => {
const pageTitle = `Tic Tac Toe - ${ page.title }`;
return new HtmlWebpackPlugin( {
filename: `${ page.filename }.html`,
template: `./src/${ page.filename }.ejs`,
title: pageTitle,
hash: true
} );
} );
};
module.exports = {
entry: [
'babel-polyfill',
'./src/js/main.js',
...Object.values( pagesList ).map( page => `./src/${ page.filename }.ejs` )
],
output: {
filename: 'js/[name].[hash].js',
path: path.resolve( __dirname, 'dist' )
},
module: {
rules: [
{
test: /\.(html)$/,
use: [
'raw-loader'
]
},
{
test: /\.(ejs)$/,
use: [
'underscore-template-loader'
]
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/,
use: [
'file-loader?name=fonts/[name].[ext]'
]
},
{
enforce: 'pre',
test: /\.js?$/,
exclude: /(node_modules|bower_components)/,
loader: 'eslint-loader'
},
{
test: /\.js?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader',
options: {
presets: [ 'babel-preset-latest' ],
cacheDirectory: true
}
},
{
test: /\.(png|jp(e*)g|svg)$/,
use: [ {
loader: 'url-loader',
options: {
limit: 8000, // Convert images < 8kb to base64 strings
name: 'assets/images/[hash]-[name].[ext]'
}
} ]
}
]
},
plugins: [
new StyleLintPlugin( {
configFile: '.stylelintrc'
} ),
...getHtmlWebpackPluginInstances(),
new FaviconsWebpackPlugin( './src/favicon.png' ),
new CleanWebpackPlugin( [ 'dist' ] )
],
devtool: 'source-map'
};