From 64b60e9ba2d135399797739c0bd0c054de4f619d Mon Sep 17 00:00:00 2001 From: Daniel Leavitt Date: Sat, 25 Feb 2017 15:28:59 -0800 Subject: [PATCH] put everything under dist when output --- README.md | 2 +- lib/install/bin/webpack-dev-server.tt | 2 +- lib/install/config/development.js | 4 +++- lib/install/config/shared.js | 10 +++++++--- lib/install/template.rb | 2 +- lib/webpacker/helper.rb | 4 ++-- lib/webpacker/railtie.rb | 2 +- lib/webpacker/source.rb | 4 ++-- 8 files changed, 18 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index cdded3996..b68810cd9 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ If you'd rather not have to run the two processes separately by hand, you can us Alternatively, you can run `./bin/webpack-dev-server`. This will launch a [Webpack Dev Server](https://webpack.github.io/docs/webpack-dev-server.html) listening on http://localhost:8080/ serving your pack files. It will recompile your files as you make changes. You also need to set -`config.x.webpacker[:dev_server_host]` in your `config/environments/development.rb` to tell Webpacker to load +`config.x.webpacker[:dev_server_host]` in your `config/environments/development.rb` and uncomment the `output.publicPath` line in your `config/webpack/development.js` to tell Webpacker to load your packs from the Webpack Dev Server. This setup allows you to leverage advanced Webpack features, such as [Hot Module Replacement](https://webpack.github.io/docs/hot-module-replacement-with-webpack.html). diff --git a/lib/install/bin/webpack-dev-server.tt b/lib/install/bin/webpack-dev-server.tt index c13880c5d..6d4847da8 100644 --- a/lib/install/bin/webpack-dev-server.tt +++ b/lib/install/bin/webpack-dev-server.tt @@ -21,5 +21,5 @@ unless File.foreach(File.join(APP_PATH, RAILS_ENV_CONFIG)).detect { |line| line. end Dir.chdir(APP_PATH) do - exec "#{SET_NODE_PATH} #{WEBPACKER_BIN} --config #{WEBPACK_CONFIG} --content-base #{APP_PATH}/public/packs #{ARGV.join(" ")}" + exec "#{SET_NODE_PATH} #{WEBPACKER_BIN} --config #{WEBPACK_CONFIG} --content-base #{APP_PATH}/public/dist #{ARGV.join(" ")}" end diff --git a/lib/install/config/development.js b/lib/install/config/development.js index 22eb3ca06..7a23e4a22 100644 --- a/lib/install/config/development.js +++ b/lib/install/config/development.js @@ -13,7 +13,9 @@ module.exports = merge(sharedConfig.config, { }, output: { - pathinfo: true + pathinfo: true, + // Make sure additional assets are loaded through webpack-dev-server + // publicPath: 'http://localhost:8080/' }, plugins: [ diff --git a/lib/install/config/shared.js b/lib/install/config/shared.js index bb63b5588..d82e6017a 100644 --- a/lib/install/config/shared.js +++ b/lib/install/config/shared.js @@ -8,17 +8,21 @@ const extname = require('path-complete-extname') let distDir = process.env.WEBPACK_DIST_DIR if (distDir === undefined) { - distDir = 'packs' + distDir = 'dist' } config = { entry: glob.sync(path.join('app', 'javascript', 'packs', '*.js*')).reduce((map, entry) => { const basename = path.basename(entry, extname(entry)) - map[basename] = path.resolve(entry) + map['packs/' + basename] = path.resolve(entry) return map }, {}), - output: { filename: '[name].js', path: path.resolve('public', distDir) }, + output: { + filename: '[name].js', + path: path.resolve('public', distDir), + publicPath: '/dist/' + }, module: { rules: [ diff --git a/lib/install/template.rb b/lib/install/template.rb index 554d41cfc..536394530 100644 --- a/lib/install/template.rb +++ b/lib/install/template.rb @@ -6,7 +6,7 @@ directory "#{__dir__}/config", 'config/webpack' append_to_file '.gitignore', <<-EOS -/public/packs +/public/dist /node_modules EOS diff --git a/lib/webpacker/helper.rb b/lib/webpacker/helper.rb index 5875729c0..d72c53a27 100644 --- a/lib/webpacker/helper.rb +++ b/lib/webpacker/helper.rb @@ -2,7 +2,7 @@ module Webpacker::Helper # Creates a script tag that references the named pack file, as compiled by Webpack per the entries list - # in config/webpack/shared.js. By default, this list is auto-generated to match everything in + # in config/webpack/shared.js. By default, this list is auto-generated to match everything in # app/javascript/packs/*.js. In production mode, the digested reference is automatically looked up. # # Examples: @@ -13,7 +13,7 @@ module Webpacker::Helper # # # In production mode: # <%= javascript_pack_tag 'calendar', 'data-turbolinks-track': 'reload' %> # => - # + # def javascript_pack_tag(name, **options) javascript_include_tag(Webpacker::Source.new(name).path, **options) end diff --git a/lib/webpacker/railtie.rb b/lib/webpacker/railtie.rb index 2b096a25b..281ac4d2b 100644 --- a/lib/webpacker/railtie.rb +++ b/lib/webpacker/railtie.rb @@ -9,7 +9,7 @@ class Webpacker::Engine < ::Rails::Engine ActionController::Base.helper Webpacker::Helper end - app.config.x.webpacker[:packs_dist_dir] ||= 'packs' + app.config.x.webpacker[:packs_dist_dir] ||= 'dist' app.config.x.webpacker[:packs_dist_path] ||= \ "/#{app.config.x.webpacker[:packs_dist_dir]}" diff --git a/lib/webpacker/source.rb b/lib/webpacker/source.rb index 18ab4de1c..a3af18870 100644 --- a/lib/webpacker/source.rb +++ b/lib/webpacker/source.rb @@ -3,8 +3,8 @@ # is by default in the production environment (as set via # `Rails.configuration.x.webpacker[:digesting] = true`). class Webpacker::Source - def initialize(name) - @name = name + def initialize(name, pack: true) + @name = pack ? "packs/#{name}" : name end def path