-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
186 lines (184 loc) · 6.24 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
const path = require('path'),
webpack = require('webpack-cli'),
ExtractTextPlugin = require('extract-text-webpack-plugin'),
nodeModules = path.resolve(__dirname, 'node_modules'),
resources = path.resolve(__dirname, 'src/ExtranetBundle/Resources,src/SiteBundle/Resources'),
config = {
cache: true,
entry: {
extranet: [
'./src/ExtranetBundle/Resources/assets/app.js',
],
site: [
'./src/SiteBundle/Resources/assets/app.js',
],
},
output: {
library: '[name]', // assets build
libraryTarget: 'umd',
path: path.join(__dirname, 'web/compiled'),
filename: '[name].js',
chunkFilename: '[name]-[chunkhash].js'
},
module: {
rules: [{
// required for es6
test: /\.js$/,
exclude: file => (
/node_modules/.test(file)
),
use: {
loader: 'babel-loader',
options: {
presets: ['env']
}
}
},
{
// required to write 'require('./style.scss')'
test: /\.s(a|c)ss$/,
exclude: /node_modules/, // Ignore the folder containing 3rd party scripts
loader: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader',
options: {
importLoaders: 1,
sourceMap: true
}
}, {
loader: 'postcss-loader',
options: {
sourceMap: true,
plugins: []
}
}, {
loader: 'sass-loader',
options: {
includePaths: [
path.resolve(resources , '/assets/'),
nodeModules
],
sourceMap: true
}
},
]
})
}, {
// required to write 'require('./style.css')'
test: /\.css$/,
loader: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader',
options: {
importLoaders: 1
}
},
'postcss-loader'
]
})
}, {
// required for bootstrap icons
test: /\.woff2?(\?v=\d+\.\d+\.\d+)?$/,
loader: 'url-loader',
options: {
prefix: 'font/',
limit: 5000,
mimetype: 'application/font-woff'
}
}, {
test: /\.(ttf|eot|svg|otf)(\?v=\d+\.\d+\.\d+)?$/,
loader: 'file-loader',
options: {
prefix: 'font/'
}
}, {
// required to support images
test: /\.(jpe?g|png|gif|svg)$/i,
use: [
{
loader: 'file-loader',
options: {
hash: 'sha512',
digest: 'hex',
name: '[hash].[ext]'
}
},
{
loader: 'image-webpack-loader',
options: {
includePaths: [
path.resolve(resources , '/public/'),
],
gifsicle: {
interlaced: false
},
bypassOnDebug: true,
optipng: {
optimizationLevel: 7
}
}
}
]
}, {
// Expose jQuery
test: require.resolve('jquery'),
use: [
{
loader: 'expose-loader?jQuery'
}, {
loader: 'expose-loader?$'
}
]
}]
},
// devtool: 'cheap-module-eval-source-map',
devtool: 'source-map',
plugins: [
new webpack.optimize.CommonsChunkPlugin({
name: 'common',
filename: 'common.js',
chunks: ['extranet'],
}),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(process.env.NODE_ENV)
}
}),
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery',
}),
new webpack.NoEmitOnErrorsPlugin(),
// Use the plugin to specify the resulting filename (and add needed behavior to the compiler)
new ExtractTextPlugin({
filename: '[name].css',
allChunks: true
})
],
externals: {
translator: 'Translator',
routing: 'Routing',
}
}
if ('production' === process.env.NODE_ENV) {
config.devtool= false
config.plugins.push(
new webpack.LoaderOptionsPlugin({
minimize: true
}),
// optimize module ids by occurrence count
new webpack.optimize.OccurrenceOrderPlugin()
)
} else {
config.plugins.push(
new webpack.LoaderOptionsPlugin({
debug: true
}),
)
}
module.exports = config