-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add static assets support #153
Conversation
Awesome! I'd love to give you some thoughts/feedback on this at some point if you're interested! |
Sure @dleavitt please do 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great Start!
Needs documentation that the webpack configs need 2 things:
- The magic output directory that the helpers know about.
- The use of the ManifestPlugin to creat the magic manifest file.
README.md
Outdated
method will automatically insert the correct digest when run in production mode. Just like the asset | ||
pipeline does it. | ||
To compile all the packs during deployment, you can use the `rails webpacker:compile` command. This will invoke the production configuration. The `javascript_pack_tag` | ||
helper method will automatically insert the correct compiled pack in production mode. Just like the asset pipeline does it. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add the stylesheet_pack_tag
docs.
README.md
Outdated
will invoke the production configuration, which includes digesting. The `javascript_pack_tag` helper | ||
method will automatically insert the correct digest when run in production mode. Just like the asset | ||
pipeline does it. | ||
To compile all the packs during deployment, you can use the `rails webpacker:compile` command. This will invoke the production configuration. The `javascript_pack_tag` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to specify the -e production
.
To compile all the packs during deployment, you can use the `rails -e production webpacker:compile` command. This will invoke the production configuration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will invoke the production configuration.
Maybe remove that sentence.
README.md
Outdated
method will automatically insert the correct digest when run in production mode. Just like the asset | ||
pipeline does it. | ||
To compile all the packs during deployment, you can use the `rails webpacker:compile` command. This will invoke the production configuration. The `javascript_pack_tag` | ||
helper method will automatically insert the correct compiled pack in production mode. Just like the asset pipeline does it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
javascript_pack_tag
helper method will automatically insert the correct compiled pack in production mode. Just like the asset pipeline does it.
How about:
The javascript_pack_tag
helper method will insert the compiled JavaScript bundle (aka pack) depending on one of 3 environments: production, static development, and hot-reloading for development.
@@ -9,19 +9,56 @@ NODE_ENV = ENV['NODE_ENV'] | |||
|
|||
APP_PATH = File.expand_path('../', __dir__) | |||
ESCAPED_APP_PATH = APP_PATH.shellescape | |||
|
|||
SET_NODE_PATH = "NODE_PATH=#{ESCAPED_APP_PATH}/node_modules" | |||
WEBPACKER_BIN = "./node_modules/.bin/webpack-dev-server" | |||
WEBPACK_CONFIG = "#{ESCAPED_APP_PATH}/config/webpack/#{NODE_ENV}.js" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WEBPACKER_BIN = "./node_modules/.bin/webpack-dev-server"
WEBPACK_CONFIG = "#{ESCAPED_APP_PATH}/config/webpack/#{NODE_ENV}.js"
For React on Rails, if we made this configurable
NODE_MODULES_PATH = "./node_modules" # or from ENV
WEPBACK_CONFIG_PATH=""#{ESCAPED_APP_PATH}/config/webpack" # or from ENV
WEBPACKER_BIN = "#{NODE_MODULES_PATH}/.bin/webpack-dev-server"
WEBPACK_CONFIG = "#{WEBPACK_CONFIG_PATH}/#{NODE_ENV}.js"
"#{RAILS_ENV_CONFIG}:#{line_num} \n\n" | ||
end | ||
|
||
value = value.strip.sub(/https?\:(\\\\|\/\/)(www.)?/,'').gsub('"', '') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
value = value.strip.sub(/https?\:(\\\\|\/\/)(www.)?/,'').gsub('"', '')
Consider %r to avoid escaping the /
value = value.strip.sub(%r{https?\:(\\\\|//)(www.)?},'').gsub('"', '')
lib/install/config/shared.js
Outdated
} | ||
} | ||
|
||
if (devHost && devPort) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All this logic should go into a file that is called like webpack.development.hot.config
.
I like to have a file that does simple creation of the assets statically for development mode. Hitting CMD-R has been better for us on big projects.
lib/install/config/shared.js
Outdated
} | ||
] | ||
}, | ||
|
||
plugins: [ | ||
new webpack.EnvironmentPlugin(Object.keys(process.env)) | ||
new webpack.EnvironmentPlugin(Object.keys(process.env)), | ||
new ExtractTextPlugin('[name].css'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move to production file.
lib/webpacker/helper.rb
Outdated
@@ -15,6 +15,27 @@ module Webpacker::Helper | |||
# <%= javascript_pack_tag 'calendar', 'data-turbolinks-track': 'reload' %> # => | |||
# <script src="/packs/calendar-1016838bab065ae1e314.js" data-turbolinks-track="reload"></script> | |||
def javascript_pack_tag(name, **options) | |||
javascript_include_tag(Webpacker::Source.new(name).path, **options) | |||
filename, _extension = name.split('.') | |||
filename += '.js' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File.basename(x, ".js")
lib/webpacker/helper.rb
Outdated
# <link rel="stylesheet" media="screen" href="/packs/calendar-1016838bab065ae1e122.css" data-turbolinks-track="reload" /> | ||
def stylesheet_pack_tag(name, **options) | ||
filename, _extension = name.split('.') | ||
filename += '.css' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File.basename(x, ".js")
lib/webpacker/source.rb
Outdated
else | ||
File.join(dist_path, filename) | ||
Webpacker::Digests.lookup(filename) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part is 👍 .
Thanks @justin808 for reviewing. I will make the changes 👍 |
lib/webpacker/digests.rb
Outdated
@@ -1,5 +1,5 @@ | |||
# Singleton registry for accessing the digested filenames computed by Webpack in production mode. | |||
# This allows javascript_pack_tag to take a reference to, say, "calendar.js" and turn it into | |||
# This allows javascript_pack_tag to take a reference to, say, "calendar.js" and turn it into | |||
# "calendar-1016838bab065ae1e314.js". These digested filenames are what enables you to long-term | |||
# cache things in production. | |||
class Webpacker::Digests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gauravtiwari We need to fix the errors in this file so they are crystal clear.
If somebody starts the rails server without first starting, and having the compilation complete, we won't have a digest file.
The typical case is to use a profile to start both the rails server and the dev server in watch mode for generating static files. The rails server will start first, and then there will be no manifest.
Here is an example:
https://github.com/shakacode/react_on_rails/blob/master/spec/dummy/Procfile.static
# Run Rails without hot reloading (static assets).
rails: REACT_ON_RAILS_ENV= rails s -b 0.0.0.0
# Build client assets, watching for changes.
rails-client-assets: sh -c 'yarn run build:dev:client'
# Build server assets, watching for changes. Remove if not server rendering.
rails-server-assets: sh -c 'yarn run build:dev:server'
@@ -0,0 +1,124 @@ | |||
AllCops: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
awesome to have rubocop!
@@ -13,10 +13,12 @@ cache: | |||
yarn: true | |||
|
|||
install: | |||
- gem install rubocop |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this get handled by the gemfile?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@justin808 hmm, may be but don't like dependencies. Also, it seems rubocop is more kinda of standalone program now, like yarn and npm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it should be in the Gemfile. If it is a development dependency, it should be there.
host, port = value.split(':') | ||
config = begin | ||
package_json = File.read(File.join(APP_PATH, 'package.json')) | ||
JSON.parse(package_json)['config'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- you may nil if there is no 'config' section
- Error message should either mention that package.json is not found or config key is not found.
I would avoid a very generic name like 'config'. Generic is more likely to get a conflict in the future.
How about 'railsConfig'?
"--config #{WEBPACK_CONFIG} --content-base #{ESCAPED_APP_PATH}/public/packs" | ||
" #{ARGV.join(" ")}" | ||
exec "NODE_PATH=#{NODE_MODULES_PATH} #{WEBPACK_BIN} " \ | ||
"--config #{WEBPACK_CONFIG} --content-base #{PACKS_PATH} #{ARGV.join(" ")}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--content-base #{PACKS_PATH}
Let's read that from the package.json rather than having the shell script read it.
|
||
Dir.chdir(APP_PATH) do | ||
exec "#{SET_NODE_PATH} #{WEBPACK_BIN} --config #{WEBPACK_CONFIG} #{ARGV.join(" ")}" | ||
exec "NODE_PATH=#{NODE_MODULES_PATH} #{WEBPACK_BIN} --config #{WEBPACK_CONFIG}" \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see comments from prior file
lib/install/templates/static.rb
Outdated
run "./bin/yarn add extract-text-webpack-plugin node-sass file-loader " \ | ||
"sass-loader css-loader style-loader " | ||
|
||
package_json = Webpacker::PackageJson.new().config |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if the user already modified package json?
Maybe webpacker should merge? not replace?
lib/webpacker/manifest.rb
Outdated
end | ||
end | ||
|
||
def initialize(path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for a true singleton, you can make the constructor, etc. private
lib/webpacker/railtie.rb
Outdated
app.config.x.webpacker[:packs_dist_dir], | ||
'digests.json') | ||
|
||
Webpacker::Digests.load(app.config.x.webpacker[:digests_path]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Big 👍 on removing this code!
lib/webpacker/source.rb
Outdated
end | ||
|
||
def path | ||
if config[:dev_server_host].present? | ||
"#{config[:dev_server_host]}/#{filename}" | ||
if Rails.env.development? && config.dev_server[:enabled] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Be sure to allow overriding the dev_sever[:enabled] option by env value, as this is something that is NOT the application config, but really a runtime option!
lib/webpacker/source.rb
Outdated
else | ||
Webpacker::Digests.lookup(filename) | ||
Webpacker::Manifest.load(digests_path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should only be reloading this during development mode. RAILS_ENV == 'production' ==> no need to reload.
… plugin Add file and style loaders Use the env options pass and configure file and style loader Setup dev server using env supplied Add node-sass Update production config to use plugins in production mode Refactor compile task as we now use manifest plugin Remove extra whitespace Refactor javascript pack tag and add a new stylesheet pack tag Remove extra logic from source lookup class Use same public path used in shared config Add some checks to make sure valid host and port is passed to dev server Change failure message Remove unwanted env variables Re-order variables Add back NODE_ENV Add the failure check block Just use manifest to lookup files in all environments Remove digesting option Remove digestion option Fix typo Remove reference to digesting in readme Fix error message Remove extra whitespace Remove loader option plugin Fix linter complaints Add example for static assets in readme Remove bash Use file.basename Cleanup webpack configs Fix typo Use env correctly Use hash in production Don't remove .js from babel, instead append jsx to it Export file loader extensions to a variable Redo everything, but first lets add rubocop Copy rubocop.yml from rails repo Change quotes Use package.json and refactor webpack config files Use package.json to load config and get rid of railtie Move templates to separate folder Update webpack binstubs to use package.json as config Lint using rubocop Conditionally require static config Setup a separate install task to setup static assets support Fix typo Add static task Update name and description in package.json Rename config to package_json and update references Add version to separate file and post-install notes Make sure puts write to terminal immediately Rename folder for clarity Update templates to use new path Remove image support from vue installer Update package.json template Update message text Refactor package_json class Add new config class to compile task Block request until digests.json is available Remove .tt Restructure static config location Fix static asset description Preserve whitespace Install static only when needed Use template to insert static support code Cleanup error and warning messages Make sure to check webpacker is installed before running static task Update not found message Update readme with latest changes Refactor classes, variable names and error messages Update post install message Rename static to assets Minor cleanup Fix readme formatting Rename for clarity Wrap it in begin block Minor fixes Wrap everything inside a block Ensure to exit out of the program Add a verify task that gets run before running any dependent task Add the verify task Fix typo Fix missing variable Update postinstall message Fix a typo
lib/webpacker/helper.rb
Outdated
unless webpacker_config[:assets] | ||
raise StandardError, | ||
"Stylesheet support is not enabled. Install using " \ | ||
"webpacker:install:assets" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just inline this raise entirely. No need to fit in 80 chars.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure 👍
lib/webpacker/package_json.rb
Outdated
@@ -0,0 +1,58 @@ | |||
# Loads the package.json file from app root to read the webpacker configuration | |||
|
|||
class Webpacker::PackageJson |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd go with Webpacker::Configuration
instead. The fact that the config is in package.json is an implementational detail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh yes, that makes more sense 😄
webpacker.gemspec
Outdated
|
||
s.files = `git ls-files`.split("\n") | ||
s.test_files = `git ls-files -- test/*`.split("\n") | ||
s.post_install_message = %{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't like the use of post install message. Let's move all docs to README.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alrighty! will remove
WEBPACK_CONFIG = "#{ESCAPED_APP_PATH}/config/webpack/#{NODE_ENV}.js" | ||
begin | ||
package_json = File.read(File.join(APP_PATH, 'package.json')) | ||
config = JSON.parse(package_json) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to have package_json as it's own var. Just inline it like JSON.parse(File.read(File.join(APP_PATH, 'package.json')))
.
|
||
# Warn the user if the configuration is not set | ||
RAILS_ENV_CONFIG = File.join("config", "environments", "#{RAILS_ENV}.rb") | ||
NODE_MODULES_PATH = "#{File.join(ESCAPED_APP_PATH, config['webpacker']['nodeModulesPath'])}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't need to what this in a string. NODE_MODULES_PATH = File.join(ESCAPED_APP_PATH, config['webpacker']['nodeModulesPath'])
is good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, do need ESCAPED_APP_PATH and APP_PATH. Just escape APP_PATH.
puts "Warning: if you want to use webpack-dev-server, you need to tell Webpacker to serve asset packs from it. Please set config.x.webpacker[:dev_server_host] in #{RAILS_ENV_CONFIG}.\n\n" | ||
if config['devServer'] && !config['devServer']['enabled'] | ||
puts "Error: If you want to use webpack-dev-server, you will need to enable " \ | ||
"webpack-dev-server from your package.json { devServer: { enabled: true } }" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems weird to me. Why not just assume its enabled if the configuration for it is there?
WEBPACK_CONFIG_PATH = "#{File.join(ESCAPED_APP_PATH, config['webpacker']['configPath'])}" | ||
PACKS_PATH = "#{File.join(ESCAPED_APP_PATH, config['webpacker']['distPath'])}" | ||
WEBPACK_BIN = "#{NODE_MODULES_PATH}/.bin/webpack-dev-server" | ||
WEBPACK_CONFIG = "#{WEBPACK_CONFIG_PATH}/development.hot.js" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given all the known issues with hot reloading, maybe it shouldn't be the default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps, rename it to development.server.js? We never had hot reloading from start as it requires more setup and got packages for different frameworks. It's just for dev server, that supports live reloading (not hot).
lib/install/bin/webpack.tt
Outdated
config = JSON.parse(package_json) | ||
|
||
NODE_MODULES_PATH = "#{File.join(ESCAPED_APP_PATH, config['webpacker']['nodeModulesPath'])}" | ||
WEBPACK_CONFIG_PATH = "#{File.join(ESCAPED_APP_PATH, config['webpacker']['configPath'])}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same style comments as per the dev server.
lib/install/config/assets.js
Outdated
}) | ||
}, | ||
{ | ||
test: /\.(jpeg|png|gif|svg|eot|svg|ttf|woff|woff2)$/i, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What provisions are we supplying to actually reference these assets? I only saw stylesheet getting a pack tag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, we don't have any for now. The assets here will be mostly used within javascripts and css as that's where the templates are. An example with react would be,
import React from 'react'
import ReactDOM from 'react-dom'
import clockIcon from '../counter/images/clock.png';
import './hello-react.sass'
const Hello = props => (
<div className="hello-react">
<img src={clockIcon} alt="clock" />
<p>Hello {props.name}!</p>
</div>
)
Hello.defaultProps = {
name: 'David'
}
Hello.propTypes = {
name: React.PropTypes.string
}
document.addEventListener('DOMContentLoaded', () => {
ReactDOM.render(
<Hello name="React" />,
document.getElementById('react-app'),
)
})
@font-face
font-family: 'Lacuna'
src: url('../fonts/lacuna-webfont.eot')
src: url('../fonts/lacuna-webfont.eot?#iefix') format('embedded-opentype'),
url('../fonts/lacuna-webfont.woff') format('woff'),
url('../fonts/lacuna-webfont.ttf') format('truetype'),
url('../fonts/lacuna-webfont.svg#Darkenstone') format('svg')
font-weight: normal
font-style: normal
#css-bg-image
width: 48px
height: 48px
background-image: url('../images/clock.png')
background-repeat: no-repeat
Perhaps, we can add an asset_pack_tag
later?
publicPath: devServer.enabled ? | ||
`http://${devServer.host}:${devServer.port}/` : `/${sharedConfig.distDir}/` | ||
} | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't see any hot reloading configured here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, same settings as before, just configurable. We can turn it on, but it will require more setup. This is just for configuring the dev server. Perhaps rename the file to development.server.js
?
lib/install/config/webpack/shared.js
Outdated
const extname = require('path-complete-extname') | ||
const { webpacker } = require('../../package.json') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd do { config }
instead and then just reference things directly off that object rather than assigning a bunch of consts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yes, totally forgot 👍 Will do
lib/install/templates/assets.rb
Outdated
|
||
insert_into_file "config/webpack/development.js", | ||
assets_webpack_config, | ||
after: "const sharedConfig = require('./shared.js')\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't like this indention style. If that's a Rubocop setting, let's change it. Should look like this:
insert_into_file "config/webpack/development.js",
assets_webpack_config,
after: "const sharedConfig = require('./shared.js')\n"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure
lib/install/templates/install.rb
Outdated
@@ -0,0 +1,20 @@ | |||
# Setup webpacker | |||
|
|||
directory "#{File.expand_path("..", __dir__)}/node", "./" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for the wrapping "".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, the first one seems like it should use a path join instead.
lib/tasks/installers/angular.rake
Outdated
|
||
if config.include?('ts-loader') | ||
if config.include?("ts-loader") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style: Use '' for keys etc without interpolation. Use "" for sentences, prose, or for interpolation.
lib/webpacker/helper.rb
Outdated
|
||
filename = File.basename(name, ".css") | ||
filename += ".css" | ||
stylesheet_link_tag(Webpacker::Source.new(filename).path, **options) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stylesheet_link_tag(Webpacker::Source.new("#{File.basename(name, '.css')}.css").path, **options)
lib/webpacker/manifest.rb
Outdated
# files, # "/packs/calendar-1016838bab065ae1e314.js" and | ||
# "/packs/calendar-1016838bab065ae1e314.css" for long-term caching | ||
|
||
class Webpacker::Manifest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the renaming from Digests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously, it was used for looking up digests on production, but now this is used in all environments to lookup assets using manifest file, not just for digesting. What do you think?
lib/webpacker/manifest.rb
Outdated
end | ||
|
||
private | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✂️ newline.
lib/webpacker/package_json.rb
Outdated
@@ -0,0 +1,58 @@ | |||
# Loads the package.json file from app root to read the webpacker configuration | |||
|
|||
class Webpacker::PackageJson |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This whole thing is too cumbersome. I can see how it's based off configuration, but it feels very boilerplatey.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, I felt too, but later realised that's how most configuration files looks. Anything you think that can make this look simpler?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
haha you are fast. is 2017 the year to introduce emoji into rails gems :D
@ytbryan Yeah, Rails got Webpacker 😉 |
@dhh Added separate loaders support in this commit - d7278d2 I felt this is one last major thing missing. No more overwriting shared.js as it now has very little configuration. Also, refactored integration installers (react etc.) to use thor, which makes it less brittle as thor is really good at it 😄 Not sure if you are okay with extensions? I have added them all by default. @ytbryan I saw that you added an alias for vue es6 module. For now, I have removed it and referenced it directly from the entry file to isolate shared.js as much as possible. |
Looking good. Ready to merge? |
@dhh Yepp 👍 |
This is so exciting! Thanks so much @gauravtiwari for getting this shipped ❤️ |
@samandmoore Nope, not on purpose, just forgot. But I guess it's easy enough now to add it 😄 |
@@ -0,0 +1,124 @@ | |||
AllCops: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use the same as rails/rails using the inherit_from
option?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should follow https://github.com/github/rubocop-github and create a gem rubocop-rails
or something and use it all over the rails repositories with inherit_gem
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inherit_from
is sufficient. We don't need a gem if we can download the config from github.
this flag was removed in #153, but without it the error handling block throws a `JSON::ParserError` and dumps the webpack output
Not sure if the whole paragraph in the README should go away, but after rails#153 it's not true that webpacker is _only_meant for JS files.
Wonderful work! Any way to add bootstrap with webpacker configuration on rails 5.1? |
@Ifegwu Here you go -
// In your main entry/pack file
import 'bootstrap/dist/css/bootstrap.css'; And then basically follow this guide - https://reactstrap.github.io/ If you have any questions please ask on StackOverflow |
Thanks for your swift response. Can this method be able to style devise? |
I have no issues, just a big thank you for this feature! This is GREAT! 😄 👏 🙏 |
Major Changes
stylesheet_pack_tag
helper tag to helper.rbMinor updates
Demo: https://webpacker-example-app.herokuapp.com/
I made some out-of-scope changes like linting. Since, this involved touching a lot of files, I thought it would make sense to do it now. Sorry :)
@dhh @dleavitt @guilleiguaran Please review when you get a chance ❤️ . Obviously, there might be some things that I have missed and sorry if I trespassed 😄
To try this out locally,
Open up the gemfile and add
run
bundle install
then,In
config/routes.rb
Open up view pages/index.html.erb
Finally, run webpack-watcher in one terminal window,
and in other,
bundle exec rails s
Go to http://localhost:3000 to see all example apps running. Now, to test out styles,
in app/javascript/packs, create a file called hello_react.sass
add a className to react example,
and finally, add
<%= stylesheet_pack_tag 'hello_react' %>
to pages/index.html.erbReload the browser and Voila!
Deploy it to heroku
Replace
sqlite
gem withpg