forked from shakacode/react-webpack-rails-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.client.base.config.js
86 lines (68 loc) · 2.63 KB
/
webpack.client.base.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
// Common client-side webpack configuration used by webpack.hot.config and webpack.rails.config.
const webpack = require('webpack');
const path = require('path');
const autoprefixer = require('autoprefixer');
const devBuild = process.env.NODE_ENV !== 'production';
const nodeEnv = devBuild ? 'development' : 'production';
module.exports = {
// the project dir
context: __dirname,
entry: {
// See use of 'vendor' in the CommonsChunkPlugin inclusion below.
vendor: [
'babel-polyfill',
'jquery',
],
// This will contain the app entry points defined by webpack.hot.config and webpack.rails.config
app: [
'./app/bundles/comments/startup/clientRegistration',
],
},
resolve: {
extensions: ['', '.js', '.jsx'],
alias: {
libs: path.join(process.cwd(), 'app', 'libs'),
react: path.resolve('./node_modules/react'),
'react-dom': path.resolve('./node_modules/react-dom'),
},
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(nodeEnv),
},
TRACE_TURBOLINKS: devBuild,
}),
// https://webpack.github.io/docs/list-of-plugins.html#2-explicit-vendor-chunk
new webpack.optimize.CommonsChunkPlugin({
// This name 'vendor' ties into the entry definition
name: 'vendor',
// We don't want the default vendor.js name
filename: 'vendor-bundle.js',
// Passing Infinity just creates the commons chunk, but moves no modules into it.
// In other words, we only put what's in the vendor entry definition in vendor-bundle.js
minChunks: Infinity,
}),
],
module: {
loaders: [
{ test: /\.(woff2?|svg)$/, loader: 'url?limit=10000' },
{ test: /\.(ttf|eot)$/, loader: 'file' },
{ test: /\.(jpe?g|png|gif|svg|ico)$/, loader: 'url?limit=10000' },
{ test: require.resolve('jquery'), loader: 'expose?jQuery' },
{ test: require.resolve('jquery'), loader: 'expose?$' },
// Use one of these to serve jQuery for Bootstrap scripts:
// Bootstrap 3
{ test: /bootstrap-sass\/assets\/javascripts\//, loader: 'imports?jQuery=jquery' },
// Bootstrap 4
{ test: /bootstrap\/dist\/js\/umd\//, loader: 'imports?jQuery=jquery' },
],
},
// Place here all postCSS plugins here, so postcss-loader will apply them
postcss: [autoprefixer],
// Place here all SASS files with variables, mixins etc.
// And sass-resources-loader will load them in every CSS Module (SASS file) for you
// (so don't need to @import them explicitly)
// https://github.com/shakacode/sass-resources-loader
sassResources: ['./app/assets/styles/app-variables.scss'],
};