small medium large xlarge

Dmfcb_pragsmall
10 Apr 2017, 18:25
David Copeland (467 posts)

It looks like the book is missing the instruction to add Webpacker to your Gemfile. The hope is that for Rails 5.1 you won’t need this, but for now, add this to Gemfile

gem "webpacker" github: "rails/rails"

And then do bundle install. Then, rails webpacker:install should work.

Generic-user-small
17 Apr 2017, 21:22
Patrick Langford (1 post)

I had to add this to my Gemfile to get webpacker installed and working:

gem ‘webpacker’, github: ‘rails/webpacker’

Also, the webpacker configuration was different. Loaders were in their own directory.

Generic-user-small
18 Apr 2017, 12:40
steve fox (9 posts)

my webpack/shared.js looks nothing like the example to be edited in the book (p.13). Is this related?

I added webpacker to my Gemfile and ran

bundle exec rails webpacker:install

shared.js:

// Note: You must restart bin/webpack-watcher for changes to take effect
/* eslint global-require: 0 */
/* eslint import/no-dynamic-require: 0 */

const webpack = require('webpack')
const { basename, join, resolve } = require('path')
const { sync } = require('glob')
const { readdirSync } = require('fs')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const ManifestPlugin = require('webpack-manifest-plugin')
const extname = require('path-complete-extname')
const { env, paths, publicPath, loadersDir } = require('./configuration.js')

const extensionGlob = `*{${paths.extensions.join(',')}}*`
const packPaths = sync(join(paths.source, paths.entry, extensionGlob))

module.exports = {
  entry: packPaths.reduce(
    (map, entry) => {
      const localMap = map
      localMap[basename(entry, extname(entry))] = resolve(entry)
      return localMap
    }, {}
  ),

  output: { filename: '[name].js', path: resolve(paths.output, paths.entry) },

  module: {
    rules: readdirSync(loadersDir).map(file => (
      require(join(loadersDir, file))
    ))
  },

  plugins: [
    new webpack.EnvironmentPlugin(JSON.parse(JSON.stringify(env))),
    new ExtractTextPlugin(env.NODE_ENV === 'production' ? '[name]-[hash].css' : '[name].css'),
    new ManifestPlugin({ fileName: 'manifest.json', publicPath, writeToFileEmit: true })
  ],

  resolve: {
    extensions: paths.extensions,
    modules: [
      resolve(paths.source),
      resolve(paths.node_modules)
    ]
  },

  resolveLoader: {
    modules: [paths.node_modules]
  }
}

Thanks.

Dmfcb_pragsmall
18 Apr 2017, 12:59
David Copeland (467 posts)

Yes, they changed webpacker after the latest beta. Since Webpacker is under active development, things are going to be messy until they release it, which is hopefully soon!

Generic-user-small
18 Apr 2017, 13:45
steve fox (9 posts)

okay, thanks.

I’ll just copy the code from the link provided in the book.

Generic-user-small
18 Apr 2017, 15:10
steve fox (9 posts)

ok. I the code for shared.js from the link to the code

https://media.pragprog.com/titles/dcbang2/code/setup/install-webpack/shine/config/webpack/shared.js

and I get this configuration file not found. Foreman start works with the shared.js as is, but it doesn’t read app/javascript/packs/application.*

$ foreman start
10:06:58 rails.1   | started with pid 28417
10:06:58 webpack.1 | started with pid 28418
10:06:59 webpack.1 | Configuration file found but no entry configured.
10:06:59 webpack.1 | Use --help to display the CLI options.
10:06:59 webpack.1 | exited with code 255
10:06:59 system    | sending SIGTERM to all processes
10:06:59 rails.1   | terminated by SIGTERM

This is rails 5.1 rc1

Steve

You must be logged in to comment