forked from shakacode/react-webpack-rails-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.rails.config.js
42 lines (32 loc) · 1.45 KB
/
webpack.rails.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
// Run like this:
// cd client && $(npm bin)/webpack -w --config webpack.rails.config.js
// Note that Foreman (Procfile.dev) has also been configured to take care of this.
// NOTE: All style sheets handled by the asset pipeline in rails
'use strict';
var config = require('./webpack.common.config');
config.output = {
filename: 'client-bundle.js',
path: '../app/assets/javascripts/generated'
};
// load jQuery from cdn or rails asset pipeline
config.externals = {jquery: 'var jQuery'};
// You can add entry points specific to rails here
config.entry.push('./scripts/rails_only');
// See webpack.common.config for adding modules common to both the webpack dev server and rails
config.module.loaders.push(
{test: /\.jsx$/, exclude: /node_modules/, loader: 'babel-loader'},
{test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader'},
// Next 2 lines expose jQuery and $ to any JavaScript files loaded after client-bundle.js
// in the Rails Asset Pipeline. Thus, load this one prior.
{test: require.resolve('jquery'), loader: 'expose?jQuery'},
{test: require.resolve('jquery'), loader: 'expose?$'}
);
module.exports = config;
// Next line is Heroku specific. You'll have BUILDPACK_URL defined for your Heroku install.
var devBuild = (typeof process.env.BUILDPACK_URL) === 'undefined';
if (devBuild) {
console.log('Webpack dev build for Rails');
module.exports.devtool = 'eval-source-map';
} else {
console.log('Webpack production build for Rails');
}