Skip to content

Commit c8172ea

Browse files
committedDec 1, 2014
Add bootstrap-sass gem; Use bootstrap-sass loader with local webpack dev server
1 parent 8b44d97 commit c8172ea

14 files changed

+116
-37
lines changed
 

‎Gemfile

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ gem 'rails_12factor'
1212

1313
# Use SCSS for stylesheets
1414
gem 'sass-rails', '~> 5.0.0.beta1'
15+
gem 'bootstrap-sass', '~> 3.3.1'
1516
# Use Uglifier as compressor for JavaScript assets
1617
gem 'uglifier', '>= 1.3.0'
1718
# Use CoffeeScript for .js.coffee assets and views
@@ -37,6 +38,8 @@ gem 'rails-html-sanitizer', '~> 1.0'
3738
# Use Unicorn as the app server
3839
gem 'unicorn'
3940

41+
gem 'autoprefixer-rails'
42+
4043
# Use Capistrano for deployment
4144
# gem 'capistrano-rails', group: :development
4245

@@ -53,5 +56,3 @@ group :development, :test do
5356
# Manage application processes
5457
gem 'foreman'
5558
end
56-
57-
gem 'autoprefixer-rails'

‎Gemfile.lock

+3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ GEM
3939
execjs
4040
binding_of_caller (0.7.3.pre1)
4141
debug_inspector (>= 0.0.1)
42+
bootstrap-sass (3.3.1.0)
43+
sass (~> 3.2)
4244
builder (3.2.2)
4345
byebug (3.2.0)
4446
columnize (~> 0.8)
@@ -163,6 +165,7 @@ PLATFORMS
163165

164166
DEPENDENCIES
165167
autoprefixer-rails
168+
bootstrap-sass (~> 3.3.1)
166169
byebug
167170
coffee-rails (~> 4.0.0)
168171
foreman

‎README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ Setup node and run the node server.
2929

3030
```
3131
npm install
32-
cd webpack && webpack --config webpack.hot.config.js
33-
node server.js
32+
cd webpack && node server.js
3433
```
3534

