forked from coopcycle/coopcycle-web
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
105 lines (100 loc) · 3.1 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
var webpack = require("webpack");
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var WebpackAssetsManifest = require('webpack-assets-manifest');
var CopyWebpackPlugin = require('copy-webpack-plugin');
var CommonChunkPlugin = require('webpack/lib/optimize/CommonsChunkPlugin');
if (process.env.NODE_ENV === 'production') {
var jsFilename = "[name].[chunkhash].js",
cssFilename = "[name].[contenthash].css";
}
else {
var jsFilename = "[name].js",
cssFilename = "[name].css";
}
var webpackConfig = {
entry: {
'css/styles': './assets/css/main.scss',
'css/tracking': './assets/css/tracking.scss',
'js/address-form': './js/app/address/form.jsx',
'js/common': ['bootstrap'],
'js/homepage': './js/app/homepage/index.js',
'js/restaurant-list': './js/app/restaurant-list/index.jsx',
'js/cart': './js/app/cart/index.jsx',
'js/order': './js/app/order/index.jsx',
'js/order-payment': './js/app/order/payment.js',
'js/order-tracking': [ 'whatwg-fetch', './js/app/order/tracking.jsx' ],
'js/profile-deliveries': './js/app/profile/deliveries.js',
'js/delivery-form': './js/app/delivery/form.jsx',
'js/restaurant-form': './js/app/restaurant/form.jsx',
'js/restaurant-menu': './js/app/restaurant/menu.jsx',
'js/restaurant-panel': './js/app/restaurant/panel.jsx',
'js/restaurants-map': './js/app/restaurants-map/index.jsx',
'js/tracking': './js/app/tracking/index.jsx',
},
output: {
publicPath: "/",
path: __dirname + '/web',
filename: jsFilename
},
resolve: {
alias: {
jquery: "jquery/src/jquery"
}
},
module: {
loaders: [
{
test: /\.scss$/,
loader: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: ['css-loader', 'sass-loader']
})
},
{
test: /\.css$/,
loader: ExtractTextPlugin.extract({ fallback: 'style-loader', use: 'css-loader' })
},
{
test: /\.(eot|ttf|woff|woff2)$/,
loader: 'file-loader?name=css/fonts/[name].[ext]'
},
{
test: /\.(svg|png)$/,
loader: 'file-loader?name=css/images/[name].[ext]'
},
{
test: /\.jsx?/,
include: __dirname + '/js',
loader: "babel-loader"
}
]
},
// Use the plugin to specify the resulting filename (and add needed behavior to the compiler)
plugins: [
new ExtractTextPlugin({filename: cssFilename, allChunks: true}),
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
}),
new CopyWebpackPlugin([
{ from: 'node_modules/coopcycle-js/build/coopcycle.js', to: 'js/coopcycle.js' }
]),
new CommonChunkPlugin({
name: 'js/common',
minChunks: 3,
filename: jsFilename
})
],
devServer: {
headers: { "Access-Control-Allow-Origin": "*" },
contentBase: __dirname + '/web',
stats: 'minimal',
compress: true,
}
};
if (process.env.NODE_ENV === 'production') {
webpackConfig.plugins.push(new WebpackAssetsManifest({
writeToDisk: true
}));
}
module.exports = webpackConfig;