This repository has been archived by the owner on Apr 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathwebpack.config.js
121 lines (116 loc) · 2.68 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
const webpack = require('webpack')
const path = require('path')
const HappyPack = require('happypack')
const nodeEnv = process.env.NODE_ENV || 'development'
const isProd = nodeEnv === 'production'
var config = {
devtool: isProd ? 'source-map' : 'cheap-eval-source-map',
context: path.join(__dirname, './app'),
entry: {
common: [
'babel-polyfill',
'highlight.js/lib/highlight',
'highlight.js/lib/languages/javascript',
'highlight.js/lib/languages/bash',
'./components/tags/highlight.js',
'./index.js'
]
},
output: {
path: path.join(__dirname, './static'),
publicPath: '/',
filename: '[name].bundle.js',
chunkFilename: '[name].bundle.js'
},
module: {
rules: [
{
test: /\.html$/,
loader: 'file-loader',
query: {
name: '[name].[ext]'
}
},
{
test: /\.s?css$/,
loaders: [
'style-loader',
'css-loader',
{
loader: 'postcss-loader',
options: {
ident: 'postcss',
plugins: () => [require('autoprefixer'), require('precss')]
}
}
]
},
{
test: /\.(js|jsx)$/,
loader: 'happypack/loader',
exclude: /node_modules/
},
{
test: /\.(png|jpg|svg|gif)$/,
// inline base64 URLs for <=8k images, direct URLs for the rest
loader: 'url-loader?limit=8192'
}
]
},
resolve: {
extensions: ['.js', '.jsx'],
modules: [
path.resolve('./app'),
'node_modules'
],
alias: {
'~': path.join(__dirname, './app')
}
},
resolveLoader: {
modules: [
path.join(__dirname, 'node_modules')
]
},
plugins: [
new HappyPack({
loaders: [ 'babel-loader?cacheDirectory' ],
threads: 4
}),
new webpack.ContextReplacementPlugin(
/highlight\.js\/lib\/languages$/,
new RegExp(`^./(${['javascript', 'bash'].join('|')})$`),
),
new webpack.optimize.CommonsChunkPlugin({
name: 'common',
minChunks: 2,
filename: 'common.bundle.js'
}),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
},
output: {
comments: false
},
sourceMap: false
}),
new webpack.DefinePlugin({
'process.env': { NODE_ENV: JSON.stringify(nodeEnv) }
})
].concat(isProd ? [] : [
new webpack.NamedModulesPlugin()
]),
devServer: {
contentBase: './app'
}
}
// development mode
if (!isProd) {
Object.keys(config.entry).forEach(function (k) {
config.entry[k].unshift(
'webpack-dev-server/client?http://0.0.0.0:2000'
)
})
}
module.exports = config