3635
Point browser to [http://0.0.0.0:3000]().
+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
@import "../../../webpack/assets/stylesheets/test-stylesheet";
22
@import "../../../webpack/assets/stylesheets/test-sass-stylesheet";
3-
@import "bootstrap-and-customizations";
3+
@import "bootstrap-sprockets";
4+
@import "bootstrap";

‎webpack/_bootstrap-customizations.scss

-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@ $pre-border-color: $pre-bg; // hide the border.
77

88
// This makes the font on the buttons and the text BIG
99
$font-size-base: 18px;
10-

‎webpack/assets/javascripts/CommentBox.jsx

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ module React from 'react/addons';
77
// the React Developer Tools: http://facebook.github.io/react/blog/2014/01/02/react-chrome-developer-tools.html
88
// require("expose?React!react");
99

10-
1110
var Input = require('react-bootstrap/Input');
1211
var Button = require('react-bootstrap/Button');
1312
var Row = require('react-bootstrap/Row');

‎webpack/bootstrap-sass.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ module.exports = {
1212
'transition': true,
1313
'alert': true,
1414
'button': true,
15-
'carousel': true,
15+
'carousel': false,
1616
'collapse': true,
1717
'dropdown': true,
18-
'modal': true,
18+
'modal': false,
1919
'tooltip': true,
2020
'popover': true,
2121
'scrollspy': true,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
//var ExtractTextPlugin = require("extract-text-webpack-plugin");
2+
3+
module.exports = {
4+
bootstrapCustomizations: "./_bootstrap-customizations.scss",
5+
mainSass: "./_main.scss",
6+
7+
// Default for the style loading is to put in your js files
8+
// styleLoader: "style-loader!css-loader!sass-loader";
9+
// styleLoader: ExtractTextPlugin.extract("style-loader", "css-loader"),
10+
11+
// ### Scripts
12+
// Any scripts here set to false will never make it to the client,
13+
// i.e. it's not packaged by webpack.
14+
scripts: {
15+
'transition': true,
16+
'alert': true,
17+
'button': true,
18+
'carousel': true,
19+
'collapse': true,
20+
'dropdown': true,
21+
'modal': false,
22+
'tooltip': true,
23+
'popover': true,
24+
'scrollspy': true,
25+
'tab': true,
26+
'affix': true
27+
},
28+
// ### Styles
29+
// Enable or disable certain less components and thus remove
30+
// the css for them from the build.
31+
styles: {
32+
"mixins": true,
33+
34+
"normalize": true,
35+
"print": true,
36+
37+
"scaffolding": true,
38+
"type": true,
39+
"code": true,
40+
"grid": true,
41+
"tables": true,
42+
"forms": true,
43+
"buttons": true,
44+
45+
"component-animations": true,
46+
"glyphicons": true,
47+
"dropdowns": true,
48+
"button-groups": true,
49+
"input-groups": true,
50+
"navs": true,
51+
"navbar": true,
52+
"breadcrumbs": true,
53+
"pagination": true,
54+
"pager": true,
55+
"labels": true,
56+
"badges": true,
57+
"jumbotron": true,
58+
"thumbnails": true,
59+
"alerts": true,
60+
"progress-bars": true,
61+
"media": true,
62+
"list-group": true,
63+
"panels": true,
64+
"wells": true,
65+
"close": true,
66+
67+
"modals": true,
68+
"tooltip": true,
69+
"popovers": true,
70+
"carousel": true,
71+
72+
"utilities": true,
73+
"responsive-utilities": true
74+
}
75+
};

‎webpack/scripts/rails_only.jsx

-2
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,3 @@
44
// Showing this for example purposes
55
// require("expose?$!jquery");
66
// require("expose?jQuery!jquery");
7-
8-

‎webpack/scripts/webpack_only.jsx

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
// These are only loaded by only by the webpack server
1+
// These are only loaded by the webpack dev server
22

3-
// Option to load stylesheets via webpack
43
require("test-stylesheet.css");
5-
6-
// Test out sass
7-
require("test-sass-stylesheet.scss");
4+
require("test-sass-stylesheet.scss"); // test out sass
85

96
require("expose?$!jquery");
107
require("expose?jQuery!jquery");
11-
require("bootstrap-webpack");

‎webpack/server.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ var comments = [{author: 'Pete Hunt', text: 'Hey there!'},
88
{author: 'Justin Gordon', text: 'Aloha from @railsonmaui'}];
99

1010
var server = new WebpackDevServer(webpack(config), {
11+
//contentBase: "/public",
1112
publicPath: config.output.publicPath,
1213
hot: true,
13-
stats: { colors: true}
14+
stats: {colors: true}
1415
});
1516

1617
server.app.use(bodyParser.json());
@@ -31,7 +32,7 @@ server.app.post('/comments.json', function(req, res) {
3132
res.send(JSON.stringify(comments));
3233
});
3334

34-
server.listen(3000, 'localhost', function (err, result) {
35+
server.listen(3000, 'localhost', function(err, result) {
3536
if (err) { console.log(err); }
36-
console.log('Listening at localhost:3000');
37+
console.log('Listening at localhost:3000...');
3738
});

‎webpack/webpack.common.config.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ module.exports = {
1111
// jquery: "var jQuery"
1212
// },
1313
resolve: {
14-
root: [path.join(__dirname, "scripts"), path.join(__dirname, "assets/javascripts"),
14+
root: [path.join(__dirname, "scripts"),
15+
path.join(__dirname, "assets/javascripts"),
1516
path.join(__dirname, "assets/stylesheets")],
1617
extensions: ["", ".webpack.js", ".web.js", ".js", ".jsx", ".scss", ".css", "config.js"]
1718
},
@@ -22,8 +23,7 @@ module.exports = {
2223
{ test: /\.css$/, loader: "style-loader!css-loader" },
2324
{ test: /\.scss$/, loader: "style!css!sass?outputStyle=expanded&imagePath=/assets/images"},
2425

25-
// the url-loader uses DataUrls.
26-
// the file-loader emits files.
26+
// The url-loader uses DataUrls. The file-loader emits files.
2727
{ test: /\.woff$/, loader: "url-loader?limit=10000&minetype=application/font-woff" },
2828
{ test: /\.ttf$/, loader: "file-loader" },
2929
{ test: /\.eot$/, loader: "file-loader" },

‎webpack/webpack.hot.config.js

+18-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
1+
// Run like this:
2+
// cd webpack && $(npm bin)/webpack -w --config webpack.hot.config.js
3+
// or:
4+
// cd webpack && node server.js
5+
16
var config = require("./webpack.common.config");
27
var webpack = require("webpack");
8+
//var ExtractTextPlugin = require("extract-text-webpack-plugin");
39

10+
// Add the following entries as appropriate:
11+
// "bootstrap-sass-loader" -> all bootstrap assets
12+
// "bootstrap-sass!./bootstrap-sass.config.js" -> custom bootstrap
13+
// "bootstrap-sass!./bootstrap-sass.extract-text.config.js" -> custom bootstrap w/ ExtractTextPlugin
414
config.entry.push("webpack-dev-server/client?http://localhost:3000",
515
"webpack/hot/dev-server",
6-
"./scripts/webpack_only");
7-
config.output = { filename: "express-bundle.js", // this file is never saved on disk
16+
"./scripts/webpack_only",
17+
"bootstrap-sass!./bootstrap-sass.config.js");
18+
//"bootstrap-sass!./bootstrap-sass.extract-text.config.js");
19+
config.output = { filename: "express-bundle.js", // this file is served directly by webpack
820
path: __dirname };
21+
//config.module.loaders.push(
22+
// { test: /\.css$/, loader: ExtractTextPlugin.extract("style-loader", "css-loader") }
23+
//);
924
config.plugins = [ new webpack.HotModuleReplacementPlugin() ];
25+
//new ExtractTextPlugin("bootstrap-and-customizations.css") ];
1026
module.exports = config;

‎webpack/webpack.rails.config.js

+3-12
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
1-
// Run like this
2-
// cd webpack && $(npm bin)/webpack -w --config webpack.rails.config.js
1+
// Run like this:
2+
// cd webpack && $(npm bin)/webpack -w --config webpack.hot.config.js
33

44
var config = require("./webpack.common.config");
5-
var path = require("path");
65

7-
// Add the following entries as appropriate:
8-
// "./scripts/rails_only" --> rails specific assets
9-
// "bootstrap-sass-loader" --> all bootstrap assets
10-
// "bootstrap-sass!./bootstrap-sass.config.js" --> custom bootstrap
11-
config.entry.push("./assets/javascripts/example",
12-
"bootstrap-sass!./bootstrap-sass.config.js");
6+
config.entry.push("./scripts/rails_only"); // rails specific assets
137
config.output = { filename: "rails-bundle.js",
148
path: "../app/assets/javascripts" };
159
config.externals = { jquery: "var jQuery" }; // load jQuery from cdn or rails asset pipeline
1610
config.module.loaders.push(
17-
// **IMPORTANT** This is needed so that each bootstrap js file required by
18-
// bootstrap-sass-loader has access to the jQuery object
19-
{ test: /bootstrap-sass\/assets\/javascripts\//, loader: "imports?jQuery=jquery" },
2011
{ test: /\.scss$/, loader: "style!css!sass?outputStyle=expanded&imagePath=/assets/images"},
2112
// Next 2 lines expose jQuery and $ to any JavaScript files loaded after rails-bundle.js
2213
// in the Rails Asset Pipeline. Thus, load this one prior.

0 commit comments

Comments
 (0)
Please sign in to comment.