-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathwebpack.config.js
146 lines (142 loc) · 3.56 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
const __STATIC_ASSETS_BASE_PATH__ = 'assets';
const path = require('path');
const isDev = require('isdev');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const MinifyPlugin = require('babel-minify-webpack-plugin');
const { optimize } = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const extractCSS = new ExtractTextPlugin({
filename: '[name].css?[contenthash]',
allChunks: true,
});
const extractSASS = new ExtractTextPlugin({
filename: '[name].css?[contenthash]',
allChunks: true,
});
const config = {
entry: {
vendor: './src/AppBundle/Resources/public/js/vendor.js',
main: './src/AppBundle/Resources/public/js/main.js',
'application-form': './src/AppBundle/Resources/public/js/application-form.js',
'build-form': './src/AppBundle/Resources/public/js/build-form.js',
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'web/'+__STATIC_ASSETS_BASE_PATH__),
publicPath: '/'+__STATIC_ASSETS_BASE_PATH__+'/',
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
},
},
{
test: /\.css$/,
use: extractCSS.extract({
fallback: {
loader: 'style-loader',
},
use: [
{
loader: 'css-loader',
},
],
}),
},
{
test: /\.scss$/,
use: extractSASS.extract({
fallback: {
loader: 'style-loader',
},
use: [
{
loader: 'css-loader',
},
{
loader: 'sass-loader',
},
],
}),
},
{
test: /\.(png|gif|jpg|svg|woff2?|ttf|eot)$/,
use: [
'url-loader?limit=10000',
],
},
],
},
plugins: [
new CopyWebpackPlugin([
{
from: './src/AppBundle/Resources/public/img',
to: 'img',
},
{
from: './src/AppBundle/Resources/public/favicons',
transform: function (content) {
return content.toString().replace(/__STATIC_ASSETS_BASE_PATH__/g, __STATIC_ASSETS_BASE_PATH__);
},
to: 'favicons',
},
{
from: './node_modules/jquery/dist/jquery.min.js',
to: 'jquery.js',
},
{
from: './vendor/friendsofsymfony/jsrouting-bundle/Resources/public/js/router.js',
to: 'fos-js-routing.js',
},
{
from: './vendor/willdurand/js-translation-bundle/Resources/public/js/translator.min.js',
to: 'bazinga-translator.js',
},
]),
new optimize.CommonsChunkPlugin({ name: 'common', filename: 'common.js' }),
extractCSS,
extractSASS,
],
externals: {
jquery: 'jQuery',
'fos-js-routing': 'Routing',
'bazinga-translator': 'Translator',
},
resolve: {
modules: [
path.resolve(__dirname, 'node_modules'),
],
},
devtool: isDev ? 'cheap-module-eval-source-map' : false,
devServer: {
host: '0.0.0.0',
disableHostCheck: true,
},
};
if (isDev) {
config.module.rules.push({
enforce: 'pre',
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'eslint-loader',
},
});
config.module.rules.push({
enforce: 'pre',
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'source-map-loader',
},
});
} else {
config.plugins.push(
new MinifyPlugin({ mangle: false/* <- to fix Safari issue, hope this will be fixed in a newer version than 0.2.0 */ })
);
}
module.exports = config;