-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
133 lines (132 loc) · 3.33 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
const webpack = require('webpack');
const path = require('path');
const TransferWebpackPlugin = require('transfer-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const CompressionPlugin = require('compression-webpack-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const nib = require('nib');
const rupture = require('rupture');
module.exports = {
devtool: 'cheap-module-eval-source-map',
entry: ['webpack-hot-middleware/client', './src/app/index.js'],
mode: 'development',
output: {
path: path.join(process.cwd(), './src/server/public'),
filename: 'main.js',
publicPath: '/'
},
module: {
rules: [
{
test: /\.js|jsx$/,
enforce: 'pre',
exclude: /node_modules/,
use: {
loader: 'eslint-loader',
},
},
{
test: /\.js|jsx$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
query: {
compact: false
}
}
},
{
test: /\.css|.styl$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: ['css-loader', 'stylus-loader']
}),
},
{
test: /\.(png|jpg|gif)$/,
use: [
{
loader: 'url-loader',
options: {
limit: 8192,
mimetype: 'image/png',
}
}
]
},
{
test: /\.(png|jpg|gif)$/,
use: [
{
loader: 'file-loader',
options: {}
}
]
},
{
test: /\.(woff|woff2)$/,
loader: 'url-loader?limit=10000&mimetype=application/font-woff'
},
{
test: /\.ttf$/,
loader: 'url-loader?limit=10000&mimetype=application/octet-stream'
},
{
test: /\.svg$/,
loader: 'url-loader?limit=10000&mimetype=image/svg+xml'
},
],
},
resolve: {
extensions: ['.js', '.jsx', '.styl'],
modules: ['node_modules'],
alias: { styles: path.resolve(__dirname, 'src/client/stylus/') },
},
optimization: {
splitChunks: {
chunks: 'async',
name: true,
cacheGroups: {
vendors: {
name: 'vendors',
chunks: 'all',
reuseExistingChunk: true,
priority: 1,
filename: 'vendor.js',
enforce: true,
test(module, chunks) {
const name = module.nameForCondition && module.nameForCondition();
return chunks.some(chunk => {
return chunk.name === 'main' && /[\\/]node_modules[\\/]/.test(name);
});
},
},
},
},
},
plugins: [
new webpack.NamedModulesPlugin(),
new webpack.HotModuleReplacementPlugin(),
new TransferWebpackPlugin([
{ from: 'client' },
], path.resolve(__dirname, 'src')),
new webpack.LoaderOptionsPlugin({
debug: true,
options: {
stylus: {
use: [nib(), rupture()],
import: [
'~nib/lib/nib/index.styl',
'~rupture/rupture/index.styl',
],
},
},
}),
new ExtractTextPlugin('[name].css', { allChunks: true }),
new CompressionPlugin({
test: /\.js$|\.css$/,
filename: '[path].gz'
}),
// new BundleAnalyzerPlugin(),
],
}