-
Notifications
You must be signed in to change notification settings - Fork 45
/
webpack.config.js
117 lines (114 loc) · 2.59 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
const webpack = require('webpack')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const CleanWebpackPlugin = require('clean-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const ManifestPlugin = require('webpack-manifest-plugin')
const UglifyJSPlugin = require('uglifyjs-webpack-plugin')
const path = require('path')
const isProduction = process.env.NODE_ENV === 'production'
const hash = isProduction ? '.[hash]' : ''
const globals = [
{
test: require.resolve('jquery'),
use: [
{
loader: 'expose-loader',
options: 'jQuery',
},
{
loader: 'expose-loader',
options: '$',
},
],
},
{
test: require.resolve(
'jquery.i18n/libs/CLDRPluralRuleParser/src/CLDRPluralRuleParser'
),
use: [
{
loader: 'expose-loader',
options: 'pluralRuleParser',
},
],
},
]
module.exports = {
entry: './src/js/bootstrap.js',
output: {
path: path.resolve(__dirname, 'out'),
filename: `[name]${hash}.js`,
},
devtool: isProduction ? 'source-map' : 'eval-source-map',
devServer: {
contentBase: './out',
port: 8080,
host: '0.0.0.0',
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['babel-preset-env'],
},
},
},
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader',
options: {
minimize: isProduction,
},
},
{
loader: 'postcss-loader',
options: {
ident: 'postcss',
plugins: () => {
return [require('autoprefixer')()]
},
},
},
],
}),
},
].concat(globals),
},
plugins: [
new CleanWebpackPlugin(['out'], {
exclude: [
'data.json',
'data.min.json',
'data.yml',
'dates.json',
'blog_planet.json',
'index.html',
],
}),
new CopyWebpackPlugin([
{
from: 'static',
to: '.',
},
]),
new ExtractTextPlugin(`[name]${hash}.css`),
new ManifestPlugin(),
].concat(
isProduction
? [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
}),
new UglifyJSPlugin({ sourceMap: true }),
]
: []
),
}