Skip to content
This repository has been archived by the owner on Dec 3, 2020. It is now read-only.

Commit

Permalink
feat(generators) Better defaults for generators. Closes #2
Browse files Browse the repository at this point in the history
  • Loading branch information
danott committed Feb 1, 2015
1 parent 2896467 commit 029588b
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 28 deletions.
9 changes: 5 additions & 4 deletions lib/generators/webpack_rails/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ class InstallGenerator < Rails::Generators::Base
source_root File.expand_path('../templates', __FILE__)

def install_everything
copy_file "package.json"
copy_file "webpack.config.js"
copy_file "webpack.precompile.js"
append_to_file ".gitignore", "node_modules"
copy_file 'package.json'
copy_file 'webpack.config.js'
copy_file 'webpack.precompile.js'
copy_file 'application.js', 'app/assets/javascripts/application.js'
append_to_file '.gitignore', 'node_modules'
end
end
end
14 changes: 14 additions & 0 deletions lib/generators/webpack_rails/templates/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Replace default Sprocket's directives with Webpack loaders!
import 'script!imports?this=>window!jquery';
import 'script!jquery_ujs';
import 'script!coffee!turbolinks.js.coffee';

// Basically, if you're importing anything from sprockets, you'll want to use
// the script-loader. While this is possible, it's best to move as many things
// as you can to being managed by npm and Webpack.
//
// Sometimes you may run into Gem provided asset that has deep Sprocket's
// directives. In this scenario, my best advice is to grab the precompiled asset
// from sprockets via http://rails-app.dev/assets/some-asset.js, and copy into
// your vendor folder at vendor/assets/javascripts/some-asset.js, and import it
// using the script-loader.
16 changes: 9 additions & 7 deletions lib/generators/webpack_rails/templates/package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
{
"name": "GeneratedByWebpackRails",
"devDependencies": {
"webpack-dev-server": "^1.6.6"
},
"license": "MIT",
"engines": {
"node": ">= 0.10"
},
"dependencies": {
"6to5-loader": "^3.0.0",
"assets-webpack-plugin": "^0.1.0",
"es6-loader": "^0.2.0",
"jsx-loader": "^0.12.2",
"react": "^0.12.2",
"webpack": "^1.4.14"
"coffee-loader": "^0.7.2",
"coffee-script": "^1.9.0",
"exec-sync": "^0.1.6",
"expose-loader": "^0.6.0",
"imports-loader": "^0.6.3",
"script-loader": "^0.6.1",
"webpack": "^1.5.3",
"webpack-dev-server": "^1.7.0"
}
}
30 changes: 14 additions & 16 deletions lib/generators/webpack_rails/templates/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
// Common webpack configuration used by webpack.hot.config and webpack.bundle.config.

var path = require("path");
var execSync = require("exec-sync");
var path = require('path');
var railsRoot = path.join(__dirname, '.')
var railsAssetPaths = JSON.parse(execSync('rails runner "puts Rails.application.assets.paths.to_json"'))

module.exports = {
context: railsRoot,
entry: {
'application.js': "./app/assets/javascripts/application.js",
'application.js': 'application.js'
},
output: {
filename: "[name]",
path: "./public/webpack"
filename: '[name]',
path: './public/webpack'
},
resolve: {
root: [
path.join(railsRoot, "./app/assets/javascripts"),
path.join(railsRoot, "./vendor/assets/javascripts"),
// If you want to venture into Stylesheets, uncomment these lines
// path.join(railsRoot, "./app/assets/stylesheets"),
// path.join(railsRoot, "./vendor/assets/stylesheets"),
path.join(railsRoot, './app/assets/javascripts'),
path.join(railsRoot, './vendor/assets/javascripts'),
],
// Stylesheets: append ".css", ".scss" to this array
extensions: ["", ".js", ".jsx"]
fallback: railsAssetPaths,
extensions: ['', '.js']
},
module: {
loaders: [
{ test: /\.js$/, loader: "es6" },
{ test: /\.jsx$/, loader: "es6!jsx?harmony" },
{ test: /\.js?$/, exclude: [/node_modules/, /vendor/], loader: '6to5-loader' },
]
},
cache: false,
cache: true,
watchDelay: 0,
devtool: 'source-map',
devServer: {
contentBase: path.join(railsRoot, './public')
},
Expand Down
3 changes: 2 additions & 1 deletion lib/generators/webpack_rails/templates/webpack.precompile.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
var config = require('./webpack.config.js');
var SaveAssetsJson = require('assets-webpack-plugin');

config.output.filename = "[chunkhash]-[name]";
config.output.filename = '[chunkhash]-[name]';

var plugin = new SaveAssetsJson({
path: config.output.path,
filename: 'manifest.json'
});

config.plugins = [plugin];
config.devtool = '';

module.exports = config;

0 comments on commit 029588b

Please sign in to comment.