forked from shakacode/react-webpack-rails-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.rails.config.js
More file actions
67 lines (62 loc) · 2.45 KB
/
webpack.rails.config.js
File metadata and controls
67 lines (62 loc) · 2.45 KB
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
// Run like this
// cd webpack && webpack -w --config webpack.rails.config.js
var path = require("path");
var railsBundleFile = "rails-bundle.js";
var railsJsAssetsDir = "../app/assets/javascripts";
var railsBundleMapFile = railsBundleFile + ".map";
var railsBundleMapRelativePath = "../../../public/assets/" + railsBundleMapFile;
module.exports = {
context: __dirname,
entry: [
// to expose something Rails specific, uncomment the next line
//"./scripts/rails_only",
"./assets/javascripts/example",
// Alternative for including everything with no customization
'bootstrap-sass-loader'
//
// Example of using customization file
//'bootstrap-sass!./bootstrap-sass.config.js'
//
// Example of using customization file with ExtractTextPlugin
//"bootstrap-sass!./bootstrap-sass.extract-text-plugin.config.js"
],
output: {
filename: railsBundleFile,
path: railsJsAssetsDir
},
// Let's load jQuery from the CDN or rails asset pipeline
externals: {
jquery: "var jQuery"
},
resolve: {
root: [ path.join(__dirname, "scripts"), path.join(__dirname, "assets/javascripts")],
extensions: ["", ".js", ".jsx"]
},
module: {
loaders: [
// **IMPORTANT** This is needed so that each bootstrap js file required by
// bootstrap-sass-loader has access to the jQuery object
{ test: /bootstrap-sass\/assets\/javascripts\//, loader: 'imports?jQuery=jquery' },
{ test: /\.scss$/, loader: "style!css!sass?outputStyle=expanded&imagePath=/assets/images"},
{ test: /\.woff$/, loader: "url-loader?limit=10000&minetype=application/font-woff" },
{ test: /\.ttf$/, loader: "file-loader" },
{ test: /\.eot$/, loader: "file-loader" },
{ test: /\.svg$/, loader: "file-loader" },
{ test: /\.jsx$/, loaders: ['es6', 'jsx?harmony'] },
// Next 2 lines expose jQuery and $ to any JavaScript files loaded after rails-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?$" }
]
}
};
var devBuild = (typeof process.env["BUILDPACK_URL"]) === "undefined";
if (devBuild) {
console.log("Webpack dev build for rails");
module.exports.devtool = "eval-source-map";
module.exports.module.loaders.push(
{ test: require.resolve("react"), loader: "expose?React" }
);
} else {
console.log("Webpack production build for rails");
}