-
Notifications
You must be signed in to change notification settings - Fork 382
/
webpack.rails.config.js
63 lines (59 loc) · 1.89 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// 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: [
// In case we don't require jQuery from CDN or asset pipeline
"./scripts/rails_only",
"./assets/javascripts/example"
],
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"]
},
resolveLoader: {
// todo -- see if this is necessary
root: [path.join(__dirname, "scripts"), path.join(__dirname, "assets/javascripts")],
extensions: ["", ".webpack.js", ".web.js", ".js", ".jsx"]
},
module: {
loaders: [
{ test: /\.jsx$/,
loaders: ['es6', 'jsx?harmony'] }
]
},
};
var devBuild = (typeof process.env["BUILDPACK_URL"]) === "undefined";
if (devBuild) {
console.log("Webpack dev build for rails");
module.exports.devtool = "source-map";
module.exports.module.loaders.push(
{ test: require.resolve("react"), loader: "expose?React" }
);
module.exports.plugins = [
function () {
this.plugin("emit", function (compilation, callback) {
// CRITICAL: This must be a relative path from the railsJsAssetsDir (where gen file goes)
var asset = compilation.assets[railsBundleMapFile];
compilation.assets[railsBundleMapRelativePath] = asset;
delete compilation.assets[railsBundleMapFile];
callback();
});
}
];
} else {
console.log("Webpack production build for rails");
}