forked from shakacode/react-webpack-rails-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.client.rails.build.config.js
123 lines (113 loc) · 3.19 KB
/
webpack.client.rails.build.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
/* eslint comma-dangle: ["error",
{"functions": "never", "arrays": "only-multiline", "objects": "only-multiline"} ] */
// Run like this:
// cd client && yarn run build:client
// Note that Foreman (Procfile.dev) has also been configured to take care of this.
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const merge = require('webpack-merge');
const config = require('./webpack.client.base.config');
const { resolve } = require('path');
const webpackConfigLoader = require('react-on-rails/webpackConfigLoader');
const configPath = resolve('..', 'config');
const { output } = webpackConfigLoader(configPath);
const devBuild = process.env.NODE_ENV !== 'production';
if (devBuild) {
console.log('Webpack dev build for Rails'); // eslint-disable-line no-console
config.devtool = 'eval-source-map';
} else {
console.log('Webpack production build for Rails'); // eslint-disable-line no-console
}
module.exports = merge(config, {
// You can add entry points specific to rails here
entry: {
'vendor-bundle': [
'jquery-ujs',
// Configures extractStyles to be true if NODE_ENV is production
'bootstrap-loader/extractStyles'
],
},
output: {
filename: '[name]-[chunkhash].js',
chunkFilename: '[name]-[chunkhash].chunk.js',
publicPath: output.publicPath,
path: output.path,
},
// See webpack.client.base.config for adding modules common to both webpack dev server and rails
module: {
rules: [
{
test: /\.jsx?$/,
use: 'babel-loader',
exclude: /node_modules/,
},
{
test: /\.css$/,
loader: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader',
options: {
minimize: true,
modules: true,
importLoaders: 1,
localIdentName: '[name]__[local]__[hash:base64:5]',
},
},
'postcss-loader',
],
}),
},
{
test: /\.scss$/,
loader: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader',
options: {
minimize: true,
modules: true,
importLoaders: 3,
localIdentName: '[name]__[local]__[hash:base64:5]',
},
},
'postcss-loader',
'sass-loader',
{
loader: 'sass-resources-loader',
options: {
resources: './app/assets/styles/app-variables.scss'
},
}
],
}),
},
{
test: require.resolve('react'),
use: {
loader: 'imports-loader',
options: {
shim: 'es5-shim/es5-shim',
sham: 'es5-shim/es5-sham',
}
}
},
{
test: require.resolve('jquery-ujs'),
use: {
loader: 'imports-loader',
options: {
jQuery: 'jquery',
}
}
}
],
},
plugins: [
new ExtractTextPlugin({
filename: '[name]-[hash].css',
allChunks: true
}),
],
});