/
webpack.config.base.js
148 lines (145 loc) · 3.53 KB
/
webpack.config.base.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
// Common Webpack configuration used by webpack.config.development and webpack.config.production
const path = require('path');
const webpack = require('webpack');
const autoprefixer = require('autoprefixer');
const e2c = require('electron-to-chromium');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const postcssLoaderOptions = {
plugins: [
autoprefixer({
browsers: e2c.electronToBrowserList('1.4')
}),
]
};
module.exports = {
output: {
filename: 'js/[name].[chunkhash].js',
path: path.resolve(__dirname, '../build'),
publicPath: '/'
},
resolve: {
modules: ['node_modules'],
alias: {
client: path.join(__dirname, '../src/client'),
server: path.join(__dirname, '../src/server')
},
extensions: ['.js', '.json', '.scss']
},
plugins: [
new webpack.IgnorePlugin(/vertx/),
new webpack.ProvidePlugin({
'fetch': 'imports?this=>global!exports?global.fetch!whatwg-fetch', // fetch API
$: 'jquery',
jQuery: 'jquery'
}),
// Shared code
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
filename: 'js/[name].[hash].js',
minChunks: Infinity
}),
new HtmlWebpackPlugin({
filename: 'index.html',
template: 'src/client/index.html',
inject: false,
}),
new ExtractTextPlugin({
filename: 'css/[name].[contenthash].css'
}),
],
module: {
rules: [
// JavaScript / ES6
{
test: /\.js?$/,
include: path.resolve(__dirname, '../src'),
use: 'babel-loader'
},
//HTML
{
test: /\.html$/,
include: [
path.resolve(__dirname, '../src/client/js'),
],
use: [{
loader: 'html-loader',
options: {
minimize: true
}
}],
},
// Images
// Inline base64 URLs for <=8k images, direct URLs for the rest
{
test: /\.(png|jpg|jpeg|gif|svg)$/,
use: {
loader: 'url-loader',
options: {
limit: 8192,
name: 'images/[name].[ext]?[hash]'
}
}
},
// Fonts
{
test: /\.(woff|woff2|ttf|eot)(\?v=\d+\.\d+\.\d+)?$/,
use: {
loader: 'url-loader',
options: {
limit: 8192,
name: 'fonts/[name].[ext]?[hash]'
}
}
},
// Application-wide styles
{
test: /\.scss$/,
include: [
path.resolve(__dirname, '../src/client/assets/styles'),
],
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [{
loader: 'css-loader',
options: {
sourceMap: true
}
},
{
loader: 'postcss-loader',
options: postcssLoaderOptions,
},
{
loader: 'sass-loader',
options: {
outputStyle: 'compressed'
}
}
]
})
},
// Component-scoped styles
{
test: /\.scss$/,
include: [
path.resolve(__dirname, '../src/client/js')
],
use: [{
loader: 'raw-loader'
},
{
loader: 'postcss-loader',
options: postcssLoaderOptions
},
{
loader: 'sass-loader',
options: {
outputStyle: 'compressed'
}
}
]
}
]
}
};