README.md in webpacker-3.2.2 vs README.md in webpacker-3.3.0

- old
+ new

@@ -84,11 +84,11 @@ # OR if you prefer to use master gem 'webpacker', git: 'https://github.com/rails/webpacker.git' ``` -and finally, run following to install Webpacker: +Finally, run following to install Webpacker: ```bash bundle bundle exec rails webpacker:install @@ -97,11 +97,11 @@ ``` ### Usage -Once installed you can start writing modern ES6-flavored JavaScript app today: +Once installed, you can start writing modern ES6-flavored JavaScript apps right away: ```yml app/javascript: ├── packs: │ # only webpack entry files here @@ -110,20 +110,20 @@ │ └── application.css └── images: └── logo.svg ``` -You can then link the JavaScript pack in Rails view using `javascript_pack_tag` helper. -If you have styles imported in your pack file, you can link using `stylesheet_pack_tag`: +You can then link the JavaScript pack in Rails views using the `javascript_pack_tag` helper. +If you have styles imported in your pack file, you can link them by using `stylesheet_pack_tag`: ```erb <%= javascript_pack_tag 'application' %> <%= stylesheet_pack_tag 'application' %> ``` If you want to link a static asset for `<link rel="prefetch">` or `<img />` tag, you -can use `asset_pack_path` helper: +can use the `asset_pack_path` helper: ```erb <link rel="prefetch" href="<%= asset_pack_path 'application.css' %>" /> <img src="<%= asset_pack_path 'images/logo.svg' %>" /> ``` @@ -134,20 +134,20 @@ ### Development Webpacker ships with two binstubs: `./bin/webpack` and `./bin/webpack-dev-server`. Both are thin wrappers around the standard `webpack.js` and `webpack-dev-server.js` -executable to ensure that the right configuration file and environment variables -are loaded depending on your environment. +executables to ensure that the right configuration files and environmental variables +are loaded based on your environment. In development, Webpacker compiles on demand rather than upfront by default. This happens when you refer to any of the pack assets using the Webpacker helper methods. -That means you don't have to run any separate process. Compilation errors are logged +This means that you don't have to run any separate processes. Compilation errors are logged to the standard Rails log. -If you want to use live code reloading, or you have enough JavaScript that on-demand compilation is too slow, you'll need to run `./bin/webpack-dev-server` or `ruby ./bin/webpack-dev-server` if on windows, -in a separate terminal from `bundle exec rails s`. This process will watch for changes +If you want to use live code reloading, or you have enough JavaScript that on-demand compilation is too slow, you'll need to run `./bin/webpack-dev-server` or `ruby ./bin/webpack-dev-server`. Windows users will need to run these commands +in a terminal separate from `bundle exec rails s`. This process will watch for changes in the `app/javascript/packs/*.js` files and automatically reload the browser to match. ```bash # webpack dev server ./bin/webpack-dev-server @@ -158,66 +158,66 @@ # standalone build ./bin/webpack ``` Once you start this development server, Webpacker will automatically start proxying all -webpack asset requests to this server. When you stop the server, it'll revert to -on-demand compilation again. +webpack asset requests to this server. When you stop the server, it'll revert back to +on-demand compilation. You can use environment variables as options supported by [webpack-dev-server](https://webpack.js.org/configuration/dev-server/) in the -form `WEBPACKER_DEV_SERVER_<OPTION>`. Please note that these environment +form `WEBPACKER_DEV_SERVER_<OPTION>`. Please note that these environmental variables will always take precedence over the ones already set in the -configuration file, and that the _same_ environment variables must +configuration file, and that the _same_ environmental variables must be available to the `rails server` process. ```bash WEBPACKER_DEV_SERVER_HOST=example.com WEBPACKER_DEV_SERVER_INLINE=true WEBPACKER_DEV_SERVER_HOT=false ./bin/webpack-dev-server ``` -By default, webpack dev server listens on `localhost` in development for security -but if you want your app to be available over local LAN IP or VM instance like vagrant +By default, the webpack dev server listens on `localhost` in development for security purposes. +However, if you want your app to be available over local LAN IP or a VM instance like vagrant, you can set the `host` when running `./bin/webpack-dev-server` binstub: ```bash WEBPACKER_DEV_SERVER_HOST=0.0.0.0 ./bin/webpack-dev-server ``` -**Note:** You need to allow webpack-dev-server host as allowed origin for `connect-src` if you are running your application in a restrict CSP environment like Rails 5.2+. This can be done in Rails 5.2+ for development environment in the CSP initializer `config/initializers/content_security_policy.rb` with a snippet like this: +**Note:** You need to allow webpack-dev-server host as an allowed origin for `connect-src` if you are running your application in a restrict CSP environment (like Rails 5.2+). This can be done in Rails 5.2+ in the CSP initializer `config/initializers/content_security_policy.rb` with a snippet like this: ```ruby p.connect_src :self, :https, 'http://localhost:3035', 'ws://localhost:3035' if Rails.env.development? ``` -**Note:** Don't forget to prefix `ruby` when running these binstubs on windows +**Note:** Don't forget to prefix `ruby` when running these binstubs on Windows ### webpack configuration See [docs/webpack](docs/webpack.md) for modifying webpack configuration and loaders. ### Upgrading -You can run following commands to upgrade Webpacker to the latest stable version, this involves upgrading the gem and related npm modules: +You can run following commands to upgrade Webpacker to the latest stable version. This process involves upgrading the gem and related npm modules: ```bash bundle update webpacker yarn upgrade @rails/webpacker --latest yarn upgrade webpack-dev-server --latest ``` ### Yarn Integrity -By default in development, webpacker runs a yarn integrity check to ensure that all local npm packages are up-to-date. This is similar to what bundler does currently in Rails, but for JavaScript packages. If your system is out of date, then Rails will not initialize and you will be asked to upgrade your local npm packages by running `yarn install`. +By default, in development, webpacker runs a yarn integrity check to ensure that all local npm packages are up-to-date. This is similar to what bundler does currently in Rails, but for JavaScript packages. If your system is out of date, then Rails will not initialize. You will be asked to upgrade your local npm packages by running `yarn install`. -To turn off this option, you will need to override the default by adding a new config options to your Rails development environment configuration file (`config/environment/development.rb`): +To turn off this option, you will need to override the default by adding a new config option to your Rails development environment configuration file (`config/environment/development.rb`): ``` config.webpacker.check_yarn_integrity = false ``` -You may also turn on this option by adding the config option to any Rails environment configuration file: +You may also turn on this feature by adding the config option to any Rails environment configuration file: ``` config.webpacker.check_yarn_integrity = true ``` @@ -237,12 +237,12 @@ ``` (or run `bundle exec rails webpacker:install:react` in a existing Rails app already setup with Webpacker). -The installer will add all relevant dependencies using Yarn, any changes -to the configuration files and an example React component to your +The installer will add all relevant dependencies using Yarn, changes +to the configuration files, and an example React component to your project in `app/javascript/packs` so that you can experiment with React right away. ### Angular with TypeScript @@ -255,23 +255,23 @@ ``` (or run `bundle exec rails webpacker:install:angular` on a Rails app already setup with Webpacker). -The installer will add TypeScript and Angular core libraries using Yarn plus -any changes to the configuration files. An example component is written in +The installer will add the TypeScript and Angular core libraries using Yarn alongside +a few changes to the configuration files. An example component written in TypeScript will also be added to your project in `app/javascript` so that you can experiment with Angular right away. -By default Angular uses a JIT compiler for development environment, this +By default, Angular uses a JIT compiler for development environment. This compiler is not compatible with restrictive CSP (Content Security Policy) environments like Rails 5.2+. You can use Angular AOT compiler in development with the [@ngtools/webpack](https://www.npmjs.com/package/@ngtools/webpack#usage) plugin. -Alternatively if you're using Rails 5.2+ you can enable `unsafe-eval` rule for -development environment, this can be done in the `config/initializers/content_security_policy.rb` -with the following configuration: +Alternatively if you're using Rails 5.2+ you can enable `unsafe-eval` rule for your +development environment. This can be done in the `config/initializers/content_security_policy.rb` +with the following code: ```ruby if Rails.env.development? p.script_src :self, :https, :unsafe_eval else @@ -289,17 +289,16 @@ # Rails 5.1+ rails new myapp --webpack=vue ``` (or run `bundle exec rails webpacker:install:vue` on a Rails app already setup with Webpacker). -The installer will add Vue and required libraries using Yarn plus -any changes to the configuration files. An example component will -also be added to your project in `app/javascript` so that you can -experiment Vue right away. +The installer will add Vue and its required libraries using Yarn alongside +automatically applying changes needed to the configuration files. An example component will +be added to your project in `app/javascript` so that you can experiment with Vue right away. -If you're using Rails 5.2+ you need to enable `unsafe-eval` rule for development environment, -this can be done in the `config/initializers/content_security_policy.rb` with the following +If you're using Rails 5.2+ you'll need to enable `unsafe-eval` rule for your development environment. +This can be done in the `config/initializers/content_security_policy.rb` with the following configuration: ```ruby if Rails.env.development? p.script_src :self, :https, :unsafe_eval @@ -320,11 +319,11 @@ rails new myapp --webpack=elm ``` (or run `bundle exec rails webpacker:install:elm` on a Rails app already setup with Webpacker). -The Elm library and core packages will be added via Yarn and Elm itself. +The Elm library and its core packages will be added via Yarn and Elm. An example `Main.elm` app will also be added to your project in `app/javascript` so that you can experiment with Elm right away. ### Stimulus @@ -354,19 +353,19 @@ To add [Erb](https://apidock.com/ruby/ERB) support in your JS templates, run `bundle exec rails webpacker:install:erb` on a Rails app already setup with Webpacker. An example `hello_erb.js.erb` file will also be added to your project -in `app/javascript/packs` so that you can experiment with Erb flavoured +in `app/javascript/packs` so that you can experiment with Erb-flavoured javascript right away. ## Paths By default, Webpacker ships with simple conventions for where the JavaScript -app files and compiled webpack bundles will go in your Rails app, -but all these options are configurable from `config/webpacker.yml` file. +app files and compiled webpack bundles will go in your Rails app. +All these options are configurable from `config/webpacker.yml` file. The configuration for what webpack is supposed to compile by default rests on the convention that every file in `app/javascript/packs/*`**(default)** or whatever path you set for `source_entry_path` in the `webpacker.yml` configuration is turned into their own output files (or entry points, as webpack calls it). Therefore you don't want to put anything inside `packs` directory that you do not want to be @@ -397,20 +396,20 @@ ### Resolved If you are adding Webpacker to an existing app that has most of the assets inside -`app/assets` or inside an engine and you want to share that -with webpack modules then you can use `resolved_paths` -option available in `config/webpacker.yml`, which lets you -add additional paths webpack should lookup when resolving modules: +`app/assets` or inside an engine, and you want to share that +with webpack modules, you can use the `resolved_paths` +option available in `config/webpacker.yml`. This lets you +add additional paths that webpack should lookup when resolving modules: ```yml resolved_paths: ['app/assets'] ``` -You can then import them inside your modules like so: +You can then import these items inside your modules like so: ```js // Note it's relative to parent directory i.e. app/assets import 'stylesheets/main' import 'images/rails.png' @@ -421,23 +420,23 @@ whole parent directory if you just need to reference one or two modules ### Watched -By default, the lazy compilation is cached until a file is changed under -tracked paths. You can configure the paths tracked -by adding new paths to `watched_paths` array, much like Rails `autoload_paths`: +By default, the lazy compilation is cached until a file is changed under your +tracked paths. You can configure which paths are tracked +by adding new paths to `watched_paths` array. This is much like Rails' `autoload_paths`: ```rb # config/initializers/webpacker.rb # or config/application.rb Webpacker::Compiler.watched_paths << 'bower_components' ``` ## Deployment -Webpacker hooks up a new `webpacker:compile` task to `assets:precompile`, which gets run whenever you run `assets:precompile`. If you are not using Sprockets `webpacker:compile` is automatically aliased to `assets:precompile`. Remember to set NODE_ENV environment variable to production during deployment or when running the rake task. +Webpacker hooks up a new `webpacker:compile` task to `assets:precompile`, which gets run whenever you run `assets:precompile`. If you are not using Sprockets, `webpacker:compile` is automatically aliased to `assets:precompile`. Remember to set NODE_ENV environment variable to production during deployment or when running this rake task. ## Docs You can find more detailed guides under [docs](./docs).