webpacker-5.4.3/ 0000755 0000041 0000041 00000000000 14123265223 013516 5 ustar www-data www-data webpacker-5.4.3/Gemfile.lock 0000644 0000041 0000041 00000010663 14123265223 015746 0 ustar www-data www-data PATH
remote: .
specs:
webpacker (5.4.0)
activesupport (>= 5.2)
rack-proxy (>= 0.6.1)
railties (>= 5.2)
semantic_range (>= 2.3.0)
GEM
remote: https://rubygems.org/
specs:
actioncable (6.1.3.2)
actionpack (= 6.1.3.2)
activesupport (= 6.1.3.2)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
actionmailbox (6.1.3.2)
actionpack (= 6.1.3.2)
activejob (= 6.1.3.2)
activerecord (= 6.1.3.2)
activestorage (= 6.1.3.2)
activesupport (= 6.1.3.2)
mail (>= 2.7.1)
actionmailer (6.1.3.2)
actionpack (= 6.1.3.2)
actionview (= 6.1.3.2)
activejob (= 6.1.3.2)
activesupport (= 6.1.3.2)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0)
actionpack (6.1.3.2)
actionview (= 6.1.3.2)
activesupport (= 6.1.3.2)
rack (~> 2.0, >= 2.0.9)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.2.0)
actiontext (6.1.3.2)
actionpack (= 6.1.3.2)
activerecord (= 6.1.3.2)
activestorage (= 6.1.3.2)
activesupport (= 6.1.3.2)
nokogiri (>= 1.8.5)
actionview (6.1.3.2)
activesupport (= 6.1.3.2)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
activejob (6.1.3.2)
activesupport (= 6.1.3.2)
globalid (>= 0.3.6)
activemodel (6.1.3.2)
activesupport (= 6.1.3.2)
activerecord (6.1.3.2)
activemodel (= 6.1.3.2)
activesupport (= 6.1.3.2)
activestorage (6.1.3.2)
actionpack (= 6.1.3.2)
activejob (= 6.1.3.2)
activerecord (= 6.1.3.2)
activesupport (= 6.1.3.2)
marcel (~> 1.0.0)
mini_mime (~> 1.0.2)
activesupport (6.1.3.2)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
zeitwerk (~> 2.3)
ast (2.4.2)
builder (3.2.4)
byebug (11.1.3)
concurrent-ruby (1.1.8)
crass (1.0.6)
erubi (1.10.0)
globalid (0.4.2)
activesupport (>= 4.2.0)
i18n (1.8.10)
concurrent-ruby (~> 1.0)
loofah (2.9.1)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.7.1)
mini_mime (>= 0.1.1)
marcel (1.0.1)
method_source (1.0.0)
mini_mime (1.0.3)
mini_portile2 (2.5.1)
minitest (5.14.4)
nio4r (2.5.7)
nokogiri (1.11.4)
mini_portile2 (~> 2.5.0)
racc (~> 1.4)
parallel (1.20.1)
parser (3.0.1.1)
ast (~> 2.4.1)
racc (1.5.2)
rack (2.2.3)
rack-proxy (0.6.5)
rack
rack-test (1.1.0)
rack (>= 1.0, < 3)
rails (6.1.3.2)
actioncable (= 6.1.3.2)
actionmailbox (= 6.1.3.2)
actionmailer (= 6.1.3.2)
actionpack (= 6.1.3.2)
actiontext (= 6.1.3.2)
actionview (= 6.1.3.2)
activejob (= 6.1.3.2)
activemodel (= 6.1.3.2)
activerecord (= 6.1.3.2)
activestorage (= 6.1.3.2)
activesupport (= 6.1.3.2)
bundler (>= 1.15.0)
railties (= 6.1.3.2)
sprockets-rails (>= 2.0.0)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.3.0)
loofah (~> 2.3)
railties (6.1.3.2)
actionpack (= 6.1.3.2)
activesupport (= 6.1.3.2)
method_source
rake (>= 0.8.7)
thor (~> 1.0)
rainbow (3.0.0)
rake (13.0.3)
regexp_parser (2.1.1)
rexml (3.2.5)
rubocop (0.93.1)
parallel (~> 1.10)
parser (>= 2.7.1.5)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8)
rexml
rubocop-ast (>= 0.6.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 2.0)
rubocop-ast (1.5.0)
parser (>= 3.0.1.1)
rubocop-performance (1.10.2)
rubocop (>= 0.90.0, < 2.0)
rubocop-ast (>= 0.4.0)
ruby-progressbar (1.11.0)
semantic_range (3.0.0)
sprockets (4.0.2)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.2.2)
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
thor (1.1.0)
tzinfo (2.0.4)
concurrent-ruby (~> 1.0)
unicode-display_width (1.7.0)
websocket-driver (0.7.3)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
zeitwerk (2.4.2)
PLATFORMS
ruby
DEPENDENCIES
bundler (>= 1.3.0)
byebug
minitest (~> 5.0)
rack-proxy
rails
rake (>= 11.1)
rubocop (= 0.93.1)
rubocop-performance
semantic_range
webpacker!
BUNDLED WITH
2.2.3
webpacker-5.4.3/docs/ 0000755 0000041 0000041 00000000000 14123265223 014446 5 ustar www-data www-data webpacker-5.4.3/docs/target.md 0000644 0000041 0000041 00000001533 14123265223 016260 0 ustar www-data www-data # Target browsers
By default webpacker provides these front-end tools:
- [@babel/preset-env](https://github.com/babel/babel/tree/master/packages/babel-preset-env)
- [Autoprefixer](https://github.com/postcss/autoprefixer)
- [postcss-preset-env](https://github.com/csstools/postcss-preset-env)
All these tools use [Browserslist](https://github.com/browserslist/browserslist) to detect which environment your users have
Webpacker browserslist default target:
```
defaults
```
`defaults`: `(> 0.5%, last 2 versions, Firefox ESR, not dead)`, [browserl.ist](https://browserl.ist/) is an online tool to check what browsers will be selected by some query.
To keep browsers data up to date, you need to run:
```bash
yarn upgrade caniuse-lite
```
at least once every few months, to prevent such [problems](https://github.com/browserslist/browserslist/issues/492)
webpacker-5.4.3/docs/deployment.md 0000644 0000041 0000041 00000011616 14123265223 017155 0 ustar www-data www-data # 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.
The `javascript_pack_tag` and `stylesheet_pack_tag` helper method will automatically insert the correct HTML tag for compiled pack. Just like the asset pipeline does it.
By default the output will look like this in different environments:
```html
```
## Heroku
In order for your Webpacker app to run on Heroku, you'll need to do a bit of configuration before hand.
```
heroku create my-webpacker-heroku-app
heroku addons:create heroku-postgresql:hobby-dev
heroku buildpacks:add heroku/nodejs
heroku buildpacks:add heroku/ruby
git push heroku master
```
We're essentially doing the following here:
* Creating an app on Heroku
* Creating a Postgres database for the app (this is assuming that you're using Heroku Postgres for your app)
* Adding the Heroku NodeJS and Ruby buildpacks for your app. This allows the `npm` or `yarn` executables to properly function when compiling your app - as well as Ruby.
* Pushing our code to Heroku and kicking off the deployment
## Nginx
Webpacker doesn't serve anything in production. You’re expected to configure your web server to serve files in public/ directly.
Some servers support sending precompressed versions of files when they're available. For example, nginx offers a `gzip_static` directive that serves files with the `.gz` extension to supported clients. With an optional module, nginx can also serve Brotli compressed files with the `.br` extension (see below for installation and configuration instructions).
Here's a sample nginx site config for a Rails app using Webpacker:
```nginx
upstream app {
# server unix:///path/to/app/tmp/puma.sock;
}
server {
listen 80;
server_name www.example.com;
root /path/to/app/public;
location @app {
proxy_pass http://app;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location / {
try_files $uri @app;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
location ~ /\.(?!well-known).* {
deny all;
}
location ~ ^/(assets|packs)/ {
gzip_static on;
brotli_static on; # Optional, see below
expires max;
add_header Cache-Control public;
}
}
```
### Installing the ngx_brotli module
If you want to serve Brotli compressed files with nginx, you will need to install the `nginx_brotli` module. Installation instructions from source can be found in the official [google/ngx_brotli](https://github.com/google/ngx_brotli) git repository. Alternatively, depending on your platform, the module might be available via a pre-compiled package.
Once installed, you need to load the module. As we want to serve the pre-compressed files, we only need the static module. Add the following line to your `nginx.conf` file and reload nginx:
```
load_module modules/ngx_http_brotli_static_module.so;
```
Now, you can set `brotli_static on;` in your nginx site config, as per the config in the last section above.
## CDN
Webpacker out-of-the-box provides CDN support using your Rails app `config.action_controller.asset_host` setting. If you already have [CDN](http://guides.rubyonrails.org/asset_pipeline.html#cdns) added in your Rails app
you don't need to do anything extra for Webpacker, it just works.
## Capistrano
### Assets compiling on every deployment even if JavaScript and CSS files are not changed
Make sure you have `public/packs` and `node_modules` in `:linked_dirs`
```ruby
append :linked_dirs, "log", "tmp/pids", "tmp/cache", "tmp/sockets", "public/packs", ".bundle", "node_modules"
```
If you have `node_modules` added to `:linked_dirs` you'll need to run yarn install before `deploy:assets:precompile`, so you can add this code snippet at the bottom deploy.rb
```ruby
before "deploy:assets:precompile", "deploy:yarn_install"
namespace :deploy do
desc "Run rake yarn install"
task :yarn_install do
on roles(:web) do
within release_path do
execute("cd #{release_path} && yarn install --silent --no-progress --no-audit --no-optional")
end
end
end
end
```
webpacker-5.4.3/docs/assets.md 0000644 0000041 0000041 00000006136 14123265223 016300 0 ustar www-data www-data # Assets
Static assets like images and fonts support is enabled out-of-box
and you can link them into your JavaScript app code and have them
compiled automatically.
## Import from node modules
You can also import styles from `node_modules` using the following syntax.
Please note that your styles will always be extracted into `[pack_name].css`:
```sass
// app/javascript/styles.sass
// ~ to tell webpack that this is not a relative import:
@import '~@material/animation/mdc-animation'
@import '~bootstrap/dist/css/bootstrap'
```
```js
// Your main app pack
// app/javascript/packs/app.js
import '../styles'
```
```erb
<%# In your views %>
<%= javascript_pack_tag 'app' %>
<%= stylesheet_pack_tag 'app' %>
```
## Import from Sprockets using helpers
It's possible to link to assets that have been precompiled by Sprockets. Add the `.erb` extension to your JavaScript file, then you can use Sprockets' asset helpers:
```erb
<%# app/javascript/my_pack/example.js.erb %>
<% helpers = ActionController::Base.helpers %>
const railsImagePath = "<%= helpers.image_path('rails.png') %>"
```
This is enabled by the `rails-erb-loader` loader rule in `config/webpack/loaders/erb.js`.
## Using babel module resolver
You can also use [babel-plugin-module-resolver](https://github.com/tleunen/babel-plugin-module-resolver) to reference assets directly from `app/assets/**`
```bash
yarn add babel-plugin-module-resolver
```
Specify the plugin in your `babel.config.js` with the custom root or alias. Here's an example:
```js
{
plugins: [
[require("babel-plugin-module-resolver").default, {
"root": ["./app"],
"alias": {
"assets": "./assets"
}
}]
]
}
```
And then within your javascript app code:
```js
// Note: we don't have to do any ../../ jazz
import FooImage from 'assets/images/foo-image.png'
import 'assets/stylesheets/bar'
```
## Link in your Rails views
You can also link `js/images/styles/fonts` used within your js app in views using
`asset_pack_path` and `image_pack_tag` helpers. These helpers are useful in cases where you just want to
create a ` ` or ` ` for an asset.
```yml
app/javascript:
- packs
- app.js
- images
- calendar.png
```
```js
// app/javascript/packs/app.js (or any of your packs)
// import all image files in a folder:
require.context('../images', true)
```
```erb
<%# Rails view, for example app/views/layouts/application.html.erb %>
<% # => %>
<%= image_pack_tag 'media/images/calendar.png' %>
<% # => %>
<%# no path resolves to default 'images' folder: %>
<%= image_pack_tag 'calendar.png' %>
<% # => %>
```
Note you need to add a `media/` prefix (not `/media/`) to any subfolder structure you might have in `app/javascript`. See more examples in the [tests](https://github.com/rails/webpacker/blob/0b86cadb5ed921e2c1538382e72a236ec30a5d97/test/helper_test.rb#L37).
webpacker-5.4.3/docs/typescript.md 0000644 0000041 0000041 00000012060 14123265223 017175 0 ustar www-data www-data # TypeScript
## Installation
1. Run the TypeScript installer
```bash
bundle exec rails webpacker:install:typescript
```
After that, a new file called `hello_typescript.ts` will be present in your `packs` directory (or rather the `source_entry_path` of your `webpacker.yml` configuration). You're now ready to write TypeScript.
## (Optional) Adding Compile-Time Type Checking
The default installation only transpiles your TypeScript code using Babel. If you would like to enable type checking as part of the Webpack compilation process (i.e. fail the build if there are TS errors), you can do the following:
1. Install the Fork TS Checker Webpack Plugin
```sh
yarn add --dev fork-ts-checker-webpack-plugin
```
2. Then add it to your development environment config in `config/webpack/development.js`
```js
const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
const path = require("path");
environment.plugins.append(
"ForkTsCheckerWebpackPlugin",
new ForkTsCheckerWebpackPlugin({
typescript: {
configFile: path.resolve(__dirname, "../../tsconfig.json"),
},
async: false,
})
);
```
If you are `fork-ts-checker-webpack-plugin` older than 5.0, the `tsconfig` option also needs to be specified:
```js
const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
const path = require("path");
environment.plugins.append(
"ForkTsCheckerWebpackPlugin",
new ForkTsCheckerWebpackPlugin({
// this is a relative path to your project's TypeScript config
tsconfig: path.resolve(__dirname, "../../tsconfig.json"),
// non-async so type checking will block compilation
async: false,
})
);
```
## Upgrading to 5.1
If you update your App to `webpacker >= 5.1` and had TypeScript installed before, you need to add some new/remove some old configurations:
1. Remove old packages:
- `yarn remove ts-loader`
2. Add new packages:
- `yarn add @babel/preset-typescript`
3. Remove old configuration files:
- Delete this file: `config/webpack/loaders/typescript.js`
4. Remove the following lines from `config/webpack/environment.js`:
- `const typescript = require('./loaders/typescript')`
- `environment.loaders.prepend('typescript', typescript)`
5. Add the TypeScript preset to your `babel.config.js`:
- This line `['@babel/preset-typescript', { 'allExtensions': true, 'isTSX': true }]` has to be added as the last item to the `presets` array in your `babel.config.js`
### Upgrading to 5.1 for Vue users
1. Remove old packages:
- `yarn remove ts-loader pnp-webpack-plugin`
2. Follow point 3 and 4 from the `TypeScript with Vue components` section
## TypeScript with React
1. Setup react using Webpacker [react installer](../README.md#react). Then run the TypeScript installer
```bash
bundle exec rails webpacker:install:typescript
```
2. Rename the generated `hello_react.js` to `hello_react.tsx`. Make the file valid TypeScript and
now you can use TypeScript, JSX with React.
## TypeScript with Vue components
1. Setup Vue using the Webpacker [Vue installer](../README.md#vue). Then run the TypeScript installer
```bash
bundle exec rails webpacker:install:typescript
```
2. Rename generated `hello_vue.js` to `hello_vue.ts`.
3. Install the right Babel preset: `yarn add babel-preset-typescript-vue`
4. Change the generated `babel.config.js` from
```js
["@babel/preset-typescript", { "allExtensions": true, "isTSX": true }]
```
to
```js
["babel-preset-typescript-vue", { "allExtensions": true, "isTSX": true }]
```
and now you can use `
```
```js
document.addEventListener('DOMContentLoaded', () => {
// Get the properties BEFORE the app is instantiated
const node = document.getElementById('hello-vue')
const props = JSON.parse(node.getAttribute('data'))
// Render component with props
new Vue({
render: h => h(App, { props })
}).$mount('#hello-vue');
})
```
You can follow same steps for Angular too.
## Elm
Just like with other implementations, we'll render our data inside a `data`
attribute:
```erb
<%= content_tag :div,
id: "hello-elm",
data: {
message: "Hello",
name: "David"
}.to_json do %>
<% end %>
```
We parse the JSON data and pass it to Elm as flags:
```js
import Elm from '../Main'
document.addEventListener('DOMContentLoaded', () => {
const node = document.getElementById('hello-elm')
const data = JSON.parse(node.getAttribute('data'))
Elm.Main.embed(node, data)
})
```
Defining `Flags` as a `type alias`, we instruct Elm to demand flags `message`
and `name` of type `String` on initialization.
Using `programWithFlags` we bring all the pieces together:
```elm
module Main exposing (..)
import Html exposing (Html, programWithFlags, h1, text)
import Html.Attributes exposing (style)
-- MODEL
type alias Flags =
{ message : String
, name : String
}
type alias Model =
{ message : String
, name : String
}
type Msg
= NoOp
-- INIT
init : Flags -> ( Model, Cmd Msg )
init flags =
let
{ message, name } =
flags
in
( Model message name, Cmd.none )
-- UPDATE
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
NoOp ->
( model, Cmd.none )
-- SUBSCRIPTIONS
subscriptions : Model -> Sub Msg
subscriptions model =
Sub.none
-- VIEW
view : Model -> Html Msg
view model =
h1 [ style [ ( "display", "flex" ), ( "justify-content", "center" ) ] ]
[ text (model.message ++ ", " ++ model.name ++ "!") ]
-- MAIN
main : Program Flags Model Msg
main =
programWithFlags
{ view = view
, init = init
, update = update
, subscriptions = subscriptions
}
```
webpacker-5.4.3/docs/css.md 0000644 0000041 0000041 00000021323 14123265223 015561 0 ustar www-data www-data # CSS, Sass and SCSS
Webpacker supports importing CSS, Sass and SCSS files directly into your JavaScript files.
Importing and loading styles is a two step process:
1. You need to tell webpack which file(s) it has to compile and know how to load
When you do `import '../scss/application.scss'`, you're telling webpack to include `application.scss` in the build. This does not mean it's going to be compiled into your javascript, only that webpack now compiles and knows how to load this file. (How that file compilation is handled is depending on how your loaders (`css-loader`, `sass-loader`, `file-loader`, etc.) are configured.)
2. You need to load those files in your views
In order to have styles load in production, you need to include `stylesheet_pack_tag` with the same name as the javascript file that imports the styles.
When you do `<%= stylesheet_pack_tag 'application' %>`, that's a run-time inclusion from Rails, where Rails gets the correct "asset path" to that file from webpack.
## Import global styles into your JS app
### Importing CSS as a multi-file pack (Webpacker v5)
When you add a CSS/SCSS/SASS file to `app/javascript/packs/` directory, make sure to use the same pack name as its complementary JavaScript pack, e.g. `application.js` and `application.css`. By Webpacker convention (as of Webpacker v5), this will bundle `application.js` and `application.scss` as part of the same entry point (also described as [a multi-file entry point in the webpack docs](https://webpack.js.org/concepts/entry-points/#single-entry-shorthand-syntax)). With this approach, you can avoid importing CSS from JS, if desired.
```
app/
javascript/
packs/
application.js
application.scss
```
### Importing CSS from CSS
You can import additional CSS/SCSS/SASS files from within a CSS file:
```
app/
javascript/
stylesheets/
application.scss
posts.scss
comments.scss
```
```css
/* app/javascript/stylesheets/application.scss */
@import './posts';
@import './comments';
```
### Importing CSS provided by an NPM package from SCSS/CSS
Given your application installs an NPM package that provides CSS, such as `flatpickr`, you can import the CSS file(s) by path from the package directory within `node_modules/`:
```js
/* app/javascript/stylesheets/application.scss */
@import "flatpickr/dist/flatpickr.css"
```
### Importing CSS from JS
```sass
// app/javascript/hello_react/styles/hello-react.sass
.hello-react
padding: 20px
font-size: 12px
```
```js
// React component example
// app/javascript/packs/hello_react.jsx
import React from 'react'
import helloIcon from '../hello_react/images/icon.png'
import '../hello_react/styles/hello-react'
const Hello = props => (
Hello {props.name}!
)
```
### Importing CSS provided by an NPM package from JS
Given your application installs an NPM package that provides CSS, such as `flatpickr`, you can import the CSS file(s) by path from the package directory within `node_modules/`. This is an alternative to importing from within a CSS file, as above:
```js
// app/javascript/packs/application.js
import "flatpickr/dist/flatpickr.css"
```
## Import scoped styles into your JS app
Stylesheets that end with `.module.*` are treated as [CSS Modules](https://github.com/css-modules/css-modules).
```sass
// app/javascript/hello_react/styles/hello-react.module.sass
.helloReact
padding: 20px
font-size: 12px
```
```js
// React component example
// app/javascript/packs/hello_react.jsx
import React from 'react'
import helloIcon from '../hello_react/images/icon.png'
import styles from '../hello_react/styles/hello-react'
const Hello = props => (
Hello {props.name}!
)
```
**Note:** Declared class is referenced as object property in JavaScript.
## Import scoped styles into your TypeScript app
Using CSS modules with a TypeScript application requires a few differences from a JavaScript app. The CSS / Sass files are the same:
```sass
// app/javascript/hello_react/styles/hello-react.module.sass
.helloReact
padding: 20px
font-size: 12px
```
There must also be a type definition file for these styles:
```typescript
export const helloReact: string;
```
You can then import the styles like this:
```typescript
// React component example
// app/javascripts/packs/hello_react.tsx
import React from 'react'
import helloIcon from '../hello_react/images/icon.png'
import * as styles from '../hello_react/styles/hello-react.module.sass'
const Hello = props => (
Hello {props.name}!
)
```
You can automatically generate type definitions for the styles by installing the `typed-scss-modules` as a development dependency:
```
yarn add typed-scss-modules --dev
```
Then by adding these lines to your `package.json`:
```
"scripts": {
"gen-typings": "yarn run tsm app/javascript/**/*.sass",
"watch-typings": "yarn run tsm app/javascript/**/*.sass -w"
},
```
You can generate the typings for the stylesheet by running the command `yarn gen-typings` when you've finished writing CSS, or run `yarn watch-typings` to have it automatically generate them as you go.
## Link styles from your Rails views
Under the hood webpack uses
[mini-css-extract-plugin](https://github.com/webpack-contrib/mini-css-extract-plugin) plugin to extract all the referenced styles within your app and compile it into
a separate `[pack_name].css` bundle so that in your view you can use the
`stylesheet_pack_tag` helper.
```erb
<%= stylesheet_pack_tag 'hello_react' %>
```
Webpacker emits css files only if `extract_css` is set to true in webpacker.yml otherwise `stylesheet_pack_tag` returns nil.
## Add bootstrap
You can use Yarn to add bootstrap or any other modules available on npm:
```bash
yarn add bootstrap
```
Import Bootstrap and theme (optional) CSS in your app/javascript/packs/application.js file:
```js
import 'bootstrap/dist/css/bootstrap'
import 'bootstrap/dist/css/bootstrap-theme'
```
Or in your app/javascript/packs/application.sass file:
```sass
// ~ to tell that this is not a relative import
@import '~bootstrap/dist/css/bootstrap'
@import '~bootstrap/dist/css/bootstrap-theme'
```
## Post-Processing CSS
Webpacker out-of-the-box provides CSS post-processing using
[postcss-loader](https://github.com/postcss/postcss-loader)
and the installer sets up a standard `postcss.config.js`
file in your app root with standard plugins.
```js
module.exports = {
plugins: [
require('postcss-import'),
require('postcss-flexbugs-fixes'),
require('postcss-preset-env')({
autoprefixer: {
flexbox: 'no-2009'
},
stage: 3
})
]
}
```
## Using CSS with [vue-loader](https://github.com/vuejs/vue-loader)
Vue templates require loading the stylesheet in your application in
order for CSS to work. This is in addition to loading the JavaScript
file for the entry point. Loading the stylesheet will also load the
CSS for any nested components.
```erb
<%= stylesheet_pack_tag 'hello_vue' %>
<%= javascript_pack_tag 'hello_vue' %>
```
## Resolve url loader
Since `Sass/libsass` does not provide url rewriting, all linked assets must be relative to the output. Add the missing url rewriting using the resolve-url-loader. Place it directly after the sass-loader in the loader chain.
```bash
yarn add resolve-url-loader
```
```js
// webpack/environment.js
const { environment } = require('@rails/webpacker')
// resolve-url-loader must be used before sass-loader
environment.loaders.get('sass').use.splice(-1, 0, {
loader: 'resolve-url-loader'
});
module.exports = environment
```
## Working with TypeScript
In order to get CSS to work with typescript you have two options.
You can either use `require` to bypass typescript special `import`.
```ts
const styles = require('../hello_react/styles/hello-react');
```
You may also use the package [typings-for-css-modules-loader](https://github.com/Jimdo/typings-for-css-modules-loader) instead of `css-loader` to automatically generate typescript `.d.ts` files in order to help resolve any css/scss styles. To do that:
```js
// app/javascript/packs/hello_react.jsx
import * as styles from '../hello_react.styles/hello-react.module.scss';
```
```bash
yarn add --dev typings-for-css-modules-loader
```
```js
// webpack/environment.js
const { environment } = require('@rails/webpacker')
// replace css-loader with typings-for-css-modules-loader
environment.loaders.get('moduleSass').use = environment.loaders.get('moduleSass').use.map((u) => {
if(u.loader == 'css-loader') {
return { ...u, loader: 'typings-for-css-modules-loader' };
} else {
return u;
}
});
```
webpacker-5.4.3/docs/env.md 0000644 0000041 0000041 00000003507 14123265223 015565 0 ustar www-data www-data # Environment variables
Environment variables are supported out of the box in Webpacker. For example if
you run the webpack dev server like so:
```
FOO=hello BAR=world ./bin/webpack-dev-server
```
You can then reference these variables in your JavaScript app code with
`process.env`:
```js
console.log(process.env.FOO) // Compiles to console.log("hello")
```
You may want to store configuration in environment variables via `.env` files,
similar to the [dotenv Ruby gem](https://github.com/bkeepers/dotenv).
In development, if you use [Foreman](http://ddollar.github.io/foreman) or [Invoker](http://invoker.codemancers.com)
to launch the webpack server, both of these tools have basic support for a
`.env` file (Invoker also supports `.env.local`), so no further configuration
is needed.
However, if you run the webpack server without Foreman/Invoker, or if you
want more control over what `.env` files to load, you can use the
[dotenv npm package](https://github.com/motdotla/dotenv). Here is what you could
do to support a "Ruby-like" dotenv:
```
yarn add dotenv
```
```javascript
// config/webpack/environment.js
...
const { environment } = require('@rails/webpacker')
const webpack = require('webpack')
const dotenv = require('dotenv')
const dotenvFiles = [
`.env.${process.env.NODE_ENV}.local`,
'.env.local',
`.env.${process.env.NODE_ENV}`,
'.env'
]
dotenvFiles.forEach((dotenvFile) => {
dotenv.config({ path: dotenvFile, silent: true })
})
module.exports = environment
```
**Warning:** using Foreman/Invoker and npm dotenv at the same time can result in
confusing behavior, in that Foreman/Invoker variables take precedence over
npm dotenv variables.
If you'd like to pass custom variables to the on demand compiler, use `Webpacker::Compiler.env` attribute.
```rb
Webpacker::Compiler.env['FRONTEND_API_KEY'] = 'your_secret_key'
```
webpacker-5.4.3/docs/docker.md 0000644 0000041 0000041 00000003234 14123265223 016241 0 ustar www-data www-data # Docker
To setup webpacker with a dockerized Rails application.
First, add a new service for webpacker in docker-compose.yml:
```Dockerfile
version: '3'
services:
webpacker:
build: .
environment:
- NODE_ENV=development
- RAILS_ENV=development
- WEBPACKER_DEV_SERVER_HOST=0.0.0.0
command: ./bin/webpack-dev-server
volumes:
- .:/webpacker-example-app
ports:
- '3035:3035'
```
add nodejs and yarn as dependencies in Dockerfile,
```dockerfile
FROM ruby:2.4.1
RUN apt-get update -qq && apt-get install -y build-essential nodejs \
&& rm -rf /var/lib/apt/lists/* \
&& curl -o- -L https://yarnpkg.com/install.sh | bash
# Rest of the commands....
```
Please note: if using `assets:precompile` in the Dockerfile or have issues with the snippet above then try:
```dockerfile
FROM ruby:2.4.1
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash \
&& apt-get update && apt-get install -y nodejs && rm -rf /var/lib/apt/lists/* \
&& curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list \
&& apt-get update && apt-get install -y yarn && rm -rf /var/lib/apt/lists/*
# Rest of the commands....
```
then add the webpacker host name environment variable to the web/app service:
```Dockerfile
web:
build:
context: .
command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
volumes:
- .:/usr/src/app
ports:
- "3000:3000"
environment:
- WEBPACKER_DEV_SERVER_HOST=webpacker
```
Lastly, rebuild your container:
```bash
docker-compose up --build
```
webpacker-5.4.3/docs/webpack-dev-server.md 0000644 0000041 0000041 00000005543 14123265223 020473 0 ustar www-data www-data # webpack-dev-server
## HTTPS
If you're using the `webpack-dev-server` in development, you can serve your packs over HTTPS
by setting the `https` option for `webpack-dev-server` to `true` in `config/webpacker.yml`,
then start the dev server as usual with `./bin/webpack-dev-server`.
Please note that the `webpack-dev-server` will use a self-signed certificate,
so your web browser will display a warning/exception upon accessing the page. If you get
`https://localhost:3035/sockjs-node/info?t=1503127986584 net::ERR_INSECURE_RESPONSE`
in your console, simply open the link in your browser and accept the SSL exception.
Now if you refresh your Rails view everything should work as expected.
## HOT module replacement
Webpacker out-of-the-box supports HMR with `webpack-dev-server` and
you can toggle it by setting `dev_server/hmr` option inside `webpacker.yml`.
Check out this guide for more information:
- https://webpack.js.org/configuration/dev-server/#devserver-hot
To support HMR with React you would need to add `react-hot-loader`. Checkout this guide for
more information:
- https://gaearon.github.io/react-hot-loader/getstarted/
**Note:** Don't forget to disable `HMR` if you are not running `webpack-dev-server`
otherwise you will get not found error for stylesheets.
## Nginx
If you use Nginx in development to proxy requests to your Rails server from
another domain, like `myapp.dev`, the Webpacker middleware will be able to
forward requests for "packs" to the webpack dev server.
If you're using `inline` mode behind Nginx, you may also need to provide the
hostname to webpack dev server so it can initiate the websocket connection for
live reloading ([Webpack
docs](https://webpack.js.org/configuration/dev-server/#devserver-public)).
To do so, set the `public` option in `config/webpacker.yml`:
```yaml
development:
# ...
dev_server:
# ...
public: myapp.dev
```
You may also need to add the following location block to your local Nginx server
configuration for your Rails app.
```
server {
listen 80;
server_name myapp.dev
# Proxy webpack dev server websocket requests
location /sockjs-node {
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://127.0.0.1:3035; # change to match your webpack-dev-server host
}
# ...
}
```
## Customizing Logging
By default, the dev server will display a colored progress notification while
your code is being compiled. (Under the hood, we are using `webpack-dev-server
--progress --color`). However, this might cause issues if you don't use
`foreman` and/or try to log webpack-dev-server's output to a file. You can
disable this stylized output by adding `pretty: false` to your `dev_server`
config:
```yaml
development:
# ...
dev_server:
# ...
pretty: false
```
webpacker-5.4.3/docs/yarn.md 0000644 0000041 0000041 00000001425 14123265223 015743 0 ustar www-data www-data # Yarn
Webpacker by default uses `yarn` as a package manager for `node_modules`
## Add a new npm module
To add any new JS module you can use `yarn`:
```bash
yarn add bootstrap material-ui
```
## Add an npm module to `devDependencies`
To add a new JS module that will only be available to local development:
```bash
yarn add --dev browser-sync
```
Be careful not to add any build or app related JS modules in this fashion. Adding JS modules to `devDependencies` [will block them from being installed in **any** production environment](https://yarnpkg.com/lang/en/docs/cli/install/#toc-yarn-install-production-true-false).
Docs from JS modules may instruct you to use `--dev` or `devDependencies`, but this is generally under the assumption that you are using a `node.js` workflow.
webpacker-5.4.3/docs/cloud9.md 0000644 0000041 0000041 00000026134 14123265223 016175 0 ustar www-data www-data # Webpack dev server and Rails on Cloud9
**Please note that this article is particularly relevant when
migrating the [`webpacker`] gem from v3.0.1 to v3.0.2, as described in
the [below](#binstub-versions).**
[**`[Go to tl;dr]`**](#tldr)
## Contents
- [Context](#context)
- [Binstub versions](#binstub-versions)
- [Quick solution](#quick-solution)
- [Flexible solution](#flexible-solution)
- [Sources](#sources)
- [Versions](#versions)
- [tl;dr](#tldr)
## Context
This article describes how to properly configure
[`webpack-dev-server`] with [`webpacker`] gem on a [Cloud9] workspace.
After a preliminary remark about the proper binstub version of the
`./bin/webpack-dev-server` script, this article presents two ways to
tackle the task: a simple and [quick solution](#quick-solution), which
is sufficient if we work alone on a project, and a slightly more
involved but [flexible approach](#flexible-solution), that can be
useful when several people might work in the same codebase.
[Cloud9]: https://c9.io
[`webpack-dev-server`]: https://github.com/webpack/webpack-dev-server
[`webpacker`]: https://github.com/rails/webpacker
## Binstub versions
A lot of the confusion about the [`webpack-dev-server`] options and
why they might not be properly taken into account, might be due to an
outdated version of the `./bin/webpack-dev-server` script. The script
created by the `rails webpacker:install` task of the [`webpacker`] gem
v3.0.1 ([source][v3.0.1/lib/install/bin/webpack-dev-server.tt]) is not
compatible with how v3.0.2 (sic) of the gem handles the
[`webpack-dev-server`] option flags (see full list of
[versions](#versions) below), which logically expects the
corresponding [binstub version][#833] of the script
([source][v3.0.2/exe/webpack-dev-server]). So please make sure that
you are using the [correct binstub][v3.0.2/exe/webpack-dev-server]
(the same applies to [`./bin/webpack`][v3.0.2/exe/webpack]). To be
fair, the [changelog of v3.0.2] properly mentions the change:
> - Added: Binstubs [#833]
> - (...)
> - Removed: Inline CLI args for dev server binstub, use env variables
instead
[changelog of v3.0.2]: https://github.com/rails/webpacker/blob/v3.0.2/CHANGELOG.md#302---2017-10-04
[v3.0.1/lib/install/bin/webpack-dev-server.tt]: https://github.com/rails/webpacker/blob/v3.0.1/lib/install/bin/webpack-dev-server.tt
[v3.0.2/exe/webpack-dev-server]: https://github.com/rails/webpacker/blob/v3.0.2/exe/webpack-dev-server
[v3.0.2/exe/webpack]: https://github.com/rails/webpacker/blob/v3.0.2/exe/webpack
[#833]: https://github.com/rails/webpacker/pull/833/files
## Quick solution
If you are working alone, the easiest way to fix the configuration of
the [`webpack-dev-server`] is to modify the `development.dev_server`
entry of the `config/webpacker.yml` file.
### `config/webpacker.yml` file
The `development.dev_server` entry of the `config/webpacker.yml` file
has to be changed from the following default values:
```yaml
dev_server:
https: false
host: localhost
port: 3035
public: localhost:3035
hmr: false
# Inline should be set to true if using HMR
inline: true
overlay: true
disable_host_check: true
use_local_ip: false
```
into these custom configuration:
```yaml
dev_server:
https: true
host: localhost
port: 8082
public: your-workspace-name-yourusername.c9users.io:8082
hmr: false
inline: false
overlay: true
disable_host_check: true
use_local_ip: false
```
You can obtain the value `your-workspace-name-yourusername.c9users.io`
for your [Cloud9] workspace with `echo ${C9_HOSTNAME}`.
There are four main differences with the approaches found in the
mentioned [sources](#sources):
- Some solutions suggested to set the [`host`][devserver-host] option
to `your-workspace-name-yourusername.c9users.io`, which required to
add a line to the `/etc/hosts` file by running `echo "0.0.0.0
${C9_HOSTNAME}" | sudo tee -a /etc/hosts`. This was only necessary
due to restrictions in previous versions of [`webpacker`] and how
the value of the [`public`][devserver-public] setting was
calculated. Currently it is [no longer necessary][pr-comment-hosts]
to modify the `/etc/hosts` file because the [`host`][devserver-host]
setting can be kept as `localhost`.
[pr-comment-hosts]: https://github.com/rails/webpacker/pull/1033#pullrequestreview-78992024
- Some solutions stressed the need to set the
[`https`][devserver-https] option to `false` but this failed with
`net::ERR_ABORTED` in the browser console and raised the following
exception in the server when the client tried to get the
JavaScript sources:
```
#
```
Setting `https: true` removes the issue.
- By leaving the [`inline`][devserver-inline] option to the default
`false` value, the live compilation still works but the browser
console constantly reports the following error:
```
Failed to load https://your-workspace-name-yourusername.c9users.io:8082/sockjs-node/info?t=1511016561187: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'https://your-workspace-name-yourusername.c9users.io' is therefore not allowed access. The response had HTTP status code 503.
```
Setting `inline: false` removes the issue.
- None of the solutions suggested to set the
[`public`][devserver-public] option in the `config/webpacker.yml`
file and some suggested to pass it to the `webpack-dev-server`
command line. By setting it in the configuration file we don't need
to care about it in the terminal.
[devserver-host]: https://webpack.js.org/configuration/dev-server/#devserver-host
[devserver-https]: https://webpack.js.org/configuration/dev-server/#devserver-https
[devserver-inline]: https://webpack.js.org/configuration/dev-server/#devserver-inline
[devserver-public]: https://webpack.js.org/configuration/dev-server/#devserver-public
With this configuration, running as usual `./bin/webpack-dev-server`
in one terminal and `./bin/rails s -b $IP -p $PORT` in another should
work.
## Flexible solution
The previous solution is useful and fast to implement, but if you are
working with other people on the same repo it can be tricky to
maintain the proper configuration in the `config/webpacker.yml` file.
Moreover, the hostname of your [Cloud9] workspace is hardcoded, so
that the configuration is not portable.
A hint about another way to configure the `webpack-dev-server` can be
found in the [README of this repo][`webpacker` documentation]:
> You can use environment variables as options supported by
> webpack-dev-server in the form `WEBPACKER_DEV_SERVER_`.
> Please note that these environment variables will always take
> precedence over the ones already set in the configuration file.
Note that when the configuration of the [`webpack-dev-server`] is
tweaked with ENV variables, those same values _have to be passed_ to
the `rails server` process as well in order to let it use the _same_
configuration.
Taking that into account, a flexible solution can be implemented using
[`foreman`] with the following `Procfile.dev`:
[`foreman`]: https://github.com/ddollar/foreman
```Procfile
web: ./bin/rails server -b ${RAILS_SERVER_BINDING:-localhost} -p ${RAILS_SERVER_PORT:-3000}
webpacker: ./bin/webpack-dev-server
```
and this `bin/start` script:
```bash
#!/bin/bash
# Immediately exit script on first error
set -e -o pipefail
APP_ROOT_FOLDER="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"
cd "${APP_ROOT_FOLDER}"
if [ -n "${C9_USER}" ]; then
# We are in a Cloud9 machine
# Make sure that Postgres is running
sudo service postgresql status || sudo service postgresql start
# Adapt the configuration of the webpack-dev-server
export APP_DOMAIN="${C9_HOSTNAME}"
export RAILS_SERVER_BINDING='0.0.0.0'
export RAILS_SERVER_PORT='8080'
export WEBPACKER_DEV_SERVER_PORT='8082'
export WEBPACKER_DEV_SERVER_HTTPS='true'
export WEBPACKER_DEV_SERVER_HOST="localhost"
export WEBPACKER_DEV_SERVER_PUBLIC="${C9_HOSTNAME}:${WEBPACKER_DEV_SERVER_PORT}"
export WEBPACKER_DEV_SERVER_HMR='false'
export WEBPACKER_DEV_SERVER_INLINE='false'
export WEBPACKER_DEV_SERVER_OVERLAY='true'
export WEBPACKER_DEV_SERVER_DISABLE_HOST_CHECK='true'
export WEBPACKER_DEV_SERVER_USE_LOCAL_IP='false'
fi
foreman start -f Procfile.dev
```
With these two scripts in place, the application can always be started
by running `bin/start`, in both [Cloud9] and other systems. The
trick is that by exporting the `WEBPACKER_DEV_SERVER_*` variables
before calling `foreman start`, we make sure that those values are
available to both `webpack-dev-server` and `rails server` processes.
## Sources
- ["Webpack dev server and Rails on Cloud9"][original-article] (the
original source for the present article, inspired by this
[comment][original-comment])
- ["Making Webpacker run on Cloud 9"] (GitHub issue)
- ["Anyone here got webpack-dev-server to work on Cloud 9?"] (GitHub issue)
- [`webpacker` documentation]
- [`webpacker/dev_server.rb` code]
- [`webpack-dev-server` documentation]
- ["Using Rails With Webpack in Cloud 9"] (blog article)
[original-article]: http://rbf.io/en/blog/2017/11/18/webpack-dev-server-and-rails-on-cloud9/
[original-comment]: https://github.com/rails/webpacker/issues/176#issuecomment-345532309
["Making Webpacker run on Cloud 9"]: https://github.com/rails/webpacker/issues/176
["Anyone here got webpack-dev-server to work on Cloud 9?"]: https://github.com/webpack/webpack-dev-server/issues/230
[`webpacker` documentation]: https://github.com/rails/webpacker/tree/v3.0.2#development
[`webpacker/dev_server.rb` code]: https://github.com/rails/webpacker/blob/v3.0.2/lib/webpacker/dev_server.rb#L55
[`webpack-dev-server` documentation]: https://webpack.js.org/configuration/dev-server/
["Using Rails With Webpack in Cloud 9"]: http://aalvarez.me/blog/posts/using-rails-with-webpack-in-cloud-9.html
## Versions
Since things in this ecosystem move fast, it's important to mention the
versions of the world for which this documentation is relevant:
```shell
$ egrep '^ ?(ruby|webpacker|rails) ' Gemfile.lock
rails (5.1.4)
webpacker (3.0.2)
ruby 2.4.2p198
$ yarn versions
yarn versions v1.1.0
{ http_parser: '2.7.0',
node: '8.5.0',
v8: '6.0.287.53',
uv: '1.14.1',
zlib: '1.2.11',
ares: '1.10.1-DEV',
modules: '57',
nghttp2: '1.25.0',
openssl: '1.0.2l',
icu: '59.1',
unicode: '9.0',
cldr: '31.0.1',
tz: '2017b' }
$ cat /etc/os-release | head -6
NAME="Ubuntu"
VERSION="14.04.5 LTS, Trusty Tahr"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 14.04.5 LTS"
VERSION_ID="14.04"
```
Everything was tested using Chrome Version 62.
## tl;dr
1. Make sure that you are running the [proper binstub
version](#binstub-versions) of `./bin/webpack-dev-server`.
1. Change the `development.dev_server` entry `config/webpacker.yml` file into:
```yaml
dev_server:
https: true
host: localhost
port: 8082
public: your-workspace-name-yourusername.c9users.io:8082
hmr: false
inline: false
overlay: true
disable_host_check: true
use_local_ip: false
```
1. Now running as usual `./bin/webpack-dev-server` in one terminal and
`./bin/rails s -b $IP -p $PORT` in another should work as expected.
webpacker-5.4.3/docs/webpack.md 0000644 0000041 0000041 00000025447 14123265223 016420 0 ustar www-data www-data # webpack
## Configuration
Webpacker gives you a default set of configuration files for test, development and
production environments in `config/webpack/*.js`. You can configure each individual
environment in their respective files or configure them all in the base
`config/webpack/environment.js` file.
By default, you don't need to make any changes to `config/webpack/*.js`
files since it's all standard production-ready configuration. However,
if you do need to customize or add a new loader, this is where you would go.
Here is how you can modify webpack configuration:
```js
// config/webpack/custom.js
module.exports = {
resolve: {
alias: {
jquery: 'jquery/src/jquery',
vue: 'vue/dist/vue.js',
React: 'react',
ReactDOM: 'react-dom',
vue_resource: 'vue-resource/dist/vue-resource',
}
}
}
// config/webpack/environment.js
const { environment } = require('@rails/webpacker')
const customConfig = require('./custom')
// Set nested object prop using path notation
environment.config.set('resolve.extensions', ['.foo', '.bar'])
environment.config.set('output.filename', '[name].js')
// Merge custom config
environment.config.merge(customConfig)
environment.config.merge({ devtool: 'none' })
// Delete a property
environment.config.delete('output.chunkFilename')
module.exports = environment
```
If you need access to configs within Webpacker's configuration,
you can import them like so:
```js
const { config } = require('@rails/webpacker')
console.log(config.output_path)
console.log(config.source_path)
```
## Loaders
You can add additional loaders beyond the base set that Webpacker provides by
adding it to your environment. We'll use `json-loader` as an example:
```
yarn add json-loader
```
```js
// config/webpack/environment.js
const { environment } = require('@rails/webpacker')
const jsonLoader = {
test: /\.json$/,
use: 'json-loader'
}
// Insert json loader at the end of list
environment.loaders.append('json', jsonLoader)
// Insert json loader at the top of list
environment.loaders.prepend('json', jsonLoader)
// Insert json loader after/before a given loader
environment.loaders.insert('json', jsonLoader, { after: 'style'} )
environment.loaders.insert('json', jsonLoader, { before: 'babel'} )
module.exports = environment
```
Finally add `.json` to the list of extensions in `config/webpacker.yml`. Now if you `import()` any `.json` files inside your JavaScript
they will be processed using `json-loader`. Voila!
You can also modify the loaders that Webpacker pre-configures for you. We'll update
the `babel` loader as an example:
```js
// config/webpack/environment.js
const { environment } = require('@rails/webpacker')
const babelLoader = environment.loaders.get('babel')
babelLoader.options.cacheDirectory = false
module.exports = environment
```
### Coffeescript 2
Out of the box webpacker supports coffeescript 1,
but here is how you can use Coffeescript 2:
```
yarn add coffeescript@2.0.1
```
```js
// config/webpack/environment.js
const { environment } = require('@rails/webpacker')
const babelLoader = environment.loaders.get('babel')
// Replace existing coffee loader with CS2 version
environment.loaders.insert('coffee', {
test: /\.coffee(\.erb)?$/,
use: babelLoader.use.concat(['coffee-loader'])
})
module.exports = environment
```
### React SVG loader
To use react svg loader, you should append svg loader before file loader:
```js
const { environment } = require('@rails/webpacker')
const babelLoader = environment.loaders.get('babel')
environment.loaders.insert('svg', {
test: /\.svg$/,
use: babelLoader.use.concat([
{
loader: 'react-svg-loader',
options: {
jsx: true // true outputs JSX tags
}
}
])
}, { before: 'file' })
const fileLoader = environment.loaders.get('file')
fileLoader.exclude = /\.(svg)$/i
```
### Url Loader
```js
// config/webpack/loaders/url.js
module.exports = {
test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
use: [{
loader: 'url-loader',
options: {
limit: 10000,
name: '[name]-[hash].[ext]'
}
}]
}
// config/webpack/environment.js
const { environment } = require('@rails/webpacker')
const url = require('./loaders/url')
environment.loaders.prepend('url', url)
// avoid using both file and url loaders
environment.loaders.get('file').test = /\.(tiff|ico|svg|eot|otf|ttf|woff|woff2)$/i
```
### Overriding Loader Options in webpack 3+ (for CSS Modules etc.)
In webpack 3+, if you'd like to specify additional or different options for a loader, edit `config/webpack/environment.js` and provide an options object to override. This is similar to the technique shown above, but the following example shows specifically how to apply CSS Modules, which is what you may be looking for:
```javascript
const { environment } = require('@rails/webpacker')
const merge = require('webpack-merge')
const myCssLoaderOptions = {
modules: {
localIdentName: '[name]__[local]___[hash:base64:5]'
},
sourceMap: true,
}
const CSSLoader = environment.loaders.get('sass').use.find(el => el.loader === 'css-loader')
CSSLoader.options = merge(CSSLoader.options, myCssLoaderOptions)
module.exports = environment
```
See [issue #756](https://github.com/rails/webpacker/issues/756#issuecomment-327148547) for additional discussion of this.
For this to work, don't forget to use the `stylesheet_pack_tag`, for example:
```
<%= stylesheet_pack_tag 'YOUR_PACK_NAME_HERE' %>
```
## Plugins
The process for adding or modifying webpack plugins is the same as the process
for loaders above:
```js
// config/webpack/environment.js
const { environment } = require('@rails/webpacker')
const webpack = require('webpack')
// Get a pre-configured plugin
const manifestPlugin = environment.plugins.get('Manifest')
manifestPlugin.options.writeToFileEmit = false
// Add an additional plugin of your choosing : ProvidePlugin
environment.plugins.prepend(
'Provide',
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
jquery: 'jquery',
'window.Tether': 'tether',
Popper: ['popper.js', 'default'],
ActionCable: 'actioncable',
Vue: 'vue',
VueResource: 'vue-resource',
})
)
// Insert before a given plugin
environment.plugins.insert('CommonChunkVendor',
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor', // Vendor code
minChunks: (module) => module.context && module.context.indexOf('node_modules') !== -1
})
, { before: 'manifest' })
module.exports = environment
```
## Resolved modules
To add new paths to `resolve.modules`, the API is same as loaders and plugins:
```js
const { environment } = require('@rails/webpacker')
// Resolved modules list API - prepend, append, insert
environment.resolvedModules.append('vendor', 'vendor')
```
### Add SplitChunks (Webpack V4)
Originally, chunks (and modules imported inside them) were connected by a parent-child relationship in the internal webpack graph. The CommonsChunkPlugin was used to avoid duplicated dependencies across them, but further optimizations were not possible.
Since webpack v4, the CommonsChunkPlugin was removed in favor of optimization.splitChunks.
For the full configuration options of SplitChunks, see the [Webpack documentation](https://webpack.js.org/plugins/split-chunks-plugin/).
```js
// config/webpack/environment.js
// Enable the default config
environment.splitChunks()
// or using custom config
environment.splitChunks((config) => Object.assign({}, config, { optimization: { splitChunks: false }}))
```
Then use the `javascript_packs_with_chunks_tag` and `stylesheet_packs_with_chunks_tag` helpers to include all the transpiled
packs with the chunks in your view, which creates html tags for all the chunks.
```erb
<%= javascript_packs_with_chunks_tag 'calendar', 'map', 'data-turbolinks-track': 'reload' %>
```
**Important:** Pass all your pack names when using this helper otherwise you will
get duplicated chunks on the page.
```erb
<%# DO %>
<%= javascript_packs_with_chunks_tag 'calendar', 'map' %>
<%# DON'T %>
<%= javascript_packs_with_chunks_tag 'calendar' %>
<%= javascript_packs_with_chunks_tag 'map' %>
```
For the old configuration with the CommonsChunkPlugin see below. **Note** that this functionality is deprecated in Webpack V4.
#### Preloading
Before preload or prefetch your assets, please read [https://developer.mozilla.org/en-US/docs/Web/HTML/Preloading_content](https://developer.mozilla.org/en-US/docs/Web/HTML/Preloading_content).
Webpack also provide it's own methods for preload or prefetch [https://medium.com/webpack/link-rel-prefetch-preload-in-webpack-51a52358f84c](https://medium.com/webpack/link-rel-prefetch-preload-in-webpack-51a52358f84c).
You can preload your assets with the `preload_pack_asset` helper if you have Rails >= 5.2.x.
```erb
<%= preload_pack_asset 'fonts/fa-regular-400.woff2' %>
```
**Warning:** You don't want to preload the css, you want to preload the fonts and images inside the css so that fonts, css, and images can all be downloaded in parallel instead of waiting for the browser to parse the css.
### Add common chunks (deprecated in Webpack V4)
The CommonsChunkPlugin is an opt-in feature that creates a separate file (known as a chunk), consisting of common modules shared between multiple entry points. By separating common modules from bundles, the resulting chunked file can be loaded once initially, and stored in the cache for later use. This results in page speed optimizations as the browser can quickly serve the shared code from the cache, rather than being forced to load a larger bundle whenever a new page is visited.
Add the plugins in `config/webpack/environment.js`:
```js
const webpack = require('webpack')
environment.plugins.append(
'CommonsChunkVendor',
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks: (module) => {
// this assumes your vendor imports exist in the node_modules directory
return module.context && module.context.indexOf('node_modules') !== -1
}
})
)
environment.plugins.append(
'CommonsChunkManifest',
new webpack.optimize.CommonsChunkPlugin({
name: 'manifest',
minChunks: Infinity
})
)
```
Now, add these files to your `layouts/application.html.erb`:
```erb
<%# Head %>
<%= javascript_pack_tag "manifest" %>
<%= javascript_pack_tag "vendor" %>
<%# If importing any styles from node_modules in your JS app %>
<%= stylesheet_pack_tag "vendor" %>
```
More detailed guides available here: [webpack guides](https://webpack.js.org/guides/)
webpacker-5.4.3/docs/misc.md 0000644 0000041 0000041 00000000726 14123265223 015730 0 ustar www-data www-data # How-Tos
## Ignoring swap files
If you are using vim or emacs and want to ignore certain files you can add `ignore-loader`:
```
yarn add ignore-loader
```
and add `ignore-loader` to `config/webpack/environment.js`
```js
// ignores vue~ swap files
const { environment } = require('@rails/webpacker')
environment.loaders.append('ignore', {
test: /.vue~$/,
loader: 'ignore-loader'
})
```
And now all files with `.vue~` will be ignored by the webpack compiler.
webpacker-5.4.3/docs/v4-upgrade.md 0000644 0000041 0000041 00000016007 14123265223 016752 0 ustar www-data www-data # Webpacker Upgrade Guide
To update a Webpacker v3.5 app to v4, follow these steps:
1. Update the `webpacker` gem and the `@rails/webpacker` package to v4. This will upgrade Webpack itself from 3.x to 4.x, make sure you're aware of [any deprecations which might effect you](https://webpack.js.org/migrate/4/). Also make sure any other packages you depend on support Webpack 4 and don't require any changes, e.g. if you explicitly include `webpack` you need to upgrade it to 4.x, and if you use `webpack-dev-server` you need to upgrade it to 3.x.
2. Browser support definitions have been moved from [`.browserslistrc`](../lib/install/config/.browserslistrc) to `/`.
3. Merge any differences between [`config/webpacker.yml`](../lib/install/config/webpacker.yml) and your `config/webpacker.yml`.
4. Webpacker v4 upgrades Babel to [v7](https://babeljs.io/docs/en/v7-migration), see also [the release blog post](https://babeljs.io/blog/2018/08/27/7.0.0). Many packages were moved to the `@babel/` namespace, any babel plugins you have will need to be updated. It may be worth checking out [babel-upgrade](https://github.com/babel/babel-upgrade) if you have problems. ([#1564](https://github.com/rails/webpacker/pull/1564))
5. `.babelrc` should be replaced with `babel.config.js` and `.postcssrc.yml` should be replaced with `postcss.config.js` ([#1822](https://github.com/rails/webpacker/pull/1822)). If you never changed these files from their defaults, the versions of [babel.config.js](../lib/install/config/babel.config.js) and [postcss.config.js](../lib/install/config/postcss.config.js) in the webpacker repository should be usable.
6. Due to the change in [#1625](https://github.com/rails/webpacker/pull/1625), you'll want to make sure that `extract_css` is set to true for the `default` environment in `webpacker.yml` if you want to have Webpacker supply your CSS.
## SplitChunks Configuration
If you used the `CommonsChunkPlugin` you'll need to upgrade to using the new `splitChunks`.
Originally, chunks (and modules imported inside them) were connected by a parent-child relationship in the internal Webpack graph. The `CommonsChunkPlugin` was used to avoid duplicated dependencies across them, but further optimizations were not possible.
In Webpack v4, the `CommonsChunkPlugin` was removed in favor of `optimization.splitChunks`.
For the full configuration options of `splitChunks`, see the [Webpack documentation](https://webpack.js.org/plugins/split-chunks-plugin/).
```js
// config/webpack/environment.js
const WebpackAssetsManifest = require('webpack-assets-manifest');
// Enable the default config
environment.splitChunks()
// or using custom config
environment.splitChunks((config) => Object.assign({}, config, { optimization: { splitChunks: false }}))
```
Then use the `javascript_packs_with_chunks_tag` and `stylesheet_packs_with_chunks_tag` helpers to include all the transpiled
packs with the chunks in your view, which creates html tags for all the chunks.
```erb
<%= javascript_packs_with_chunks_tag 'calendar', 'map', 'data-turbolinks-track': 'reload' %>
```
**Important:** Pass all your pack names to the helper otherwise you will get duplicated chunks on the page.
```erb
<%# DO %>
<%= javascript_packs_with_chunks_tag 'calendar', 'map' %>
<%# DON'T %>
<%= javascript_packs_with_chunks_tag 'calendar' %>
<%= javascript_packs_with_chunks_tag 'map' %>
```
## Package-Specific Notes
- If you're using React, you need to add `"@babel/preset-react"`, to the list of `presets` in your babel config.
- If you're using Vue Loader, you'll need to upgrade to [v15](https://vue-loader.vuejs.org/migrating.html) for Webpack 4.
- To see what Webpacker generates for a given framework with v4, you may want to re-run `bundle exec rake webpacker:install:FRAMEWORK` and let it override the files for your given JavaScript framework, and then compare them to see what changes you'll need to make.
## Excluding node_modules From Being Transpiled By Babel-Loader
One change to take into consideration, is that Webpacker 4 transpiles the
`node_modules` folder with the `babel-loader`. This folder used to be ignored by
Webpacker 3. The new behavior helps in case some library contains ES6 code, but in
some cases it can lead to issues. To avoid running `babel-loader` in the
`node_modules` folder, replicating the same behavior as Webpacker 3, the
following code can be added to `config/webpack/environment.js`:
```javascript
environment.loaders.delete('nodeModules')
```
Alternatively, in order to skip only a specific library in the `node_modules`
folder, this code can be added:
```javascript
const nodeModulesLoader = environment.loaders.get('nodeModules')
if (!Array.isArray(nodeModulesLoader.exclude)) {
nodeModulesLoader.exclude = (nodeModulesLoader.exclude == null)
? []
: [nodeModulesLoader.exclude]
}
nodeModulesLoader.exclude.push(/some-library/) // replace `some-library` with
// the actual path to exclude
```
## Source Maps Enabled By Default
Source maps are now enabled in production to make debugging in production easier. Enabling source maps doesn't have drawbacks for most of the applications since maps are compressed by default and aren't loaded by browsers unless Dev Tools are opened.
If you want to keep the old behavior source maps can be disabled in any environment configuration, e.g:
```js
// config/webpack/production.js
const environment = require('./environment')
environment.config.merge({ devtool: false })
module.exports = environment.toWebpackConfig()
```
## Namespaces
The compiled packs in the public directory are now stored under namespaces:
- JavaScripts are stored under `js`
- Stylesheets are stored under `css`
- Other resources are stored under `media`
```rb
# Before
"runtime~hello_react" => "/packs/runtime~hello_react-da2baf7fd07b0e8b6d17.js"
# After
"runtime~hello_react" => "/packs/js/runtime~hello_react-da2baf7fd07b0e8b6d17.js"
```
## Upgrading projects with custom Webpack setups that use only the view helpers
The default value for `extract_css` is **false** in `config/webpack.yml`. Custom webpack builds that extract the CSS such as often used with [React on Rails](https://github.com/shakacode/react_on_rails) should set this value to true or else no CSS link tags are generated.
```yml
default: &default
# other stuff
extract_css: true
# by default, extract and emit a css file. The default is false
```
## Example Upgrades
This is what an upgrade to Webpacker 4 looked like for existing Rails apps (please contribute yours!):
- https://github.com/connorshea/ContinueFromCheckpoint/pull/77
webpacker-5.4.3/docs/integrations.md 0000644 0000041 0000041 00000015005 14123265223 017477 0 ustar www-data www-data # Integrations
Webpacker ships with basic out-of-the-box integration for React, Angular, Vue and Elm.
You can see a list of available commands/tasks by running `bundle exec rails webpacker`:
## React
To use Webpacker with [React](https://facebook.github.io/react/), create a
new Rails 5.1+ app using `--webpack=react` option:
```bash
# Rails 5.1+
rails new myapp --webpack=react
```
(or run `bundle exec rails webpacker:install:react` in an existing Rails app already
setup with Webpacker).
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
To use Webpacker with [Angular](https://angular.io/), create a
new Rails 5.1+ app using `--webpack=angular` option:
```bash
# Rails 5.1+
rails new myapp --webpack=angular
```
(or run `bundle exec rails webpacker:install:angular` on a Rails app already
setup with Webpacker).
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
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 your
development environment. This can be done in the `config/initializers/content_security_policy.rb`
with the following code:
```ruby
Rails.application.config.content_security_policy do |policy|
if Rails.env.development?
policy.script_src :self, :https, :unsafe_eval
else
policy.script_src :self, :https
end
end
```
## Vue
To use Webpacker with [Vue](https://vuejs.org/), create a
new Rails 5.1+ app using `--webpack=vue` option:
```bash
# 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 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'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
Rails.application.config.content_security_policy do |policy|
if Rails.env.development?
policy.script_src :self, :https, :unsafe_eval
else
policy.script_src :self, :https
end
end
```
You can read more about this in the [Vue docs](https://vuejs.org/v2/guide/installation.html#CSP-environments).
### Lazy loading integration
See [docs/es6](es6.md) to know more about Webpack and Webpacker configuration.
For instance, you can lazy load Vue JS components:
Before:
```js
import Vue from 'vue'
import { VCard } from 'vuetify/lib'
Vue.component('VCard', VCard)
```
After:
```js
import Vue from 'vue'
// With destructuring assignment
Vue.component('VCard', import('vuetify/lib').then(({ VCard }) => VCard)
// Or without destructuring assignment
Vue.component('OtherComponent', () => import('./OtherComponent'))
```
You can use it in a Single File Component as well:
```html
...
```
By wrapping the import function into an arrow function, Vue will execute it only when it gets requested, loading the module in that moment.
##### Automatic registration
```js
/**
* The following block of code may be used to automatically register your
* Vue components. It will recursively scan this directory for the Vue
* components and automatically register them with their "basename".
*
* Eg. ./components/OtherComponent.vue ->
* Eg. ./UI/ButtonComponent.vue ->
*/
const files = require.context('./', true, /\.vue$/i)
files.keys().map(key => {
const component = key.split('/').pop().split('.')[0]
// With Lazy Loading
Vue.component(component, () => import(`${key}`))
// Or without Lazy Loading
Vue.component(component, files(key).default)
})
```
## Elm
To use Webpacker with [Elm](http://elm-lang.org), create a
new Rails 5.1+ app using `--webpack=elm` option:
```
# Rails 5.1+
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 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.
## Svelte
To use Webpacker with [Svelte](https://svelte.dev), create a
new Rails 5.1+ app using `--webpack=svelte` option:
```
# Rails 5.1+
rails new myapp --webpack=svelte
```
(or run `bundle exec rails webpacker:install:svelte` on a Rails app already setup with Webpacker).
Please play with the [Svelte Tutorial](https://svelte.dev/tutorial/basics) or learn more about its API at https://svelte.dev/docs
## Stimulus
To use Webpacker with [Stimulus](http://stimulusjs.org), create a
new Rails 5.1+ app using `--webpack=stimulus` option:
```
# Rails 5.1+
rails new myapp --webpack=stimulus
```
(or run `bundle exec rails webpacker:install:stimulus` on a Rails app already setup with Webpacker).
Please read [The Stimulus Handbook](https://stimulusjs.org/handbook/introduction) or learn more about its source code at https://github.com/stimulusjs/stimulus
## CoffeeScript
To add [CoffeeScript](http://coffeescript.org/) support,
run `bundle exec rails webpacker:install:coffee` on a Rails app already
setup with Webpacker.
An example `hello_coffee.coffee` file will also be added to your project
in `app/javascript/packs` so that you can experiment with CoffeeScript right away.
## Erb
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
javascript right away.
webpacker-5.4.3/docs/testing.md 0000644 0000041 0000041 00000010026 14123265223 016444 0 ustar www-data www-data # Testing
## Karma setup for Typescript
Webpacker does not setup `Karma` by default, so you've to manually install it along with its dependencies as per your need. Following things marked as optional can be used to fancify the test results (Recommended).
```js
// package.json
"scripts": {
"test": "NODE_ENV=test karma start"
},
"dependencies": {
"typescript": "^2.5.2"
},
"devDependencies": {
"karma": "^1.7.1",
"karma-webpack": "^2.0.4",
"karma-chrome-launcher": "^2.2.0",
"karma-jquery": "^0.2.2",
"karma-jasmine": "^1.1.0",
"karma-jasmine-jquery": "^0.1.1",
"jasmine-core": "^2.8.0",
[optional] "karma-coverage": "^1.1.1",
[optional] "karma-coverage-istanbul-reporter": "^1.3.0",
[optional] "karma-spec-reporter": "0.0.31",
[optional] "istanbul-instrumenter-loader": "^3.0.0",
}
```
It is beneficial to use the same webpack configuration file (generated by webpacker) in Karma configuration to avoid redundancy. Following line tells Karma not to write transpiled source files onto filesystem while testing to avoid `Error: EACCES: permission denied, mkdir '/_karma_webpack_' ` error. Then inject a new rule a.k.a. loader in the existing ones (needed only if you have installed `istanbul-instrumenter-loader`) to generate a coverage report under `/coverage` directory.
```js
// config/webpack/test.js
const environment = require('./environment')
environment.plugins.get('Manifest').options.writeToFileEmit = process.env.NODE_ENV !== 'test'
environment.loaders.append('istanbul-instrumenter', {
test: /\.ts$/,
enforce: "post",
loader: "istanbul-instrumenter-loader",
query: {
esModules: true
},
exclude: ["node_modules", /\.test\.ts$/]
}) /* optional */
module.exports = environment.toWebpackConfig()
```
Finally, update `karma.conf.js` to read the same `test.js` file mentioned above. Rest of the things are mandatory (few marked as optional wherever appropriate).
```js
// karma.conf.js
const webpackConfig = require('./config/webpack/test.js')
module.exports = function(config) {
config.set({
basePath: "",
frameworks: ["jquery-3.2.1", "jasmine-jquery", "jasmine"],
plugins: [
"karma-jquery",
"karma-jasmine-jquery",
"karma-jasmine",
"karma-webpack",
"karma-chrome-launcher",
"karma-coverage-istanbul-reporter" /* optional */,
"karma-spec-reporter" /* optional */
],
files: [ "/* add spec files */" ],
exclude: [],
webpack: webpackConfig,
preprocessors: {"/* add spec files */" : ["webpack"]},
mime: { "text/x-typescript": ["ts"] },
reporters: ["progress", "coverage-istanbul" /* optional */],
coverageIstanbulReporter: {
reports: [ 'html', 'lcovonly', 'text-summary' ],
fixWebpackSourcePaths: true
} /* optional */,
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ["Chrome"],
singleRun: true
});
};
```
## Lazy compilation
Webpacker lazily compiles assets in test env so you can write your tests without any extra
setup and everything will just work out of the box.
Here is a sample system test case with hello_react example component:
```js
// Example React component
import React from 'react'
import ReactDOM from 'react-dom'
import PropTypes from 'prop-types'
const Hello = props => (
Hello David
)
document.addEventListener('DOMContentLoaded', () => {
ReactDOM.render(
,
document.body.appendChild(document.createElement('div')),
)
})
```
```erb
<%# views/pages/home.html.erb %>
<%= javascript_pack_tag "hello_react" %>
```
```rb
# Tests example React component
require "application_system_test_case"
class HomesTest < ApplicationSystemTestCase
test "can see the hello message" do
visit root_url
assert_selector "h5", text: "Hello! David"
end
end
```
## Capybara setup for Rails
Make sure you configure Rails to serve static files from the public directory in the test environment.
```rb
# config/environments/test.rb
# Configure public file server for tests with Cache-Control for performance.
config.public_file_server.enabled = true
```
webpacker-5.4.3/.eslintignore 0000644 0000041 0000041 00000000060 14123265223 016215 0 ustar www-data www-data lib/*
node_modules/*
vendor/*
**/__tests__/**/*
webpacker-5.4.3/.travis.yml 0000644 0000041 0000041 00000001543 14123265223 015632 0 ustar www-data www-data language: ruby
dist: xenial
before_install:
- gem install rubygems-update && update_rubygems
- yes | rvm @global do gem install bundler -v 2.1.4 || true
rvm:
- 2.4.9
- 2.5.5
- 2.6.5
- 2.7.0
- ruby-head
gemfile:
- gemfiles/Gemfile-rails.5.2.x
- gemfiles/Gemfile-rails.6.0.x
- gemfiles/Gemfile-rails-edge
cache:
bundler: true
directories:
- node_modules
yarn: true
install:
- bundle install --jobs 3 --retry 3
- nvm install 12
- node -v
- npm i -g yarn
- yarn
script:
- yarn lint
- yarn test
- bundle exec rubocop
- bundle exec rake test
matrix:
allow_failures:
- gemfile: gemfiles/Gemfile-rails-edge
- rvm: ruby-head
exclude:
- rvm: 2.4.9
gemfile: gemfiles/Gemfile-rails-edge
- rvm: 2.5.5
gemfile: gemfiles/Gemfile-rails-edge
- rvm: 2.4.9
gemfile: gemfiles/Gemfile-rails.6.0.x
webpacker-5.4.3/test/ 0000755 0000041 0000041 00000000000 14123265223 014475 5 ustar www-data www-data webpacker-5.4.3/test/compiler_test.rb 0000644 0000041 0000041 00000005034 14123265223 017675 0 ustar www-data www-data require "test_helper"
class CompilerTest < Minitest::Test
def remove_compilation_digest_path
Webpacker.compiler.send(:compilation_digest_path).tap do |path|
path.delete if path.exist?
end
end
def setup
remove_compilation_digest_path
end
def teardown
remove_compilation_digest_path
end
def test_custom_environment_variables
assert_nil Webpacker.compiler.send(:webpack_env)["FOO"]
Webpacker.compiler.env["FOO"] = "BAR"
assert Webpacker.compiler.send(:webpack_env)["FOO"] == "BAR"
ensure
Webpacker.compiler.env = {}
end
def test_default_watched_paths
assert_equal Webpacker.compiler.send(:default_watched_paths), [
"app/assets/**/*{.mjs,.js,.sass,.scss,.css,.module.sass,.module.scss,.module.css,.png,.svg,.gif,.jpeg,.jpg,.elm}",
"/etc/yarn/**/*{.mjs,.js,.sass,.scss,.css,.module.sass,.module.scss,.module.css,.png,.svg,.gif,.jpeg,.jpg,.elm}",
"app/elm/**/*{.mjs,.js,.sass,.scss,.css,.module.sass,.module.scss,.module.css,.png,.svg,.gif,.jpeg,.jpg,.elm}",
"app/javascript/**/*{.mjs,.js,.sass,.scss,.css,.module.sass,.module.scss,.module.css,.png,.svg,.gif,.jpeg,.jpg,.elm}",
"yarn.lock",
"package.json",
"config/webpack/**/*"
]
end
def test_freshness
assert Webpacker.compiler.stale?
assert !Webpacker.compiler.fresh?
end
def test_compile
assert !Webpacker.compiler.compile
end
def test_freshness_on_compile_success
status = OpenStruct.new(success?: true)
assert Webpacker.compiler.stale?
Open3.stub :capture3, [:sterr, :stdout, status] do
Webpacker.compiler.compile
assert Webpacker.compiler.fresh?
end
end
def test_freshness_on_compile_fail
status = OpenStruct.new(success?: false)
assert Webpacker.compiler.stale?
Open3.stub :capture3, [:sterr, :stdout, status] do
Webpacker.compiler.compile
assert Webpacker.compiler.fresh?
end
end
def test_compilation_digest_path
assert_equal Webpacker.compiler.send(:compilation_digest_path).basename.to_s, "last-compilation-digest-#{Webpacker.env}"
end
def test_external_env_variables
assert_nil Webpacker.compiler.send(:webpack_env)["WEBPACKER_ASSET_HOST"]
assert_nil Webpacker.compiler.send(:webpack_env)["WEBPACKER_RELATIVE_URL_ROOT"]
ENV["WEBPACKER_ASSET_HOST"] = "foo.bar"
ENV["WEBPACKER_RELATIVE_URL_ROOT"] = "/baz"
assert_equal Webpacker.compiler.send(:webpack_env)["WEBPACKER_ASSET_HOST"], "foo.bar"
assert_equal Webpacker.compiler.send(:webpack_env)["WEBPACKER_RELATIVE_URL_ROOT"], "/baz"
end
end
webpacker-5.4.3/test/test_app/ 0000755 0000041 0000041 00000000000 14123265223 016314 5 ustar www-data www-data webpacker-5.4.3/test/test_app/config.ru 0000644 0000041 0000041 00000000176 14123265223 020135 0 ustar www-data www-data # This file allows the `Rails.root` to be correctly determined.
require_relative "config/environment"
run Rails.application
webpacker-5.4.3/test/test_app/package.json 0000644 0000041 0000041 00000000324 14123265223 020601 0 ustar www-data www-data {
"name": "test_app",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"private": true,
"dependencies": {
"left-pad": "^1.2.0"
},
"devDependencies": {
"right-pad": "^1.0.1"
}
}
webpacker-5.4.3/test/test_app/bin/ 0000755 0000041 0000041 00000000000 14123265223 017064 5 ustar www-data www-data webpacker-5.4.3/test/test_app/bin/webpack 0000644 0000041 0000041 00000000527 14123265223 020427 0 ustar www-data www-data #!/usr/bin/env ruby
ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
ENV["NODE_ENV"] ||= ENV["RAILS_ENV"]
require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)
require "bundler/setup"
require "webpacker"
require "webpacker/webpack_runner"
Webpacker::WebpackRunner.run(ARGV)
webpacker-5.4.3/test/test_app/bin/webpack-dev-server 0000755 0000041 0000041 00000000534 14123265223 022510 0 ustar www-data www-data #!/usr/bin/env ruby
ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
ENV["NODE_ENV"] ||= ENV["RAILS_ENV"]
require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)
require "bundler/setup"
require "webpacker"
require "webpacker/dev_server_runner"
Webpacker::DevServerRunner.run(ARGV)
webpacker-5.4.3/test/test_app/app/ 0000755 0000041 0000041 00000000000 14123265223 017074 5 ustar www-data www-data webpacker-5.4.3/test/test_app/app/javascript/ 0000755 0000041 0000041 00000000000 14123265223 021242 5 ustar www-data www-data webpacker-5.4.3/test/test_app/app/javascript/packs/ 0000755 0000041 0000041 00000000000 14123265223 022343 5 ustar www-data www-data webpacker-5.4.3/test/test_app/app/javascript/packs/multi_entry.js 0000644 0000041 0000041 00000000207 14123265223 025253 0 ustar www-data www-data /*
* Dummy file #2 for Multi File Entry points: https://webpack.js.org/guides/entry-advanced/
* This file must be named the same
*/
webpacker-5.4.3/test/test_app/app/javascript/packs/application.js 0000644 0000041 0000041 00000001003 14123265223 025176 0 ustar www-data www-data /* eslint no-console:0 */
// This file is automatically compiled by Webpack, along with any other files
// present in this directory. You're encouraged to place your actual application logic in
// a relevant structure within app/javascript and only use these pack files to reference
// that code so it'll be compiled.
//
// To reference this file, add <%= javascript_pack_tag 'application' %> to the appropriate
// layout file, like app/views/layouts/application.html.erb
console.log('Hello World from Webpacker')
webpacker-5.4.3/test/test_app/app/javascript/packs/multi_entry.css 0000644 0000041 0000041 00000000206 14123265223 025426 0 ustar www-data www-data /*
* Dummy file #1 for Multi File Entry points: https://webpack.js.org/guides/entry-advanced/
* This file must be named the same
*/ webpacker-5.4.3/test/test_app/Rakefile 0000644 0000041 0000041 00000000104 14123265223 017754 0 ustar www-data www-data require_relative "config/application"
Rails.application.load_tasks
webpacker-5.4.3/test/test_app/yarn.lock 0000644 0000041 0000041 00000000602 14123265223 020135 0 ustar www-data www-data # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
left-pad@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/left-pad/-/left-pad-1.2.0.tgz#d30a73c6b8201d8f7d8e7956ba9616087a68e0ee"
right-pad@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/right-pad/-/right-pad-1.0.1.tgz#8ca08c2cbb5b55e74dafa96bf7fd1a27d568c8d0"
webpacker-5.4.3/test/test_app/config/ 0000755 0000041 0000041 00000000000 14123265223 017561 5 ustar www-data www-data webpacker-5.4.3/test/test_app/config/webpacker.yml 0000644 0000041 0000041 00000004114 14123265223 022247 0 ustar www-data www-data # Note: You must restart bin/webpack-dev-server for changes to take effect
default: &default
source_path: app/javascript
source_entry_path: packs
public_root_path: public
public_output_path: packs
cache_path: tmp/cache/webpacker
webpack_compile_output: false
# Additional paths webpack should lookup modules
# ['app/assets', 'engine/foo/app/assets']
additional_paths:
- app/assets
- /etc/yarn
# This configuration option is deprecated and is only here for testing, to
# ensure backwards-compatibility. Please use `additional_paths`.
resolved_paths:
- app/elm
# Reload manifest.json on all requests so we reload latest compiled packs
cache_manifest: false
# Extract and emit a css file
extract_css: false
static_assets_extensions:
- .jpg
- .jpeg
- .png
- .gif
- .tiff
- .ico
- .svg
extensions:
- .mjs
- .js
- .sass
- .scss
- .css
- .module.sass
- .module.scss
- .module.css
- .png
- .svg
- .gif
- .jpeg
- .jpg
- .elm
development:
<<: *default
compile: true
# Reference: https://webpack.js.org/configuration/dev-server/
dev_server:
https: false
host: localhost
port: 3035
public: localhost:3035
hmr: false
# Inline should be set to true if using HMR
inline: true
overlay: true
disable_host_check: true
use_local_ip: false
pretty: false
test:
<<: *default
compile: true
# Compile test packs to a separate directory
public_output_path: packs-test
production:
<<: *default
# Production depends on precompilation of packs prior to booting for performance.
compile: false
# Extract and emit a css file
extract_css: true
# Cache manifest.json for performance
cache_manifest: true
staging:
<<: *default
# Production depends on precompilation of packs prior to booting for performance.
compile: false
# Extract and emit a css file
extract_css: true
# Cache manifest.json for performance
cache_manifest: true
# Compile staging packs to a separate directory
public_output_path: packs-staging
webpacker-5.4.3/test/test_app/config/application.rb 0000644 0000041 0000041 00000000415 14123265223 022411 0 ustar www-data www-data require "action_controller/railtie"
require "action_view/railtie"
require "webpacker"
module TestApp
class Application < ::Rails::Application
config.secret_key_base = "abcdef"
config.eager_load = true
config.active_support.test_order = :sorted
end
end
webpacker-5.4.3/test/test_app/config/webpacker_public_root.yml 0000644 0000041 0000041 00000000510 14123265223 024644 0 ustar www-data www-data # Note: You must restart bin/webpack-dev-server for changes to take effect
default: &default
public_root_path: ../public
development:
<<: *default
compile: true
test:
<<: *default
compile: true
public_output_path: packs-test
production:
<<: *default
compile: false
extract_css: true
cache_manifest: true
webpacker-5.4.3/test/test_app/config/environment.rb 0000644 0000041 0000041 00000000150 14123265223 022446 0 ustar www-data www-data require_relative "application"
Rails.backtrace_cleaner.remove_silencers!
Rails.application.initialize!
webpacker-5.4.3/test/test_app/config/webpack/ 0000755 0000041 0000041 00000000000 14123265223 021175 5 ustar www-data www-data webpacker-5.4.3/test/test_app/config/webpack/development.js 0000644 0000041 0000041 00000000000 14123265223 024043 0 ustar www-data www-data webpacker-5.4.3/test/test_app/public/ 0000755 0000041 0000041 00000000000 14123265223 017572 5 ustar www-data www-data webpacker-5.4.3/test/test_app/public/packs/ 0000755 0000041 0000041 00000000000 14123265223 020673 5 ustar www-data www-data webpacker-5.4.3/test/test_app/public/packs/manifest.json 0000644 0000041 0000041 00000002664 14123265223 023404 0 ustar www-data www-data {
"bootstrap.css": "/packs/bootstrap-c38deda30895059837cf.css",
"application.css": "/packs/application-dd6b1cd38bfa093df600.css",
"bootstrap.js": "/packs/bootstrap-300631c4f0e0f9c865bc.js",
"application.js": "/packs/application-k344a6d59eef8632c9d1.js",
"application.png": "/packs/application-k344a6d59eef8632c9d1.png",
"fonts/fa-regular-400.woff2": "/packs/fonts/fa-regular-400-944fb546bd7018b07190a32244f67dc9.woff2",
"media/images/image.jpg": "/packs/media/images/image-c38deda30895059837cf.jpg",
"media/images/image-2x.jpg": "/packs/media/images/image-2x-7cca48e6cae66ec07b8e.jpg",
"media/images/nested/image.jpg": "/packs/media/images/nested/image-c38deda30895059837cf.jpg",
"media/images/mb-icon.png": "/packs/media/images/mb-icon-c38deda30895059837cf.png",
"media/images/nested/mb-icon.png": "/packs/media/images/nested/mb-icon-c38deda30895059837cf.png",
"entrypoints": {
"application": {
"js": [
"/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js",
"/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js",
"/packs/application-k344a6d59eef8632c9d1.js"
],
"css": [
"/packs/1-c20632e7baf2c81200d3.chunk.css",
"/packs/application-k344a6d59eef8632c9d1.chunk.css"
]
},
"hello_stimulus": {
"css": [
"/packs/1-c20632e7baf2c81200d3.chunk.css",
"/packs/hello_stimulus-k344a6d59eef8632c9d1.chunk.css"
]
}
}
}
webpacker-5.4.3/test/dev_server_test.rb 0000644 0000041 0000041 00000001765 14123265223 020236 0 ustar www-data www-data require "test_helper"
class DevServerTest < Webpacker::Test
def test_running?
refute Webpacker.dev_server.running?
end
def test_host
with_rails_env("development") do
assert_equal Webpacker.dev_server.host, "localhost"
end
end
def test_port
with_rails_env("development") do
assert_equal Webpacker.dev_server.port, 3035
end
end
def test_https?
with_rails_env("development") do
assert_equal Webpacker.dev_server.https?, false
end
end
def test_protocol
with_rails_env("development") do
assert_equal Webpacker.dev_server.protocol, "http"
end
end
def test_host_with_port
with_rails_env("development") do
assert_equal Webpacker.dev_server.host_with_port, "localhost:3035"
end
end
def test_pretty?
with_rails_env("development") do
refute Webpacker.dev_server.pretty?
end
end
def test_default_env_prefix
assert_equal Webpacker::DevServer::DEFAULT_ENV_PREFIX, "WEBPACKER_DEV_SERVER"
end
end
webpacker-5.4.3/test/webpack_runner_test.rb 0000644 0000041 0000041 00000002520 14123265223 021065 0 ustar www-data www-data require "test_helper"
require "webpacker/webpack_runner"
class WebpackRunnerTest < Webpacker::Test
def setup
@original_node_env, ENV["NODE_ENV"] = ENV["NODE_ENV"], "development"
@original_rails_env, ENV["RAILS_ENV"] = ENV["RAILS_ENV"], "development"
end
def teardown
ENV["NODE_ENV"] = @original_node_env
ENV["RAILS_ENV"] = @original_rails_env
end
def test_run_cmd_via_node_modules
cmd = ["#{test_app_path}/node_modules/.bin/webpack", "--config", "#{test_app_path}/config/webpack/development.js"]
verify_command(cmd, use_node_modules: true)
end
def test_run_cmd_via_yarn
cmd = ["yarn", "webpack", "--config", "#{test_app_path}/config/webpack/development.js"]
verify_command(cmd, use_node_modules: false)
end
private
def test_app_path
File.expand_path("test_app", __dir__)
end
def verify_command(cmd, use_node_modules: true)
cwd = Dir.pwd
Dir.chdir(test_app_path)
klass = Webpacker::WebpackRunner
instance = klass.new([])
mock = Minitest::Mock.new
mock.expect(:call, nil, [Webpacker::Compiler.env, *cmd])
klass.stub(:new, instance) do
instance.stub(:node_modules_bin_exist?, use_node_modules) do
Kernel.stub(:exec, mock) { klass.run([]) }
end
end
mock.verify
ensure
Dir.chdir(cwd)
end
end
webpacker-5.4.3/test/helper_test.rb 0000644 0000041 0000041 00000016347 14123265223 017353 0 ustar www-data www-data require "test_helper"
class HelperTest < ActionView::TestCase
tests Webpacker::Helper
attr_reader :request
def setup
@request = Class.new do
def send_early_hints(links) end
def base_url
"https://example.com"
end
end.new
end
def test_asset_pack_path
assert_equal "/packs/bootstrap-300631c4f0e0f9c865bc.js", asset_pack_path("bootstrap.js")
assert_equal "/packs/bootstrap-c38deda30895059837cf.css", asset_pack_path("bootstrap.css")
Webpacker.config.stub :extract_css?, false do
assert_nil asset_pack_path("bootstrap.css")
assert_equal "/packs/application-k344a6d59eef8632c9d1.png", asset_pack_path("application.png")
end
end
def test_asset_pack_url
assert_equal "https://example.com/packs/bootstrap-300631c4f0e0f9c865bc.js", asset_pack_url("bootstrap.js")
assert_equal "https://example.com/packs/bootstrap-c38deda30895059837cf.css", asset_pack_url("bootstrap.css")
Webpacker.config.stub :extract_css?, false do
assert_nil asset_pack_path("bootstrap.css")
assert_equal "https://example.com/packs/application-k344a6d59eef8632c9d1.png", asset_pack_url("application.png")
end
end
def test_image_pack_tag
assert_equal \
" ",
image_pack_tag("application.png", size: "16x10", alt: "Edit Entry")
assert_equal \
" ",
image_pack_tag("image.jpg", size: "16x10", alt: "Edit Entry")
assert_equal \
" ",
image_pack_tag("media/images/image.jpg", size: "16x10", alt: "Edit Entry")
assert_equal \
" ",
image_pack_tag("nested/image.jpg", size: "16x10", alt: "Edit Entry")
assert_equal \
" ",
image_pack_tag("media/images/nested/image.jpg", size: "16x10", alt: "Edit Entry")
assert_equal \
" ",
image_pack_tag("media/images/image.jpg", srcset: { "media/images/image-2x.jpg" => "2x" })
end
def test_favicon_pack_tag
assert_equal \
" ",
favicon_pack_tag("application.png", rel: "apple-touch-icon", type: "image/png")
assert_equal \
" ",
favicon_pack_tag("mb-icon.png", rel: "apple-touch-icon", type: "image/png")
assert_equal \
" ",
favicon_pack_tag("media/images/mb-icon.png", rel: "apple-touch-icon", type: "image/png")
assert_equal \
" ",
favicon_pack_tag("nested/mb-icon.png", rel: "apple-touch-icon", type: "image/png")
assert_equal \
" ",
favicon_pack_tag("media/images/nested/mb-icon.png", rel: "apple-touch-icon", type: "image/png")
end
def test_javascript_pack_tag
assert_equal \
%(),
javascript_pack_tag("bootstrap.js")
end
def test_javascript_pack_tag_symbol
assert_equal \
%(),
javascript_pack_tag(:bootstrap)
end
def test_javascript_pack_tag_splat
assert_equal \
%(\n) +
%(),
javascript_pack_tag("bootstrap.js", "application.js", defer: true)
end
def test_javascript_pack_tag_split_chunks
assert_equal \
%(\n) +
%(\n) +
%(),
javascript_packs_with_chunks_tag("application")
end
def test_preload_pack_asset
if self.class.method_defined?(:preload_link_tag)
assert_equal \
%( ),
preload_pack_asset("fonts/fa-regular-400.woff2")
else
error = assert_raises do
preload_pack_asset("fonts/fa-regular-400.woff2")
end
assert_equal \
"You need Rails >= 5.2 to use this tag.",
error.message
end
end
def test_stylesheet_pack_tag_split_chunks
assert_equal stylesheet_packs_with_chunks_tag("application", "hello_stimulus").in?([
%( \n) +
%( \n) +
%( ),
%( \n) +
%( \n) +
%( ),
]),
true
end
def test_stylesheet_pack_tag
assert_equal stylesheet_pack_tag("bootstrap.css").in?([
%( ),
%( ),
]), true
end
def test_stylesheet_pack_tag_symbol
assert_equal stylesheet_pack_tag(:bootstrap).in?([
%( ),
%( ),
]), true
end
def test_stylesheet_pack_tag_splat
assert_equal stylesheet_pack_tag("bootstrap.css", "application.css", media: "all").in?([
%( \n) +
%( ),
%( \n) +
%( ),
]), true
end
end
webpacker-5.4.3/test/dev_server_runner_test.rb 0000644 0000041 0000041 00000002555 14123265223 021625 0 ustar www-data www-data require "test_helper"
require "webpacker/dev_server_runner"
class DevServerRunnerTest < Webpacker::Test
def setup
@original_node_env, ENV["NODE_ENV"] = ENV["NODE_ENV"], "development"
@original_rails_env, ENV["RAILS_ENV"] = ENV["RAILS_ENV"], "development"
end
def teardown
ENV["NODE_ENV"] = @original_node_env
ENV["RAILS_ENV"] = @original_rails_env
end
def test_run_cmd_via_node_modules
cmd = ["#{test_app_path}/node_modules/.bin/webpack-dev-server", "--config", "#{test_app_path}/config/webpack/development.js"]
verify_command(cmd, use_node_modules: true)
end
def test_run_cmd_via_yarn
cmd = ["yarn", "webpack-dev-server", "--config", "#{test_app_path}/config/webpack/development.js"]
verify_command(cmd, use_node_modules: false)
end
private
def test_app_path
File.expand_path("test_app", __dir__)
end
def verify_command(cmd, use_node_modules: true)
cwd = Dir.pwd
Dir.chdir(test_app_path)
klass = Webpacker::DevServerRunner
instance = klass.new([])
mock = Minitest::Mock.new
mock.expect(:call, nil, [Webpacker::Compiler.env, *cmd])
klass.stub(:new, instance) do
instance.stub(:node_modules_bin_exist?, use_node_modules) do
Kernel.stub(:exec, mock) { klass.run([]) }
end
end
mock.verify
ensure
Dir.chdir(cwd)
end
end
webpacker-5.4.3/test/rake_tasks_test.rb 0000644 0000041 0000041 00000005435 14123265223 020217 0 ustar www-data www-data require "test_helper"
class RakeTasksTest < Minitest::Test
def test_rake_tasks
output = Dir.chdir(test_app_path) { `rake -T` }
assert_includes output, "webpacker"
assert_includes output, "webpacker:check_binstubs"
assert_includes output, "webpacker:check_node"
assert_includes output, "webpacker:check_yarn"
assert_includes output, "webpacker:clean"
assert_includes output, "webpacker:clobber"
assert_includes output, "webpacker:compile"
assert_includes output, "webpacker:install"
assert_includes output, "webpacker:install:angular"
assert_includes output, "webpacker:install:coffee"
assert_includes output, "webpacker:install:elm"
assert_includes output, "webpacker:install:erb"
assert_includes output, "webpacker:install:react"
assert_includes output, "webpacker:install:svelte"
assert_includes output, "webpacker:install:stimulus"
assert_includes output, "webpacker:install:typescript"
assert_includes output, "webpacker:install:vue"
assert_includes output, "webpacker:verify_install"
end
def test_rake_task_webpacker_check_binstubs
output = Dir.chdir(test_app_path) { `rake webpacker:check_binstubs 2>&1` }
refute_includes output, "webpack binstubs not found."
end
def test_check_node_version
output = Dir.chdir(test_app_path) { `rake webpacker:check_node 2>&1` }
refute_includes output, "Webpacker requires Node.js"
end
def test_check_yarn_version
output = Dir.chdir(test_app_path) { `rake webpacker:check_yarn 2>&1` }
refute_includes output, "Yarn not installed"
refute_includes output, "Webpacker requires Yarn"
end
def test_rake_webpacker_yarn_install_in_non_production_environments
assert_includes test_app_dev_dependencies, "right-pad"
Webpacker.with_node_env("test") do
Dir.chdir(test_app_path) do
`bundle exec rake webpacker:yarn_install`
end
end
assert_includes installed_node_module_names, "right-pad",
"Expected dev dependencies to be installed"
end
def test_rake_webpacker_yarn_install_in_production_environment
Webpacker.with_node_env("production") do
Dir.chdir(test_app_path) do
`bundle exec rake webpacker:yarn_install`
end
end
refute_includes installed_node_module_names, "right-pad",
"Expected only production dependencies to be installed"
end
private
def test_app_path
File.expand_path("test_app", __dir__)
end
def test_app_dev_dependencies
package_json = File.expand_path("package.json", test_app_path)
JSON.parse(File.read(package_json))["devDependencies"]
end
def installed_node_module_names
node_modules_path = File.expand_path("node_modules", test_app_path)
Dir.chdir(node_modules_path) { Dir.glob("*") }
end
end
webpacker-5.4.3/test/env_test.rb 0000644 0000041 0000041 00000000705 14123265223 016653 0 ustar www-data www-data require "test_helper"
class EnvTest < Webpacker::Test
def test_current
assert_equal Webpacker.env, Rails.env
end
def test_custom_without_config
with_rails_env("foo") do
assert_equal Webpacker.env, "production"
end
end
def test_custom_with_config
with_rails_env("staging") do
assert_equal Webpacker.env, "staging"
end
end
def test_default
assert_equal Webpacker::Env::DEFAULT, "production"
end
end
webpacker-5.4.3/test/command_test.rb 0000644 0000041 0000041 00000001654 14123265223 017505 0 ustar www-data www-data require "test_helper"
class CommandTest < Minitest::Test
def test_compile_command_returns_success_status_when_stale
Webpacker.compiler.stub :stale?, true do
Webpacker.compiler.stub :run_webpack, true do
assert_equal true, Webpacker.commands.compile
end
end
end
def test_compile_command_returns_success_status_when_fresh
Webpacker.compiler.stub :stale?, false do
Webpacker.compiler.stub :run_webpack, true do
assert_equal true, Webpacker.commands.compile
end
end
end
def test_compile_command_returns_failure_status_when_stale
Webpacker.compiler.stub :stale?, true do
Webpacker.compiler.stub :run_webpack, false do
assert_equal false, Webpacker.commands.compile
end
end
end
def test_clean_command_works_with_nested_hashes_and_without_any_compiled_files
File.stub :delete, true do
assert Webpacker.commands.clean
end
end
end
webpacker-5.4.3/test/configuration_test.rb 0000644 0000041 0000041 00000007163 14123265223 020737 0 ustar www-data www-data require "test_helper"
class ConfigurationTest < Webpacker::Test
def setup
@config = Webpacker::Configuration.new(
root_path: Pathname.new(File.expand_path("test_app", __dir__)),
config_path: Pathname.new(File.expand_path("./test_app/config/webpacker.yml", __dir__)),
env: "production"
)
end
def test_source_path
source_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/app/javascript").to_s
assert_equal source_path, @config.source_path.to_s
end
def test_source_path_globbed
assert_equal @config.source_path_globbed,
"app/javascript/**/*{.mjs,.js,.sass,.scss,.css,.module.sass,.module.scss,.module.css,.png,.svg,.gif,.jpeg,.jpg,.elm}"
end
def test_source_entry_path
source_entry_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/app/javascript", "packs").to_s
assert_equal @config.source_entry_path.to_s, source_entry_path
end
def test_public_root_path
public_root_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/public").to_s
assert_equal @config.public_path.to_s, public_root_path
end
def test_public_output_path
public_output_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/public/packs").to_s
assert_equal @config.public_output_path.to_s, public_output_path
@config = Webpacker::Configuration.new(
root_path: @config.root_path,
config_path: Pathname.new(File.expand_path("./test_app/config/webpacker_public_root.yml", __dir__)),
env: "production"
)
public_output_path = File.expand_path File.join(File.dirname(__FILE__), "public/packs").to_s
assert_equal @config.public_output_path.to_s, public_output_path
end
def test_public_manifest_path
public_manifest_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/public/packs", "manifest.json").to_s
assert_equal @config.public_manifest_path.to_s, public_manifest_path
end
def test_cache_path
cache_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/tmp/cache/webpacker").to_s
assert_equal @config.cache_path.to_s, cache_path
end
def test_additional_paths
assert_equal @config.additional_paths, ["app/assets", "/etc/yarn", "app/elm"]
end
def test_additional_paths_globbed
assert_equal @config.additional_paths_globbed, [
"app/assets/**/*{.mjs,.js,.sass,.scss,.css,.module.sass,.module.scss,.module.css,.png,.svg,.gif,.jpeg,.jpg,.elm}",
"/etc/yarn/**/*{.mjs,.js,.sass,.scss,.css,.module.sass,.module.scss,.module.css,.png,.svg,.gif,.jpeg,.jpg,.elm}",
"app/elm/**/*{.mjs,.js,.sass,.scss,.css,.module.sass,.module.scss,.module.css,.png,.svg,.gif,.jpeg,.jpg,.elm}"
]
end
def test_extensions
config_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/config/webpacker.yml").to_s
webpacker_yml = YAML.load_file(config_path)
assert_equal @config.extensions, webpacker_yml["default"]["extensions"]
end
def test_cache_manifest?
assert @config.cache_manifest?
with_rails_env("development") do
refute Webpacker.config.cache_manifest?
end
with_rails_env("test") do
refute Webpacker.config.cache_manifest?
end
end
def test_compile?
refute @config.compile?
with_rails_env("development") do
assert Webpacker.config.compile?
end
with_rails_env("test") do
assert Webpacker.config.compile?
end
end
def test_extract_css?
assert @config.extract_css?
with_rails_env("development") do
refute Webpacker.config.extract_css?
end
with_rails_env("test") do
refute Webpacker.config.extract_css?
end
end
end
webpacker-5.4.3/test/webpacker_test.rb 0000644 0000041 0000041 00000000600 14123265223 020020 0 ustar www-data www-data require "test_helper"
class WebpackerTest < Webpacker::Test
def test_config_params
assert_equal Rails.env, Webpacker.config.env
assert_equal Webpacker.instance.root_path, Webpacker.config.root_path
assert_equal Webpacker.instance.config_path, Webpacker.config.config_path
with_rails_env("test") do
assert_equal "test", Webpacker.config.env
end
end
end
webpacker-5.4.3/test/test_helper.rb 0000644 0000041 0000041 00000001477 14123265223 017351 0 ustar www-data www-data # frozen_string_literal: true
require "minitest/autorun"
require "rails"
require "rails/test_help"
require "byebug"
require_relative "test_app/config/environment"
Rails.env = "production"
Webpacker.instance = ::Webpacker::Instance.new
class Webpacker::Test < Minitest::Test
private
def reloaded_config
Webpacker.instance.instance_variable_set(:@env, nil)
Webpacker.instance.instance_variable_set(:@config, nil)
Webpacker.instance.instance_variable_set(:@dev_server, nil)
Webpacker.env
Webpacker.config
Webpacker.dev_server
end
def with_rails_env(env)
original = Rails.env
Rails.env = ActiveSupport::StringInquirer.new(env)
reloaded_config
yield
ensure
Rails.env = ActiveSupport::StringInquirer.new(original)
reloaded_config
end
end
webpacker-5.4.3/test/manifest_test.rb 0000644 0000041 0000041 00000004172 14123265223 017673 0 ustar www-data www-data require "test_helper"
class ManifestTest < Minitest::Test
def test_lookup_exception!
asset_file = "calendar.js"
error = assert_raises_manifest_missing_entry_error do
Webpacker.manifest.lookup!(asset_file)
end
assert_match "Webpacker can't find #{asset_file} in #{manifest_path}", error.message
end
def test_lookup_with_type_exception!
asset_file = "calendar"
error = assert_raises_manifest_missing_entry_error do
Webpacker.manifest.lookup!(asset_file, type: :javascript)
end
assert_match "Webpacker can't find #{asset_file}.js in #{manifest_path}", error.message
end
def test_lookup_success!
assert_equal Webpacker.manifest.lookup!("bootstrap.js"), "/packs/bootstrap-300631c4f0e0f9c865bc.js"
end
def test_lookup_nil
assert_nil Webpacker.manifest.lookup("foo.js")
end
def test_lookup_chunks_nil
assert_nil Webpacker.manifest.lookup_pack_with_chunks("foo.js")
end
def test_lookup_success
assert_equal Webpacker.manifest.lookup("bootstrap.js"), "/packs/bootstrap-300631c4f0e0f9c865bc.js"
end
def test_lookup_entrypoint_exception!
asset_file = "calendar"
error = assert_raises_manifest_missing_entry_error do
Webpacker.manifest.lookup_pack_with_chunks!(asset_file, type: :javascript)
end
assert_match "Webpacker can't find #{asset_file}.js in #{manifest_path}", error.message
end
def test_lookup_entrypoint
application_entrypoints = [
"/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js",
"/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js",
"/packs/application-k344a6d59eef8632c9d1.js"
]
assert_equal Webpacker.manifest.lookup_pack_with_chunks!("application", type: :javascript), application_entrypoints
end
private
def assert_raises_manifest_missing_entry_error(&block)
error = nil
Webpacker.config.stub :compile?, false do
error = assert_raises Webpacker::Manifest::MissingEntryError, &block
end
error
end
def manifest_path
File.expand_path File.join(File.dirname(__FILE__), "test_app/public/packs", "manifest.json").to_s
end
end
webpacker-5.4.3/README.md 0000644 0000041 0000041 00000037310 14123265223 015001 0 ustar www-data www-data # Webpacker
[](https://travis-ci.org/rails/webpacker)
[](https://www.npmjs.com/package/@rails/webpacker)
[](https://rubygems.org/gems/webpacker)
Webpacker makes it easy to use the JavaScript pre-processor and bundler
[webpack 4.x.x+](https://webpack.js.org/)
to manage application-like JavaScript in Rails. It coexists with the asset pipeline,
as the primary purpose for webpack is app-like JavaScript, not images, CSS, or
even JavaScript Sprinkles (that all continues to live in app/assets).
However, it is possible to use Webpacker for CSS, images and fonts assets as well,
in which case you may not even need the asset pipeline. This is mostly relevant when exclusively using component-based JavaScript frameworks.
**NOTE:** The master branch now hosts the code for v5.x.x. Please refer to [4-x-stable](https://github.com/rails/webpacker/tree/4-x-stable) branch for 4.x documentation.
## Table of Contents
- [Prerequisites](#prerequisites)
- [Features](#features)
- [Installation](#installation)
- [Usage](#usage)
- [Development](#development)
- [Webpack Configuration](#webpack-configuration)
- [Custom Rails environments](#custom-rails-environments)
- [Upgrading](#upgrading)
- [Integrations](#integrations)
- [React](./docs/integrations.md#react)
- [Angular with TypeScript](./docs/integrations.md#angular-with-typescript)
- [Vue](./docs/integrations.md#vue)
- [Elm](./docs/integrations.md#elm)
- [Stimulus](./docs/integrations.md#stimulus)
- [Svelte](./docs/integrations.md#svelte)
- [Typescript](./docs/typescript.md)
- [CoffeeScript](./docs/integrations.md#coffeescript)
- [Erb](./docs/integrations.md#erb)
- [Paths](#paths)
- [Resolved](#resolved)
- [Watched](#watched)
- [Deployment](#deployment)
- [Docs](#docs)
- [Contributing](#contributing)
- [License](#license)
## Prerequisites
- Ruby 2.4+
- Rails 5.2+
- Node.js 10.17.0+
- Yarn 1.x+
## Features
- [webpack 4.x.x](https://webpack.js.org/)
- ES6 with [babel](https://babeljs.io/)
- Automatic code splitting using multiple entry points
- Stylesheets - Sass and CSS
- Images and fonts
- PostCSS - Auto-Prefixer
- Asset compression, source-maps, and minification
- CDN support
- React, Angular, Elm and Vue support out-of-the-box
- Rails view helpers
- Extensible and configurable
## Installation
You can either add Webpacker during setup of a new Rails 5.1+ application
using new `--webpack` option:
```bash
# Available Rails 5.1+
rails new myapp --webpack
```
Or add it to your `Gemfile`:
```ruby
# Gemfile
gem 'webpacker', '~> 5.x'
# OR if you prefer to use master
gem 'webpacker', git: 'https://github.com/rails/webpacker.git'
yarn add https://github.com/rails/webpacker.git
yarn add core-js regenerator-runtime
```
Finally, run the following to install Webpacker:
```bash
bundle
bundle exec rails webpacker:install
# OR (on rails version < 5.0)
bundle exec rake webpacker:install
```
Optional: To fix ["unmet peer dependency" warnings](https://github.com/rails/webpacker/issues/1078),
```bash
yarn upgrade
```
When `package.json` and/or `yarn.lock` changes, such as when pulling down changes to your local environment in a team settings, be sure to keep your NPM packages up-to-date:
```bash
yarn install
```
### Usage
Once installed, you can start writing modern ES6-flavored JavaScript apps right away:
```yml
app/javascript:
├── packs:
│ # only webpack entry files here
│ └── application.js
│ └── application.css
└── src:
│ └── my_component.js
└── stylesheets:
│ └── my_styles.css
└── images:
└── logo.svg
```
In `/packs/application.js`, include this at the top of the file:
```js
import 'core-js/stable'
import 'regenerator-runtime/runtime'
```
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 ` ` or ` ` tag, you
can use the `asset_pack_path` helper:
```erb
```
If you are using new webpack 4 split chunks API, then consider using `javascript_packs_with_chunks_tag` helper, which creates html
tags for a pack and all the dependent chunks.
```erb
<%= javascript_packs_with_chunks_tag 'calendar', 'map', 'data-turbolinks-track': 'reload' %>
```
**Important:** Pass all your pack names when using `javascript_packs_with_chunks_tag`
helper otherwise you will get duplicated chunks on the page.
```erb
<%# DO %>
<%= javascript_packs_with_chunks_tag 'calendar', 'map' %>
<%# DON'T %>
<%= javascript_packs_with_chunks_tag 'calendar' %>
<%= javascript_packs_with_chunks_tag 'map' %>
```
**Note:** In order for your styles or static assets files to be available in your view,
you would need to link them in your "pack" or entry file.
### 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`
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.
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`. 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
# watcher
./bin/webpack --watch --colors --progress
# 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 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_ `. Please note that these environmental
variables will always take precedence over the ones already set in the
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, 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 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
Rails.application.config.content_security_policy do |policy|
policy.connect_src :self, :https, 'http://localhost:3035', 'ws://localhost:3035' if Rails.env.development?
end
```
**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.
### Custom Rails environments
Out of the box Webpacker ships with - development, test and production environments in `config/webpacker.yml` however, in most production apps extra environments are needed as part of deployment workflow. Webpacker supports this out of the box from version 3.4.0+ onwards.
You can choose to define additional environment configurations in webpacker.yml,
```yml
staging:
<<: *default
# Production depends on precompilation of packs prior to booting for performance.
compile: false
# Cache manifest.json for performance
cache_manifest: true
# Compile staging packs to a separate directory
public_output_path: packs-staging
```
or, Webpacker will use production environment as a fallback environment for loading configurations. Please note, `NODE_ENV` can either be set to `production`, `development` or `test`.
This means you don't need to create additional environment files inside `config/webpacker/*` and instead use webpacker.yml to load different configurations using `RAILS_ENV`.
For example, the below command will compile assets in production mode but will use staging configurations from `config/webpacker.yml` if available or use fallback production environment configuration:
```bash
RAILS_ENV=staging bundle exec rails assets:precompile
```
And, this will compile in development mode and load configuration for cucumber environment
if defined in webpacker.yml or fallback to production configuration
```bash
RAILS_ENV=cucumber NODE_ENV=development bundle exec rails assets:precompile
```
Please note, binstubs compiles in development mode however rake tasks
compiles in production mode.
```bash
# Compiles in development mode unless NODE_ENV is specified
./bin/webpack
./bin/webpack-dev-server
# compiles in production mode by default unless NODE_ENV is specified
bundle exec rails assets:precompile
bundle exec rails webpacker:compile
```
### Upgrading
You can run following commands to upgrade Webpacker to the latest stable version. This process involves upgrading the gem and related JavaScript packages:
```bash
bundle update webpacker
rails webpacker:binstubs
yarn upgrade @rails/webpacker --latest
yarn upgrade webpack-dev-server --latest
# Or to install the latest release (including pre-releases)
yarn add @rails/webpacker@next
```
## Integrations
Webpacker ships with basic out-of-the-box integration. You can see a list of available commands/tasks by running `bundle exec rails webpacker`.
Included install integrations:
- [React](./docs/integrations.md#React)
- [Angular with TypeScript](./docs/integrations.md#Angular-with-TypeScript)
- [Vue](./docs/integrations.md#Vue)
- [Elm](./docs/integrations.md#Elm)
- [Svelte](./docs/integrations.md#Svelte)
- [Stimulus](./docs/integrations.md#Stimulus)
- [CoffeeScript](./docs/integrations.md#CoffeeScript)
- [Typescript](./docs/typescript.md)
- [Erb](./docs/integrations.md#Erb)
See [Integrations](./docs/integrations.md) for further details.
## Paths
By default, Webpacker ships with simple conventions for where the JavaScript
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
an entry file. As a rule of thumb, put all files you want to link in your views inside
"packs" directory and keep everything else under `app/javascript`.
Suppose you want to change the source directory from `app/javascript`
to `frontend` and output to `assets/packs`. This is how you would do it:
```yml
# config/webpacker.yml
source_path: frontend
source_entry_path: packs
public_output_path: assets/packs # outputs to => public/assets/packs
```
Similarly you can also control and configure `webpack-dev-server` settings from `config/webpacker.yml` file:
```yml
# config/webpacker.yml
development:
dev_server:
host: localhost
port: 3035
```
If you have `hmr` turned to true, then the `stylesheet_pack_tag` generates no output, as you will want to configure your styles to be inlined in your JavaScript for hot reloading. During production and testing, the `stylesheet_pack_tag` will create the appropriate HTML tags.
### 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, you can use the `additional_paths`
option available in `config/webpacker.yml`. This lets you
add additional paths that webpack should lookup when resolving modules:
```yml
additional_paths: ['app/assets']
```
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'
```
**Note:** Please be careful when adding paths here otherwise it
will make the compilation slow, consider adding specific paths instead of
whole parent directory if you just need to reference one or two modules
## 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`. Similar to sprockets both rake tasks will compile packs in production mode but will use `RAILS_ENV` to load configuration from `config/webpacker.yml` (if available).
When compiling assets for production on a remote server, such as a continuous integration environment, it's recommended to use `yarn install --frozen-lockfile` to install NPM packages on the remote host to ensure that the installed packages match the `yarn.lock` file.
## Docs
- [Development](https://github.com/rails/webpacker#development)
- [Webpack](./docs/webpack.md)
- [Webpack-dev-server](./docs/webpack-dev-server.md)
- [Environment Variables](./docs/env.md)
- [Folder Structure](./docs/folder-structure.md)
- [Assets](./docs/assets.md) - [CSS, Sass and SCSS](./docs/css.md) - [ES6](./docs/es6.md), [Target browsers](./docs/target.md)
- [Props](./docs/props.md)
- [Typescript](./docs/typescript.md)
- [Yarn](./docs/yarn.md)
- [Misc](./docs/misc.md)
- [Deployment](./docs/deployment.md)
- [Docker](./docs/docker.md)
- [Using in Rails engines](./docs/engines.md)
- [Webpacker on Cloud9](./docs/cloud9.md)
- [Testing](./docs/testing.md)
- [Troubleshooting](./docs/troubleshooting.md)
- [v3 to v4 Upgrade Guide](./docs/v4-upgrade.md)
## Contributing
[](https://www.codetriage.com/rails/webpacker)
We encourage you to contribute to Webpacker! See [CONTRIBUTING](CONTRIBUTING.md) for guidelines about how to proceed.
## License
Webpacker is released under the [MIT License](https://opensource.org/licenses/MIT).
webpacker-5.4.3/package.json 0000644 0000041 0000041 00000004661 14123265223 016013 0 ustar www-data www-data {
"name": "@rails/webpacker",
"version": "5.4.3",
"description": "Use webpack to manage app-like JavaScript modules in Rails",
"main": "package/index.js",
"files": [
"package",
"lib/install/config/webpacker.yml"
],
"engines": {
"node": ">=10.17.0",
"yarn": ">=1 <4"
},
"dependencies": {
"@babel/core": "^7.15.0",
"@babel/plugin-proposal-class-properties": "^7.14.5",
"@babel/plugin-proposal-object-rest-spread": "^7.14.7",
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/plugin-transform-destructuring": "^7.14.7",
"@babel/plugin-transform-regenerator": "^7.14.5",
"@babel/plugin-transform-runtime": "^7.15.0",
"@babel/preset-env": "^7.15.0",
"@babel/runtime": "^7.15.3",
"babel-loader": "^8.2.2",
"babel-plugin-dynamic-import-node": "^2.3.3",
"babel-plugin-macros": "^2.8.0",
"case-sensitive-paths-webpack-plugin": "^2.4.0",
"compression-webpack-plugin": "^4.0.1",
"core-js": "^3.16.2",
"css-loader": "^3.6.0",
"file-loader": "^6.2.0",
"flatted": "^3.2.2",
"glob": "^7.1.7",
"js-yaml": "^3.14.1",
"mini-css-extract-plugin": "^0.9.0",
"optimize-css-assets-webpack-plugin": "^5.0.8",
"path-complete-extname": "^1.0.0",
"pnp-webpack-plugin": "^1.7.0",
"postcss-flexbugs-fixes": "^4.2.1",
"postcss-import": "^12.0.1",
"postcss-loader": "^3.0.0",
"postcss-preset-env": "^6.7.0",
"postcss-safe-parser": "^4.0.2",
"regenerator-runtime": "^0.13.9",
"sass": "^1.38.0",
"sass-loader": "10.1.1",
"style-loader": "^1.3.0",
"terser-webpack-plugin": "^4.2.3",
"webpack": "^4.46.0",
"webpack-assets-manifest": "^3.1.1",
"webpack-cli": "^3.3.12",
"webpack-sources": "^1.4.3"
},
"devDependencies": {
"eslint": "^7.32.0",
"eslint-config-airbnb": "^18.2.1",
"eslint-plugin-import": "^2.24.0",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-react": "^7.24.0",
"jest": "^27.0.6"
},
"jest": {
"testRegex": "(/__tests__/.*|(\\.|/))\\.jsx?$",
"roots": [
"/package"
]
},
"scripts": {
"test": "jest",
"lint": "eslint package/"
},
"repository": {
"type": "git",
"url": "git+https://github.com/rails/webpacker.git"
},
"author": "David Heinemeier Hansson ",
"license": "MIT",
"bugs": {
"url": "https://github.com/rails/webpacker/issues"
},
"homepage": "https://github.com/rails/webpacker"
}
webpacker-5.4.3/gemfiles/ 0000755 0000041 0000041 00000000000 14123265223 015311 5 ustar www-data www-data webpacker-5.4.3/gemfiles/Gemfile-rails.6.0.x 0000644 0000041 0000041 00000000255 14123265223 020466 0 ustar www-data www-data source "https://rubygems.org"
gemspec path: "../"
gem "rails", "~> 6.0.0.rc2"
gem "rake", ">= 11.1"
gem "rack-proxy", require: false
gem "minitest", "~> 5.0"
gem "byebug"
webpacker-5.4.3/gemfiles/Gemfile-rails.5.2.x 0000644 0000041 0000041 00000000251 14123265223 020463 0 ustar www-data www-data source "https://rubygems.org"
gemspec path: "../"
gem "rails", "~> 5.2.0"
gem "rake", ">= 11.1"
gem "rack-proxy", require: false
gem "minitest", "~> 5.0"
gem "byebug"
webpacker-5.4.3/gemfiles/Gemfile-rails-edge 0000644 0000041 0000041 00000000446 14123265223 020622 0 ustar www-data www-data source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gemspec path: "../"
gem "rails", github: "rails/rails", branch: "main"
gem "arel", github: "rails/arel"
gem "rake", ">= 11.1"
gem "rack-proxy", require: false
gem "minitest", "~> 5.0"
gem "byebug"
webpacker-5.4.3/CHANGELOG.md 0000644 0000041 0000041 00000103543 14123265223 015335 0 ustar www-data www-data **Please note that Webpacker 3.1.0 and 3.1.1 have some serious bugs so please consider using either 3.0.2 or 3.2.0**
**Please note that Webpacker 4.1.0 has an installer bug. Please use 4.2.0 or above**
## [[5.4.2]](https://github.com/rails/webpacker/compare/v5.4.0...v5.4.1) - 2021-08-20
- Fix babel warning about private-methods in @babel/plugin-proposal-private-property-in-object as well.
## [[5.4.1]](https://github.com/rails/webpacker/compare/v5.4.0...v5.4.1) - 2021-08-20
- Update all dependencies within the same major version (#3120)
- Fix babel warning about private-methods (#3016)
## [[5.4.0]](https://github.com/rails/webpacker/compare/v5.3.0...v5.4.0) - 2021-05-18
- Fix compatibility with Psych 4
## [[5.3.0]](https://github.com/rails/webpacker/compare/v5.2.1...v5.3.0) - 2021-04-27
- Adds experimental Yarn 2 support. Note you must manually set `nodeLinker: node-modules` in your `.yarnrc.yml`.
- Keep backups, even when they're old [#2912](https://github.com/rails/webpacker/pull/2912)
## [[5.2.2]](https://github.com/rails/webpacker/compare/v5.2.1...v5.2.2) - 2021-04-27
- Bump deps and remove node-sass [#2997](https://github.com/rails/webpacker/pull/2997).
## [[5.2.1]](https://github.com/rails/webpacker/compare/v5.2.0...v5.2.1) - 2020-08-17
- Revert [#1311](https://github.com/rails/webpacker/pull/1311).
## [[5.2.0]](https://github.com/rails/webpacker/compare/v5.1.1...v5.2.0) - 2020-08-16
- Bump dependencies and fixes. See [diff](https://github.com/rails/webpacker/compare/v5.1.1...5-x-stable) for changes.
## [[5.1.1]](https://github.com/rails/webpacker/compare/v5.1.0...v5.1.1) - 2020-04-20
- Update [TypeScript documentation](https://github.com/rails/webpacker/blob/master/docs/typescript.md) and installer to use babel-loader for typescript.[(#2541](https://github.com/rails/webpacker/pull/2541)
## [[5.1.0]](https://github.com/rails/webpacker/compare/v5.0.1...v5.1.0) - 2020-04-19
- Remove yarn integrity check [#2518](https://github.com/rails/webpacker/pull/2518)
- Switch from ts-loader to babel-loader [#2449](https://github.com/rails/webpacker/pull/2449)
Please see the [TypeScript documentation](https://github.com/rails/webpacker/blob/master/docs/typescript.md) to upgrade existing projects to use typescript with 5.1
- Resolve multi-word snakecase WEBPACKER_DEV_SERVER env values [#2528](https://github.com/rails/webpacker/pull/2528)
## [[5.0.1]](https://github.com/rails/webpacker/compare/v5.0.0...v5.0.1) - 2020-03-22
- Upgrade deps and fix sass loader config options bug [#2508](https://github.com/rails/webpacker/pull/2508)
## [[5.0.0]](https://github.com/rails/webpacker/compare/v4.2.2...v5.0.0) - 2020-03-22
- Bump minimum node version [#2428](https://github.com/rails/webpacker/pull/2428)
- Bump minimum ruby/rails version [#2415](https://github.com/rails/webpacker/pull/2415)
- Add support for multiple files per entry [#2476](https://github.com/rails/webpacker/pull/2476)
```js
entry: {
home: ['./home.js', './home.scss'],
account: ['./account.js', './account.scss']
}
```
You can now have two entry files with same names inside packs folder, `home.scss` and `home.js`
And, other minor fixes, please see a list of changes [here](https://github.com/rails/webpacker/compare/v4.2.2...v5.0.0)
## [[4.2.2]](https://github.com/rails/webpacker/compare/v4.2.1...v4.2.2) - 2019-12-09
- Fixed issue with webpack clean task for nested assets [#2391](https://github.com/rails/webpacker/pull/2391)
## [[4.2.1]](https://github.com/rails/webpacker/compare/v4.2.0...v4.2.1) - 2019-12-09
- Fixed issue with webpack clean task [#2389](https://github.com/rails/webpacker/pull/2389)
## [[4.2.0]](https://github.com/rails/webpacker/compare/v4.1.0...v4.2.0) - 2019-11-12
- Fixed installer bug [#2366](https://github.com/rails/webpacker/pull/2366)
## [[4.1.0]](https://github.com/rails/webpacker/compare/v4.0.7...v4.1.0) - 2019-11-12
- Added favicon_pack_tag to generate favicon links [#2281](https://github.com/rails/webpacker/pull/2281)
- Add support for Brotli compression [#2273](https://github.com/rails/webpacker/pull/2273)
- Support .(sass|scss).erb [#2259](https://github.com/rails/webpacker/pull/2259)
- Elm: Enable production optimizations when compiling in production [#2234](https://github.com/rails/webpacker/pull/2234)
- fixes webpacker:clean erroring because of nested hashes [#2318](https://github.com/rails/webpacker/pull/2318)
- Revert of production env enforcement [#2341](https://github.com/rails/webpacker/pull/2341)
- Add a preload_pack_asset helper [#2124](https://github.com/rails/webpacker/pull/2124)
- Record the compilation digest even on webpack error [#2117](https://github.com/rails/webpacker/pull/2117)
- See more changes [here](https://github.com/rails/webpacker/compare/v4.0.7...v4.1.0)
## [[4.0.7]](https://github.com/rails/webpacker/compare/v4.0.6...v4.0.7) - 2019-06-03
- Prevent `@babel/plugin-transform-runtime` from rewriting babel helpers in core-js. Remove unneeded runtime `@babel/runtime-corejs3` [#2116](https://github.com/rails/webpacker/pull/2116)
- Fix for: [#2109 Uncaught TypeError: **webpack_require**(...) is not a function](https://github.com/rails/webpacker/issues/2109): **If you are upgrading**, please check your `babel.config.js` against the [default `babel.config.js`](https://github.com/rails/webpacker/blob/master/lib/install/config/babel.config.js):
- `@babel/preset-env` should contain `corejs: 3`
- `@babel/plugin-transform-runtime` should contain `corejs: false`
- Removed unneeded runtime `@babel/runtime-corejs3`
## [[4.0.6]](https://github.com/rails/webpacker/compare/v4.0.5...v4.0.6) - 2019-05-30
- Webpack should not be transpiled [#2111](https://github.com/rails/webpacker/pull/2111)
## [[4.0.5]](https://github.com/rails/webpacker/compare/v4.0.4...v4.0.5) - 2019-05-30
- Don't let babel & core-js transpile each other [#2110](https://github.com/rails/webpacker/pull/2110)
## [[4.0.4]](https://github.com/rails/webpacker/compare/v4.0.3...v4.0.4) - 2019-05-28
- Remove bundler version constraint
## [[4.0.3]](https://github.com/rails/webpacker/compare/v4.0.2...v4.0.3) - 2019-05-28
Please see the diff
##### Breaking changes (for pre-existing apps)
- [`@babel/polyfill`](https://babeljs.io/docs/en/next/babel-polyfill.html) [doesn't make it possible to provide a smooth migration path from `core-js@2` to `core-js@3`](https://github.com/zloirock/core-js/blob/master/docs/2019-03-19-core-js-3-babel-and-a-look-into-the-future.md#babelpolyfill): for this reason, it was decided to deprecate `@babel/polyfill` in favor of separate inclusion of required parts of `core-js` and `regenerator-runtime`. [#2031](https://github.com/rails/webpacker/pull/2031)
In each of your `/packs/*.js` files, change this:
```js
import '@babel/polyfill'
```
to this:
```js
import 'core-js/stable'
import 'regenerator-runtime/runtime'
```
Don't forget to install those dependencies directly!
```sh
yarn add core-js regenerator-runtime
```
## [4.0.2] - 2019-03-06
- Bump the version on npm
## [4.0.1] - 2019-03-04
### Fixed
- Pre-release version installer
## [4.0.0] - 2019-03-04
No changes in this release. See RC releases for changes.
## [4.0.0.rc.8] - 2019-03-03
### Fixed
- Re-enable source maps in production to make debugging in production
easier. Enabling source maps doesn't have drawbacks for most of the
applications since maps are compressed by default and aren't loaded
by browsers unless Dev Tools are opened.
Source maps can be disabled in any environment configuration, e.g:
```js
// config/webpack/production.js
const environment = require('./environment')
environment.config.merge({ devtool: 'none' })
module.exports = environment.toWebpackConfig()
```
- Reintroduced `context` to the file loader. Reverting the simpler paths change
- Updated file loader to have filename based on the path. This change
keeps the old behaviour intact i.e. let people use namespaces for media
inside `app/javascript` and also include media outside of `app/javascript`
with simpler paths, for example from `node_modules` or `app/assets`
```bash
# Files inside app/javascript (i.e. packs source path)
# media/[full_path_relative_to_app_javascript]/name_of_the_asset_with_digest
media/images/google-97e897b3851e415bec4fd30c265eb3ce.jpg
media/images/rails-45b116b1f66cc5e6f9724e8f9a2db73d.png
media/images/some_namespace/google-97e897b3851e415bec4fd30c265eb3ce.jpg
# Files outside app/javascript (i.e. packs source path)
# media/[containing_folder_name]/name_of_the_asset_with_digest
media/some_assets/rails_assets-f0f7bbb5.png
media/webfonts/fa-brands-400-4b115e11.woff2
```
This change is done so we don't end up paths like `media/_/assets/images/rails_assets-f0f7bbb5ef00110a0dcef7c2cb7d34a6.png` or `media/_/_/node_modules/foo-f0f7bbb5ef00110a0dcef7c2cb7d34a6.png` for media outside of
`app/javascript`
## [4.0.0.rc.7] - 2019-01-25
### Fixed
- Webpacker builds test app assets [#1908](https://github.com/rails/webpacker/issues/1908)
## [4.0.0.rc.6] - 2019-01-25
### Fixed
- Remove `context` from file loader in favour of simpler paths
```rb
# before
"_/assets/images/avatar.png": "/packs/_/assets/images/avatar-057862c747f0fdbeae506bdd0516cad1.png"
# after
"media/avatar.png": "/packs/media/avatar-057862c747f0fdbeae506bdd0516cad1.png"
```
To get old behaviour:
```js
// config/webpack/environment.js
const { environment, config } = require('@rails/webpacker')
const { join } = require('path')
const fileLoader = environment.loaders.get('file')
fileLoader.use[0].options.name = '[path][name]-[hash].[ext]'
fileLoader.use[0].options.context = join(config.source_path) // optional if you don't want to expose full paths
```
### Added
- Namespaces for compiled packs in the public directory
```rb
# before
"runtime~hello_react" => "/packs/runtime~hello_react-da2baf7fd07b0e8b6d17.js"
# after
"runtime~hello_react" => "/packs/js/runtime~hello_react-da2baf7fd07b0e8b6d17.js"
```
## [4.0.0.rc.5] - 2019-01-21
### Updated
- Gems and node dependencies
## [4.0.0.rc.4] - 2019-01-21
### Added
- `stylesheet_packs_with_chunks_tag` helper, similar to javascript helper but for
loading stylesheets chunks.
```erb
<%= stylesheet_packs_with_chunks_tag 'calendar', 'map', 'data-turbolinks-track': 'reload' %>
```
**Important:** Pass all your pack names when using `stylesheet_packs_with_chunks_tag`
helper otherwise you will get duplicated chunks on the page.
```erb
<%# DO %>
# <%= stylesheet_packs_with_chunks_tag 'calendar', 'map' %>
<%# DON'T %>
# <%= stylesheet_packs_with_chunks_tag 'calendar' %>
# <%= stylesheet_packs_with_chunks_tag 'map' %>
```
## [4.0.0.rc.3] - 2019-01-17
### Fixed
- Issue with javascript_pack_tag asset duplication [#1898](https://github.com/rails/webpacker/pull/1898)
### Added
- `javascript_packs_with_chunks_tag` helper, which creates html tags
for a pack and all the dependent chunks, when using splitchunks.
```erb
<%= javascript_packs_with_chunks_tag 'calendar', 'map', 'data-turbolinks-track': 'reload' %>
```
**Important:** Pass all your pack names when using `javascript_packs_with_chunks_tag`
helper otherwise you will get duplicated chunks on the page.
```erb
<%# DO %>
<%= javascript_packs_with_chunks_tag 'calendar', 'map' %>
<%# DON'T %>
<%= javascript_packs_with_chunks_tag 'calendar' %>
<%= javascript_packs_with_chunks_tag 'map' %>
```
## [4.0.0.rc.2] - 2018-12-15
### Fixed
- Disable integrity hash generation [#1835](https://github.com/rails/webpacker/issues/1835)
## [4.0.0.rc.1] - 2018-12-14
### Breaking changes
- Order of rules changed so you might have to change append to prepend,
depending on how you want to process packs [#1823](https://github.com/rails/webpacker/pull/1823)
```js
environment.loaders.prepend()
```
- Separate CSS extraction from build environment [#1625](https://github.com/rails/webpacker/pull/1625)
```yml
# Extract and emit a css file
extract_css: true
```
- Separate rule to compile node modules
(fixes cases where ES6 libraries were included in the app code) [#1823](https://github.com/rails/webpacker/pull/1823).
In previous versions only application code was transpiled. Now everything in `node_modules` is transpiled with Babel. In some cases it could break your build (known issue with `mapbox-gl` package being broken by Babel, https://github.com/mapbox/mapbox-gl-js/issues/3422).
[`nodeModules` loader](https://github.com/rails/webpacker/pull/1823/files#diff-456094c8451b5774db50028dfecf4aa8) ignores `config.babel.js` and uses hard-coded `'@babel/preset-env', { modules: false }` config.
To keep previous behavior, remove `nodeModules` loader specifying `environment.loaders.delete('nodeModules');` in your `config/webpack/environment.js` file.
- File loader extensions API [#1823](https://github.com/rails/webpacker/pull/1823)
```yml
# webpacker.yml
static_assets_extensions:
- .pdf
# etc..
```
### Added
- Move `.babelrc` and `.postcssrc` to `.js` variant [#1822](https://github.com/rails/webpacker/pull/1822)
- Use postcss safe parser when optimising css assets [#1822](https://github.com/rails/webpacker/pull/1822)
- Add split chunks api (undocumented)
```js
const { environment } = require('@rails/webpacker')
// Enable with default config
environment.splitChunks()
// Configure via a callback
environment.splitChunks((config) =>
Object.assign({}, config, { optimization: { splitChunks: false } })
)
```
- Allow changing static file extensions using webpacker.yml (undocumented)
## [4.0.0-pre.3] - 2018-10-01
### Added
- Move supported browsers configuration to [.browserslistrc](https://github.com/browserslist/browserslist#queries)
### Breaking changes
- postcss-next is replaced with postcss-preset-env
- babel@7
### Fixed
- Bring back test env [#1563](https://github.com/rails/webpacker/pull/1563)
Please see a list of [commits](https://github.com/rails/webpacker/compare/2dd68f0273074aadb3f869c4c30369d5e4e3fea7...master)
## [4.0.0-pre.2] - 2018-04-2
### Fixed
- Webpack dev server version in installer
## [4.0.0-pre.1] - 2018-04-2
Pre-release to try out webpack 4.0 support
### Added
- Webpack 4.0 support [#1376](https://github.com/rails/webpacker/pull/1316)
### Fixed
- Remove compilation digest file if webpack command fails[#1398](https://github.com/rails/webpacker/issues/1398)
## [3.6.0] - 2019-03-06
See changes: https://github.com/rails/webpacker/compare/88a253ed42966eb2d5c997435e9396881513bce1...3-x-stable
## [3.5.5] - 2018-07-09
See changes: https://github.com/rails/webpacker/compare/e8b197e36c77181ca2e4765c620faea59dcd0351...3-x-stable
### Added
- On CI, sort files & check modified w/ digest intead of mtime[#1522](https://github.com/rails/webpacker/pull/1522)
## [3.5.3] - 2018-05-03
### Fixed
- Relax Javascript package dependencies [#1466](https://github.com/rails/webpacker/pull/1466#issuecomment-386336605)
## [3.5.2] - 2018-04-29
- Pin Javascript package to 3.5.x
## [3.5.1] - 2018-04-29
- Upgraded gems and Javascript packages
## [3.5.0] - 2018-04-29
### Fixed
- Remove compilation digest file if webpack command fails [#1399](https://github.com/rails/webpacker/pull/1399)
- Handle http dev_server setting properly in the proxy [#1420](https://github.com/rails/webpacker/pull/1420)
- Use correct protocol [#1425](https://github.com/rails/webpacker/pull/1425)
### Added
- `image_pack_tag` helper [#1400](https://github.com/rails/webpacker/pull/1400)
- devserver proxy for custom environments [#1415](https://github.com/rails/webpacker/pull/1415)
- Rails webpacker:info task [#1416](https://github.com/rails/webpacker/pull/1416)
- Include `RAILS_RELATIVE_URL_ROOT` environment variable in publicPath [#1428](https://github.com/rails/webpacker/pull/1428)
Complete list of changes: [#1464](https://github.com/rails/webpacker/pull/1464)
## [3.4.3] - 2018-04-3
### Fixed
- Lock webpacker version in installer [#1401](https://github.com/rails/webpacker/issues/1401)
## [3.4.1] - 2018-03-24
### Fixed
- Yarn integrity check in development [#1374](https://github.com/rails/webpacker/issues/1374)
## [3.4.0] - 2018-03-23
**Please use 3.4.1 instead**
### Added
- Support for custom Rails environments [#1359](https://github.com/rails/webpacker/pull/1359)
_This could break the compilation if you set NODE_ENV to custom environment. Now, NODE_ENV only understands production or development mode_
## [3.3.1] - 2018-03-12
### Fixed
- Use webpack dev server 2.x until webpacker supports webpack 4.x [#1338](https://github.com/rails/webpacker/issues/1338)
## [3.3.0] - 2018-03-03
### Added
- Separate task for installing/updating binstubs
- CSS modules support [#1248](https://github.com/rails/webpacker/pull/1248)
- Pass `relative_url_root` to webpacker config [#1236](https://github.com/rails/webpacker/pull/1236)
### Breaking changes
- Fixes [#1281](https://github.com/rails/webpacker/issues/1281) by installing binstubs only as local executables. To upgrade:
```
bundle exec rails webpacker:binstubs
```
- set function is now removed from plugins and loaders, please use `append` or `prepend`
```js
// config/webpack/environment.js
const { environment } = require('@rails/webpacker')
environment.loaders.append('json', {
test: /\.json$/,
use: 'json-loader'
})
```
### Fixed
- Limit ts-loader to 3.5.0 until webpack 4 support [#1308](https://github.com/rails/webpacker/pull/1308)
- Custom env support [#1304](https://github.com/rails/webpacker/pull/1304)
## [3.2.2] - 2018-02-11
### Added
- Stimulus example [https://stimulusjs.org/](https://stimulusjs.org/)
```bash
bundle exec rails webpacker:install:stimulus
```
- Upgrade gems and npm packages [#1254](https://github.com/rails/webpacker/pull/1254)
And, bunch of bug fixes [See changes](https://github.com/rails/webpacker/compare/v3.2.1...v3.2.2)
## [3.2.1] - 2018-01-21
- Disable dev server running? check if no dev server config is present in that environment [#1179](https://github.com/rails/webpacker/pull/1179)
- Fix checking 'webpack' binstub on Windows [#1123](https://github.com/rails/webpacker/pull/1123)
- silence yarn output if checking is successful [#1131](https://github.com/rails/webpacker/pull/1131)
- Update uglifyJs plugin to support ES6 [#1194](https://github.com/rails/webpacker/pull/1194)
- Add typescript installer [#1145](https://github.com/rails/webpacker/pull/1145)
- Update default extensions and move to installer [#1181](https://github.com/rails/webpacker/pull/1181)
- Revert file loader [#1196](https://github.com/rails/webpacker/pull/1196)
## [3.2.0] - 2017-12-16
### To upgrade:
```bash
bundle update webpacker
yarn upgrade @rails/webpacker
```
### Breaking changes
If you are using react, vue, angular, elm, erb or coffeescript inside your
`packs/` please re-run the integration installers as described in the README.
```bash
bundle exec rails webpacker:install:react
bundle exec rails webpacker:install:vue
bundle exec rails webpacker:install:angular
bundle exec rails webpacker:install:elm
bundle exec rails webpacker:install:erb
bundle exec rails webpacker:install:coffee
```
Or simply copy required loaders used in your app from
https://github.com/rails/webpacker/tree/master/lib/install/loaders
into your `config/webpack/loaders/`
directory and add it to webpack build from `config/webpack/environment.js`
```js
const erb = require('./loaders/erb')
const elm = require('./loaders/elm')
const typescript = require('./loaders/typescript')
const vue = require('./loaders/vue')
const coffee = require('./loaders/coffee')
environment.loaders.append('coffee', coffee)
environment.loaders.append('vue', vue)
environment.loaders.append('typescript', typescript)
environment.loaders.append('elm', elm)
environment.loaders.append('erb', erb)
```
In `.postcssrc.yml` you need to change the plugin name from `postcss-smart-import` to `postcss-import`:
```yml
plugins:
postcss-import: {}
postcss-cssnext: {}
```
### Added (npm module)
- Upgrade gems and webpack dependencies
- `postcss-import` in place of `postcss-smart-import`
### Removed (npm module)
- `postcss-smart-import`, `coffee-loader`, `url-loader`, `rails-erb-loader` as dependencies
- `publicPath` from file loader [#1107](https://github.com/rails/webpacker/pull/1107)
### Fixed (npm module)
- Return native array type for `ConfigList` [#1098](https://github.com/rails/webpacker/pull/1098)
### Added (Gem)
- New `asset_pack_url` helper [#1102](https://github.com/rails/webpacker/pull/1102)
- New installers for coffee and erb
```bash
bundle exec rails webpacker:install:erb
bundle exec rails webpacker:install:coffee
```
- Resolved paths from webpacker.yml to compiler watched list
## [3.1.1] - 2017-12-11
### Fixed
- Include default webpacker.yml config inside npm package
## [3.1.0] - 2017-12-11
### Added (npm module)
- Expose base config from environment
```js
environment.config.set('resolve.extensions', ['.foo', '.bar'])
environment.config.set('output.filename', '[name].js')
environment.config.delete('output.chunkFilename')
environment.config.get('resolve')
environment.config.merge({
output: {
filename: '[name].js'
}
})
```
- Expose new API's for loaders and plugins to insert at position
```js
const jsonLoader = {
test: /\.json$/,
exclude: /node_modules/,
loader: 'json-loader'
}
environment.loaders.append('json', jsonLoader)
environment.loaders.prepend('json', jsonLoader)
environment.loaders.insert('json', jsonLoader, { after: 'style' })
environment.loaders.insert('json', jsonLoader, { before: 'babel' })
// Update a plugin
const manifestPlugin = environment.plugins.get('Manifest')
manifestPlugin.opts.writeToFileEmit = false
// Update coffee loader to use coffeescript 2
const babelLoader = environment.loaders.get('babel')
environment.loaders.insert(
'coffee',
{
test: /\.coffee(\.erb)?$/,
use: babelLoader.use.concat(['coffee-loader'])
},
{ before: 'json' }
)
```
- Expose `resolve.modules` paths like loaders and plugins
```js
environment.resolvedModules.append('vendor', 'vendor')
```
- Enable sourcemaps in `style` and `css` loader
- Separate `css` and `sass` loader for easier configuration. `style` loader is now
`css` loader, which resolves `.css` files and `sass` loader resolves `.scss` and `.sass`
files.
```js
// Enable css modules with sass loader
const sassLoader = environment.loaders.get('sass')
const cssLoader = sassLoader.use.find(
(loader) => loader.loader === 'css-loader'
)
cssLoader.options = Object.assign({}, cssLoader.options, {
modules: true,
localIdentName: '[path][name]__[local]--[hash:base64:5]'
})
```
- Expose rest of configurable dev server options from webpacker.yml
```yml
quiet: false
headers:
'Access-Control-Allow-Origin': '*'
watch_options:
ignored: /node_modules/
```
- `pretty` option to disable/enable color and progress output when running dev server
```yml
dev_server:
pretty: false
```
- Enforce deterministic loader order in desc order, starts processing from top to bottom
- Enforce the entire path of all required modules match the exact case of the actual path on disk using [case sensitive paths plugin](https://github.com/Urthen/case-sensitive-paths-webpack-plugin).
- Add url loader to process and embed smaller static files
### Removed
- resolve url loader [#1042](https://github.com/rails/webpacker/issues/1042)
### Added (Gem)
- Allow skipping webpacker compile using an env variable
```bash
WEBPACKER_PRECOMPILE=no|false|n|f
WEBPACKER_PRECOMPILE=false bundle exec rails assets:precompile
```
- Use `WEBPACKER_ASSET_HOST` instead of `ASSET_HOST` for CDN
- Alias `webpacker:compile` task to `assets:precompile` if is not defined so it works
without sprockets
## [3.0.2] - 2017-10-04
### Added
- Allow dev server connect timeout (in seconds) to be configurable, default: 0.01
```rb
# Change to 1s
Webpacker.dev_server.connect_timeout = 1
```
- Restrict the source maps generated in production [#770](https://github.com/rails/webpacker/pull/770)
- Binstubs [#833](https://github.com/rails/webpacker/pull/833)
- Allow dev server settings to be overridden by env variables [#843](https://github.com/rails/webpacker/pull/843)
- A new `lookup` method to manifest to perform lookup without raise and return `nil`
```rb
Webpacker.manifest.lookup('foo.js')
# => nil
Webpacker.manifest.lookup!('foo.js')
# => raises Webpacker::Manifest::MissingEntryError
```
- Catch all exceptions in `DevServer.running?` and return false [#878](https://github.com/rails/webpacker/pull/878)
### Removed
- Inline CLI args for dev server binstub, use env variables instead
- Coffeescript as core dependency. You have to manually add coffeescript now, if you are using
it in your app.
```bash
yarn add coffeescript@1.12.7
# OR coffeescript 2.0
yarn add coffeescript
```
## [3.0.1] - 2017-09-01
### Fixed
- Missing `node_modules/.bin/*` files by bumping minimum Yarn version to 0.25.2 [#727](https://github.com/rails/webpacker/pull/727)
- `webpacker:compile` task so that fails properly when webpack compilation fails [#728](https://github.com/rails/webpacker/pull/728)
- Rack dev server proxy middleware when served under another proxy (example: pow), which uses `HTTP_X_FORWARDED_HOST` header resulting in `404` for webpacker assets
- Make sure tagged logger works with rails < 5 [#716](https://github.com/rails/webpacker/pull/716)
### Added
- Allow webpack dev server listen host/ip to be configurable using additional `--listen-host` option
```bash
./bin/webpack-dev-server --listen-host 0.0.0.0 --host localhost
```
### Removed
- `watchContentBase` from devServer config so it doesn't unncessarily trigger
live reload when manifest changes. If you have applied this workaround from [#724](https://github.com/rails/webpacker/issues/724), please revert the change from `config/webpack/development.js` since this is now fixed.
## [3.0.0] - 2017-08-30
### Added
- `resolved_paths` option to allow adding additional paths webpack should lookup when resolving modules
```yml
# config/webpacker.yml
# Additional paths webpack should lookup modules
resolved_paths: [] # empty by default
```
- `Webpacker::Compiler.fresh?` and `Webpacker::Compiler.stale?` answer the question of whether compilation is needed.
The old `Webpacker::Compiler.compile?` predicate is deprecated.
- Dev server config class that exposes config options through singleton.
```rb
Webpacker.dev_server.running?
```
- Rack middleware proxies webpacker requests to dev server so we can always serve from same-origin and the lookup works out of the box - no more paths prefixing
- `env` attribute on `Webpacker::Compiler` allows setting custom environment variables that the compilation is being run with
```rb
Webpacker::Compiler.env['FRONTEND_API_KEY'] = 'your_secret_key'
```
### Breaking changes
**Note:** requires running `bundle exec rails webpacker:install`
`config/webpack/**/*.js`:
- The majority of this config moved to the [@rails/webpacker npm package](https://www.npmjs.com/package/@rails/webpacker). `webpacker:install` only creates `config/webpack/{environment,development,test,production}.js` now so if you're upgrading from a previous version you can remove all other files.
`webpacker.yml`:
- Move dev-server config options under defaults so it's transparently available in all environments
- Add new `HMR` option for hot-module-replacement
- Add HTTPS
### Removed
- Host info from manifest.json, now looks like this:
```json
{
"hello_react.js": "/packs/hello_react.js"
}
```
### Fixed
- Update `webpack-dev-server.tt` to respect RAILS_ENV and NODE_ENV values [#502](https://github.com/rails/webpacker/issues/502)
- Use `0.0.0.0` as default listen address for `webpack-dev-server`
- Serve assets using `localhost` from dev server - [#424](https://github.com/rails/webpacker/issues/424)
```yml
dev_server:
host: localhost
```
- On Windows, `ruby bin/webpacker` and `ruby bin/webpacker-dev-server` will now bypass yarn, and execute via `node_modules/.bin` directly - [#584](https://github.com/rails/webpacker/pull/584)
### Breaking changes
- Add `compile` and `cache_path` options to `config/webpacker.yml` for configuring lazy compilation of packs when a file under tracked paths is changed [#503](https://github.com/rails/webpacker/pull/503). To enable expected behavior, update `config/webpacker.yml`:
```yaml
default: &default
cache_path: tmp/cache/webpacker
test:
compile: true
development:
compile: true
production:
compile: false
```
- Make test compilation cacheable and configurable so that the lazy compilation
only triggers if files are changed under tracked paths.
Following paths are watched by default -
```rb
["app/javascript/**/*", "yarn.lock", "package.json", "config/webpack/**/*"]
```
To add more paths:
```rb
# config/initializers/webpacker.rb or config/application.rb
Webpacker::Compiler.watched_paths << 'bower_components'
```
## [2.0] - 2017-05-24
### Fixed
- Update `.babelrc` to fix compilation issues - [#306](https://github.com/rails/webpacker/issues/306)
- Duplicated asset hosts - [#320](https://github.com/rails/webpacker/issues/320), [#397](https://github.com/rails/webpacker/pull/397)
- Missing asset host when defined as a `Proc` or on `ActionController::Base.asset_host` directly - [#397](https://github.com/rails/webpacker/pull/397)
- Incorrect asset host when running `webpacker:compile` or `bin/webpack` in development mode - [#397](https://github.com/rails/webpacker/pull/397)
- Update `webpacker:compile` task to use `stdout` and `stderr` for better logging - [#395](https://github.com/rails/webpacker/issues/395)
- ARGV support for `webpack-dev-server` - [#286](https://github.com/rails/webpacker/issues/286)
### Added
- [Elm](http://elm-lang.org) support. You can now add Elm support via the following methods:
- New app: `rails new --webpack=elm`
- Within an existing app: `rails webpacker:install:elm`
- Support for custom `public_output_path` paths independent of `source_entry_path` in `config/webpacker.yml`. `output` is also now relative to `public/`. - [#397](https://github.com/rails/webpacker/pull/397)
Before (compile to `public/packs`):
```yaml
source_entry_path: packs
public_output_path: packs
```
After (compile to `public/sweet/js`):
```yaml
source_entry_path: packs
public_output_path: sweet/js
```
- `https` option to use `https` mode, particularly on platforms like - https://community.c9.io/t/running-a-rails-app/1615 or locally - [#176](https://github.com/rails/webpacker/issues/176)
- [Babel] Dynamic import() and Class Fields and Static Properties babel plugin to `.babelrc`
```json
{
"presets": [
[
"env",
{
"modules": false,
"targets": {
"browsers": "> 1%",
"uglify": true
},
"useBuiltIns": true
}
]
],
"plugins": [
"syntax-dynamic-import",
"transform-class-properties",
{ "spec": true }
]
}
```
- Source-map support for production bundle
#### Breaking Change
- Consolidate and flatten `paths.yml` and `development.server.yml` config into one file - `config/webpacker.yml` - [#403](https://github.com/rails/webpacker/pull/403). This is a breaking change and requires you to re-install webpacker and cleanup old configuration files.
```bash
bundle update webpacker
bundle exec rails webpacker:install
# Remove old/unused configuration files
rm config/webpack/paths.yml
rm config/webpack/development.server.yml
rm config/webpack/development.server.js
```
**Warning**: For now you also have to add a pattern in `.gitignore` by hand.
```diff
/public/packs
+/public/packs-test
/node_modules
```
## [1.2] - 2017-04-27
Some of the changes made requires you to run below commands to install new changes.
```
bundle update webpacker
bundle exec rails webpacker:install
```
### Fixed
- Support Spring - [#205](https://github.com/rails/webpacker/issues/205)
```ruby
Spring.after_fork { Webpacker.bootstrap } if defined?(Spring)
```
- Check node version and yarn before installing webpacker - [#217](https://github.com/rails/webpacker/issues/217)
- Include webpacker helper to views - [#172](https://github.com/rails/webpacker/issues/172)
- Webpacker installer on windows - [#245](https://github.com/rails/webpacker/issues/245)
- Yarn duplication - [#278](https://github.com/rails/webpacker/issues/278)
- Add back Spring for `rails-erb-loader` - [#216](https://github.com/rails/webpacker/issues/216)
- Move babel presets and plugins to .babelrc - [#202](https://github.com/rails/webpacker/issues/202)
### Added
- A changelog - [#211](https://github.com/rails/webpacker/issues/211)
- Minimize CSS assets - [#218](https://github.com/rails/webpacker/issues/218)
- Pack namespacing support - [#201](https://github.com/rails/webpacker/pull/201)
For example:
```
app/javascript/packs/admin/hello_vue.js
app/javascript/packs/admin/hello.vue
app/javascript/packs/hello_vue.js
app/javascript/packs/hello.vue
```
- Add tree-shaking support - [#250](https://github.com/rails/webpacker/pull/250)
- Add initial test case by @kimquy [#259](https://github.com/rails/webpacker/pull/259)
- Compile assets before test:controllers and test:system
### Removed
- Webpack watcher - [#295](https://github.com/rails/webpacker/pull/295)
## [1.1] - 2017-03-24
This release requires you to run below commands to install new features.
```
bundle update webpacker
bundle exec rails webpacker:install
# if installed react, vue or angular
bundle exec rails webpacker:install:[react, angular, vue]
```
### Added (breaking changes)
- Static assets support - [#153](https://github.com/rails/webpacker/pull/153)
- Advanced webpack configuration - [#153](https://github.com/rails/webpacker/pull/153)
### Removed
```rb
config.x.webpacker[:digesting] = true
```
webpacker-5.4.3/.rubocop.yml 0000644 0000041 0000041 00000013331 14123265223 015771 0 ustar www-data www-data require: rubocop-performance
AllCops:
TargetRubyVersion: 2.4
# RuboCop has a bunch of cops enabled by default. This setting tells RuboCop
# to ignore them, so only the ones explicitly set in this file are enabled.
DisabledByDefault: true
Exclude:
- 'lib/install/templates/**'
- 'vendor/**/*'
- 'node_modules/**/*'
# Prefer &&/|| over and/or.
Style/AndOr:
Enabled: true
# Align `when` with `case`.
Layout/CaseIndentation:
Enabled: true
# Align comments with method definitions.
Layout/CommentIndentation:
Enabled: true
# No extra empty lines.
Layout/EmptyLines:
Enabled: true
# In a regular class definition, no empty lines around the body.
Layout/EmptyLinesAroundClassBody:
Enabled: true
# In a regular method definition, no empty lines around the body.
Layout/EmptyLinesAroundMethodBody:
Enabled: true
# In a regular module definition, no empty lines around the body.
Layout/EmptyLinesAroundModuleBody:
Enabled: true
# Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }.
Style/HashSyntax:
Enabled: true
# Method definitions after `private` or `protected` isolated calls need one
# extra level of indentation.
Layout/IndentationConsistency:
Enabled: true
EnforcedStyle: indented_internal_methods
# Detect hard tabs, no hard tabs.
Layout/IndentationStyle:
Enabled: true
# Two spaces, no tabs (for indentation).
Layout/IndentationWidth:
Enabled: true
Layout/SpaceAfterColon:
Enabled: true
Layout/SpaceAfterComma:
Enabled: true
Layout/SpaceAroundEqualsInParameterDefault:
Enabled: true
Layout/SpaceAroundKeyword:
Enabled: true
Layout/SpaceAroundOperators:
Enabled: true
Layout/SpaceBeforeFirstArg:
Enabled: true
# Defining a method with parameters needs parentheses.
Style/MethodDefParentheses:
Enabled: true
# Use `foo {}` not `foo{}`.
Layout/SpaceBeforeBlockBraces:
Enabled: true
# Use `foo { bar }` not `foo {bar}`.
Layout/SpaceInsideBlockBraces:
Enabled: true
# Use `{ a: 1 }` not `{a:1}`.
Layout/SpaceInsideHashLiteralBraces:
Enabled: true
Layout/SpaceInsideParens:
Enabled: true
# Check quotes usage according to lint rule below.
Style/StringLiterals:
Enabled: true
EnforcedStyle: double_quotes
# Blank lines should not have any spaces.
Layout/TrailingEmptyLines:
Enabled: true
# No trailing whitespace.
Layout/TrailingWhitespace:
Enabled: true
# Use quotes for string literals when they are enough.
Style/RedundantPercentQ:
Enabled: true
# Align `end` with the matching keyword or starting expression except for
# assignments, where it should be aligned with the LHS.
Layout/EndAlignment:
Enabled: true
EnforcedStyleAlignWith: variable
# Use my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
Lint/RequireParentheses:
Enabled: true
# Use `bind_call(obj, args, ...)` instead of `bind(obj).call(args, ...)`.
Performance/BindCall:
Enabled: true
# Use `caller(n..n)` instead of `caller`.
Performance/Caller:
Enabled: true
# Use `casecmp` for case comparison.
Performance/Casecmp:
Enabled: true
# Extract Array and Hash literals outside of loops into local variables or constants.
Performance/CollectionLiteralInLoop:
Enabled: true
# Prefer `sort_by(&:foo)` instead of `sort { |a, b| a.foo <=> b.foo }`.
Performance/CompareWithBlock:
Enabled: true
# Use `count` instead of `{select,find_all,filter,reject}...{size,count,length}`.
Performance/Count:
Enabled: true
# Use `delete_prefix` instead of `gsub`.
Performance/DeletePrefix:
Enabled: true
# Use `delete_suffix` instead of `gsub`.
Performance/DeleteSuffix:
Enabled: true
# Use `detect` instead of `select.first`, `find_all.first`, `filter.first`, `select.last`, `find_all.last`, and `filter.last`.
Performance/Detect:
Enabled: true
# Use `str.{start,end}_with?(x, ..., y, ...)` instead of `str.{start,end}_with?(x, ...) || str.{start,end}_with?(y, ...)`.
Performance/DoubleStartEndWith:
Enabled: true
# Use `end_with?` instead of a regex match anchored to the end of a string.
Performance/EndWith:
Enabled: true
# Do not compute the size of statically sized objects except in constants.
Performance/FixedSize:
Enabled: true
# Use `Enumerable#flat_map` instead of `Enumerable#map...Array#flatten(1).
Performance/FlatMap:
Enabled: true
# Use `key?` or `value?` instead of `keys.include?` or `values.include?`.
Performance/InefficientHashSearch:
Enabled: true
# Use `Range#cover?` instead of `Range#include?` (or `Range#member?`).
Performance/RangeInclude:
Enabled: true
# Use `yield` instead of `block.call`.
Performance/RedundantBlockCall:
Enabled: true
# Use `=~` instead of `String#match` or `Regexp#match` in a context where the returned `MatchData` is not needed.
Performance/RedundantMatch:
Enabled: true
# Use Hash#[]=, rather than Hash#merge! with a single key-value pair.
Performance/RedundantMerge:
Enabled: true
# Use `match?` instead of `Regexp#match`, `String#match`, `Symbol#match`, `Regexp#===`, or `=~` when `MatchData` is not used.
Performance/RegexpMatch:
Enabled: true
# Use `reverse_each` instead of `reverse.each`.
Performance/ReverseEach:
Enabled: true
# Use `size` instead of `count` for counting the number of elements in `Array` and `Hash`.
Performance/Size:
Enabled: true
# Use `start_with?` instead of a regex match anchored to the beginning of a string.
Performance/StartWith:
Enabled: true
# Use `tr` instead of `gsub` when you are replacing the same number of characters.
# Use `delete` instead of `gsub` when you are deleting characters.
Performance/StringReplacement:
Enabled: true
# Checks for .times.map calls.
Performance/TimesMap:
Enabled: true
# Use unary plus to get an unfrozen string literal.
Performance/UnfreezeString:
Enabled: true
# Use `URI::DEFAULT_PARSER` instead of `URI::Parser.new`.
Performance/UriDefaultParser:
Enabled: true
webpacker-5.4.3/.gitignore 0000644 0000041 0000041 00000000226 14123265223 015506 0 ustar www-data www-data /.bundle
/pkg
/test/test_app/log
node_modules
.byebug_history
/test/test_app/tmp
yarn-debug.log*
yarn-error.log*
.yarn-integrity
/log
gemfiles/*.lock
webpacker-5.4.3/.node-version 0000644 0000041 0000041 00000000010 14123265223 016116 0 ustar www-data www-data 10.17.0
webpacker-5.4.3/webpacker.gemspec 0000644 0000041 0000041 00000002203 14123265223 017023 0 ustar www-data www-data $:.push File.expand_path("../lib", __FILE__)
require "webpacker/version"
Gem::Specification.new do |s|
s.name = "webpacker"
s.version = Webpacker::VERSION
s.authors = [ "David Heinemeier Hansson", "Gaurav Tiwari" ]
s.email = [ "david@basecamp.com", "gaurav@gauravtiwari.co.uk" ]
s.summary = "Use webpack to manage app-like JavaScript modules in Rails"
s.homepage = "https://github.com/rails/webpacker"
s.license = "MIT"
s.metadata = {
"source_code_uri" => "https://github.com/rails/webpacker/tree/v#{Webpacker::VERSION}",
"changelog_uri" => "https://github.com/rails/webpacker/blob/v#{Webpacker::VERSION}/CHANGELOG.md"
}
s.required_ruby_version = ">= 2.4.0"
s.add_dependency "activesupport", ">= 5.2"
s.add_dependency "railties", ">= 5.2"
s.add_dependency "rack-proxy", ">= 0.6.1"
s.add_dependency "semantic_range", ">= 2.3.0"
s.add_development_dependency "bundler", ">= 1.3.0"
s.add_development_dependency "rubocop", "0.93.1"
s.add_development_dependency "rubocop-performance"
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- test/*`.split("\n")
end
webpacker-5.4.3/.eslintrc.js 0000644 0000041 0000041 00000000441 14123265223 015754 0 ustar www-data www-data module.exports = {
extends: 'airbnb',
rules: {
'comma-dangle': ['error', 'never'],
'import/no-unresolved': 'off',
'import/no-extraneous-dependencies': 'off',
'import/extensions': 'off',
semi: ['error', 'never']
},
env: {
browser: true,
node: true
}
}
webpacker-5.4.3/Rakefile 0000644 0000041 0000041 00000000333 14123265223 015162 0 ustar www-data www-data # frozen_string_literal: true
require "bundler/gem_tasks"
require "rake/testtask"
Rake::TestTask.new do |t|
t.libs << "test"
t.test_files = FileList["test/**/*_test.rb"]
t.verbose = true
end
task default: :test
webpacker-5.4.3/lib/ 0000755 0000041 0000041 00000000000 14123265223 014264 5 ustar www-data www-data webpacker-5.4.3/lib/tasks/ 0000755 0000041 0000041 00000000000 14123265223 015411 5 ustar www-data www-data webpacker-5.4.3/lib/tasks/webpacker.rake 0000644 0000041 0000041 00000003642 14123265223 020225 0 ustar www-data www-data tasks = {
"webpacker:info" => "Provides information on Webpacker's environment",
"webpacker:install" => "Installs and setup webpack with Yarn",
"webpacker:compile" => "Compiles webpack bundles based on environment",
"webpacker:clean" => "Remove old compiled webpacks",
"webpacker:clobber" => "Removes the webpack compiled output directory",
"webpacker:check_node" => "Verifies if Node.js is installed",
"webpacker:check_yarn" => "Verifies if Yarn is installed",
"webpacker:check_binstubs" => "Verifies that webpack & webpack-dev-server are present",
"webpacker:binstubs" => "Installs Webpacker binstubs in this application",
"webpacker:verify_install" => "Verifies if Webpacker is installed",
"webpacker:yarn_install" => "Support for older Rails versions. Install all JavaScript dependencies as specified via Yarn",
"webpacker:install:react" => "Installs and setup example React component",
"webpacker:install:vue" => "Installs and setup example Vue component",
"webpacker:install:angular" => "Installs and setup example Angular component",
"webpacker:install:elm" => "Installs and setup example Elm component",
"webpacker:install:svelte" => "Installs and setup example Svelte component",
"webpacker:install:stimulus" => "Installs and setup example Stimulus component",
"webpacker:install:erb" => "Installs Erb loader with an example",
"webpacker:install:coffee" => "Installs CoffeeScript loader with an example",
"webpacker:install:typescript" => "Installs Typescript loader with an example"
}.freeze
desc "Lists all available tasks in Webpacker"
task :webpacker do
puts "Available Webpacker tasks are:"
tasks.each { |task, message| puts task.ljust(30) + message }
end
webpacker-5.4.3/lib/tasks/installers.rake 0000644 0000041 0000041 00000002122 14123265223 020432 0 ustar www-data www-data installers = {
"Angular": :angular,
"Elm": :elm,
"React": :react,
"Vue": :vue,
"Erb": :erb,
"Coffee": :coffee,
"Typescript": :typescript,
"Svelte": :svelte,
"Stimulus": :stimulus
}.freeze
dependencies = {
"Angular": [:typescript]
}
bin_path = ENV["BUNDLE_BIN"] || "./bin"
namespace :webpacker do
namespace :install do
installers.each do |name, task_name|
desc "Install everything needed for #{name}"
task task_name => ["webpacker:verify_install"] do
template = File.expand_path("../install/#{task_name}.rb", __dir__)
base_path =
if Rails::VERSION::MAJOR >= 5
"#{RbConfig.ruby} #{bin_path}/rails app:template"
else
"#{RbConfig.ruby} #{bin_path}/rake rails:template"
end
dependencies[name] ||= []
dependencies[name].each do |dependency|
dependency_template = File.expand_path("../install/#{dependency}.rb", __dir__)
system "#{base_path} LOCATION=#{dependency_template}"
end
exec "#{base_path} LOCATION=#{template}"
end
end
end
end
webpacker-5.4.3/lib/tasks/webpacker/ 0000755 0000041 0000041 00000000000 14123265223 017354 5 ustar www-data www-data webpacker-5.4.3/lib/tasks/webpacker/compile.rake 0000644 0000041 0000041 00000002360 14123265223 021651 0 ustar www-data www-data $stdout.sync = true
def yarn_install_available?
rails_major = Rails::VERSION::MAJOR
rails_minor = Rails::VERSION::MINOR
rails_major > 5 || (rails_major == 5 && rails_minor >= 1)
end
def enhance_assets_precompile
# yarn:install was added in Rails 5.1
deps = yarn_install_available? ? [] : ["webpacker:yarn_install"]
Rake::Task["assets:precompile"].enhance(deps) do
Rake::Task["webpacker:compile"].invoke
end
end
namespace :webpacker do
desc "Compile JavaScript packs using webpack for production with digests"
task compile: ["webpacker:verify_install", :environment] do
Webpacker.with_node_env(ENV.fetch("NODE_ENV", "production")) do
Webpacker.ensure_log_goes_to_stdout do
if Webpacker.compile
# Successful compilation!
else
# Failed compilation
exit!
end
end
end
end
end
# Compile packs after we've compiled all other assets during precompilation
skip_webpacker_precompile = %w(no false n f).include?(ENV["WEBPACKER_PRECOMPILE"])
unless skip_webpacker_precompile
if Rake::Task.task_defined?("assets:precompile")
enhance_assets_precompile
else
Rake::Task.define_task("assets:precompile" => ["webpacker:yarn_install", "webpacker:compile"])
end
end
webpacker-5.4.3/lib/tasks/webpacker/check_yarn.rake 0000644 0000041 0000041 00000002306 14123265223 022327 0 ustar www-data www-data require "semantic_range"
namespace :webpacker do
desc "Verifies if Yarn is installed"
task :check_yarn do
begin
yarn_version = `yarn --version`.strip
raise Errno::ENOENT if yarn_version.blank?
pkg_path = Pathname.new("#{__dir__}/../../../package.json").realpath
yarn_range = JSON.parse(pkg_path.read)["engines"]["yarn"]
is_valid = SemanticRange.satisfies?(yarn_version, yarn_range) rescue false
is_unsupported = SemanticRange.satisfies?(yarn_version, ">=4.0.0") rescue false
unless is_valid
$stderr.puts "Webpacker requires Yarn \"#{yarn_range}\" and you are using #{yarn_version}"
if is_unsupported
$stderr.puts "This version of Webpacker does not support Yarn #{yarn_version}. Please downgrade to a supported version of Yarn https://yarnpkg.com/lang/en/docs/install/"
else
$stderr.puts "Please upgrade Yarn https://yarnpkg.com/lang/en/docs/install/"
end
$stderr.puts "Exiting!"
exit!
end
rescue Errno::ENOENT
$stderr.puts "Yarn not installed. Please download and install Yarn from https://yarnpkg.com/lang/en/docs/install/"
$stderr.puts "Exiting!"
exit!
end
end
end
webpacker-5.4.3/lib/tasks/webpacker/clobber.rake 0000644 0000041 0000041 00000001147 14123265223 021633 0 ustar www-data www-data require "webpacker/configuration"
namespace :webpacker do
desc "Remove the webpack compiled output directory"
task clobber: ["webpacker:verify_install", :environment] do
Webpacker.clobber
$stdout.puts "Removed webpack output path directory #{Webpacker.config.public_output_path}"
end
end
skip_webpacker_clobber = %w(no false n f).include?(ENV["WEBPACKER_PRECOMPILE"])
unless skip_webpacker_clobber
# Run clobber if the assets:clobber is run
if Rake::Task.task_defined?("assets:clobber")
Rake::Task["assets:clobber"].enhance do
Rake::Task["webpacker:clobber"].invoke
end
end
end
webpacker-5.4.3/lib/tasks/webpacker/clean.rake 0000644 0000041 0000041 00000001306 14123265223 021302 0 ustar www-data www-data $stdout.sync = true
require "webpacker/configuration"
namespace :webpacker do
desc "Remove old compiled webpacks"
task :clean, [:keep, :age] => ["webpacker:verify_install", :environment] do |_, args|
Webpacker.ensure_log_goes_to_stdout do
Webpacker.clean(Integer(args.keep || 2), Integer(args.age || 3600))
end
end
end
skip_webpacker_clean = %w(no false n f).include?(ENV["WEBPACKER_PRECOMPILE"])
unless skip_webpacker_clean
# Run clean if the assets:clean is run
if Rake::Task.task_defined?("assets:clean")
Rake::Task["assets:clean"].enhance do
Rake::Task["webpacker:clean"].invoke
end
else
Rake::Task.define_task("assets:clean" => "webpacker:clean")
end
end
webpacker-5.4.3/lib/tasks/webpacker/info.rake 0000644 0000041 0000041 00000001276 14123265223 021161 0 ustar www-data www-data require "webpacker/version"
namespace :webpacker do
desc "Provide information on Webpacker's environment"
task :info do
$stdout.puts "Ruby: #{`ruby --version`}"
$stdout.puts "Rails: #{Rails.version}"
$stdout.puts "Webpacker: #{Webpacker::VERSION}"
$stdout.puts "Node: #{`node --version`}"
$stdout.puts "Yarn: #{`yarn --version`}"
$stdout.puts "\n"
$stdout.puts "@rails/webpacker: \n#{`npm list @rails/webpacker version`}"
$stdout.puts "Is bin/webpack present?: #{File.exist? 'bin/webpack'}"
$stdout.puts "Is bin/webpack-dev-server present?: #{File.exist? 'bin/webpack-dev-server'}"
$stdout.puts "Is bin/yarn present?: #{File.exist? 'bin/yarn'}"
end
end
webpacker-5.4.3/lib/tasks/webpacker/binstubs.rake 0000644 0000041 0000041 00000000776 14123265223 022063 0 ustar www-data www-data binstubs_template_path = File.expand_path("../../install/binstubs.rb", __dir__).freeze
bin_path = ENV["BUNDLE_BIN"] || "./bin"
namespace :webpacker do
desc "Installs Webpacker binstubs in this application"
task binstubs: [:check_node, :check_yarn] do
if Rails::VERSION::MAJOR >= 5
exec "#{RbConfig.ruby} #{bin_path}/rails app:template LOCATION=#{binstubs_template_path}"
else
exec "#{RbConfig.ruby} #{bin_path}/rake rails:template LOCATION=#{binstubs_template_path}"
end
end
end
webpacker-5.4.3/lib/tasks/webpacker/check_node.rake 0000644 0000041 0000041 00000002412 14123265223 022301 0 ustar www-data www-data require "semantic_range"
namespace :webpacker do
desc "Verifies if Node.js is installed"
task :check_node do
begin
node_version = `node -v || nodejs -v`.strip
raise Errno::ENOENT if node_version.blank?
pkg_path = Pathname.new("#{__dir__}/../../../package.json").realpath
node_range = JSON.parse(pkg_path.read)["engines"]["node"]
is_valid = SemanticRange.satisfies?(node_version, node_range) rescue false
semver_major = node_version[/\d+/] rescue nil
is_unstable = semver_major.to_i.odd? rescue false
if is_unstable
$stderr.puts "Warning: you are using an unstable release of Node.js (#{node_version}). If you encounter issues with Node.js, consider switching to an Active LTS release. More info: https://docs.npmjs.com/try-the-latest-stable-version-of-node"
end
unless is_valid
$stderr.puts "Webpacker requires Node.js \"#{node_range}\" and you are using #{node_version}"
$stderr.puts "Please upgrade Node.js https://nodejs.org/en/download/"
$stderr.puts "Exiting!"
exit!
end
rescue Errno::ENOENT
$stderr.puts "Node.js not installed. Please download and install Node.js https://nodejs.org/en/download/"
$stderr.puts "Exiting!"
exit!
end
end
end
webpacker-5.4.3/lib/tasks/webpacker/check_binstubs.rake 0000644 0000041 0000041 00000000617 14123265223 023212 0 ustar www-data www-data namespace :webpacker do
desc "Verifies that webpack & webpack-dev-server are present."
task :check_binstubs do
unless File.exist?("bin/webpack")
$stderr.puts "webpack binstubs not found.\n"\
"Have you run rails webpacker:install ?\n"\
"Make sure the bin directory or binstubs are not included in .gitignore\n"\
"Exiting!"
exit!
end
end
end
webpacker-5.4.3/lib/tasks/webpacker/verify_install.rake 0000644 0000041 0000041 00000000662 14123265223 023256 0 ustar www-data www-data require "webpacker/configuration"
namespace :webpacker do
desc "Verifies if Webpacker is installed"
task verify_install: [:check_node, :check_yarn, :check_binstubs] do
unless Webpacker.config.config_path.exist?
$stderr.puts "Configuration config/webpacker.yml file not found. \n"\
"Make sure webpacker:install is run successfully before " \
"running dependent tasks"
exit!
end
end
end
webpacker-5.4.3/lib/tasks/webpacker/install.rake 0000644 0000041 0000041 00000000760 14123265223 021671 0 ustar www-data www-data install_template_path = File.expand_path("../../install/template.rb", __dir__).freeze
bin_path = ENV["BUNDLE_BIN"] || "./bin"
namespace :webpacker do
desc "Install Webpacker in this application"
task install: [:check_node, :check_yarn] do
if Rails::VERSION::MAJOR >= 5
exec "#{RbConfig.ruby} #{bin_path}/rails app:template LOCATION=#{install_template_path}"
else
exec "#{RbConfig.ruby} #{bin_path}/rake rails:template LOCATION=#{install_template_path}"
end
end
end
webpacker-5.4.3/lib/tasks/webpacker/yarn_install.rake 0000644 0000041 0000041 00000001040 14123265223 022712 0 ustar www-data www-data namespace :webpacker do
desc "Support for older Rails versions. Install all JavaScript dependencies as specified via Yarn"
task :yarn_install do
valid_node_envs = %w[test development production]
node_env = ENV.fetch("NODE_ENV") do
valid_node_envs.include?(Rails.env) ? Rails.env : "production"
end
yarn_flags =
if `yarn --version`.start_with?("1")
"--no-progress --frozen-lockfile"
else
"--immutable"
end
system({ "NODE_ENV" => node_env }, "yarn install #{yarn_flags}")
end
end
webpacker-5.4.3/lib/webpacker.rb 0000644 0000041 0000041 00000002130 14123265223 016550 0 ustar www-data www-data require "active_support/core_ext/module/attribute_accessors"
require "active_support/core_ext/string/inquiry"
require "active_support/logger"
require "active_support/tagged_logging"
module Webpacker
extend self
def instance=(instance)
@instance = instance
end
def instance
@instance ||= Webpacker::Instance.new
end
def with_node_env(env)
original = ENV["NODE_ENV"]
ENV["NODE_ENV"] = env
yield
ensure
ENV["NODE_ENV"] = original
end
def ensure_log_goes_to_stdout
old_logger = Webpacker.logger
Webpacker.logger = ActiveSupport::Logger.new(STDOUT)
yield
ensure
Webpacker.logger = old_logger
end
delegate :logger, :logger=, :env, to: :instance
delegate :config, :compiler, :manifest, :commands, :dev_server, to: :instance
delegate :bootstrap, :clean, :clobber, :compile, to: :commands
end
require "webpacker/instance"
require "webpacker/env"
require "webpacker/configuration"
require "webpacker/manifest"
require "webpacker/compiler"
require "webpacker/commands"
require "webpacker/dev_server"
require "webpacker/railtie" if defined?(Rails)
webpacker-5.4.3/lib/install/ 0000755 0000041 0000041 00000000000 14123265223 015732 5 ustar www-data www-data webpacker-5.4.3/lib/install/svelte.rb 0000644 0000041 0000041 00000002311 14123265223 017556 0 ustar www-data www-data require "webpacker/configuration"
say "Copying svelte loader to config/webpack/loaders"
copy_file "#{__dir__}/loaders/svelte.js", Rails.root.join("config/webpack/loaders/svelte.js").to_s
say "Adding svelte loader to config/webpack/environment.js"
insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
"const svelte = require('./loaders/svelte')\n",
after: /require\(('|")@rails\/webpacker\1\);?\n/
insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
"environment.loaders.prepend('svelte', svelte)\n",
before: "module.exports"
say "Copying Svelte example entry file to #{Webpacker.config.source_entry_path}"
copy_file "#{__dir__}/examples/svelte/hello_svelte.js",
"#{Webpacker.config.source_entry_path}/hello_svelte.js"
say "Copying Svelte app file to #{Webpacker.config.source_path}"
copy_file "#{__dir__}/examples/svelte/app.svelte",
"#{Webpacker.config.source_path}/app.svelte"
say "Installing all Svelte dependencies"
run "yarn add svelte svelte-loader"
say "Updating webpack paths to include .svelte file extension"
insert_into_file Webpacker.config.config_path, "- .svelte\n".indent(4), after: /\s+extensions:\n/
say "Webpacker now supports Svelte 🎉", :green
webpacker-5.4.3/lib/install/stimulus.rb 0000644 0000041 0000041 00000000760 14123265223 020147 0 ustar www-data www-data say "Appending Stimulus setup code to #{Webpacker.config.source_entry_path}/application.js"
append_to_file "#{Webpacker.config.source_entry_path}/application.js" do
"\n" + open("#{__dir__}/examples/stimulus/application.js").read
end
say "Creating controllers directory"
directory "#{__dir__}/examples/stimulus/controllers", "#{Webpacker.config.source_path}/controllers"
say "Installing all Stimulus dependencies"
run "yarn add stimulus"
say "Webpacker now supports Stimulus.js 🎉", :green
webpacker-5.4.3/lib/install/erb.rb 0000644 0000041 0000041 00000001777 14123265223 017043 0 ustar www-data www-data require "webpacker/configuration"
say "Copying erb loader to config/webpack/loaders"
copy_file "#{__dir__}/loaders/erb.js", Rails.root.join("config/webpack/loaders/erb.js").to_s
say "Adding erb loader to config/webpack/environment.js"
insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
"const erb = require('./loaders/erb')\n",
after: /require\(('|")@rails\/webpacker\1\);?\n/
insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
"environment.loaders.prepend('erb', erb)\n",
before: "module.exports"
say "Updating webpack paths to include .erb file extension"
insert_into_file Webpacker.config.config_path, "- .erb\n".indent(4), after: /\s+extensions:\n/
say "Copying the example entry file to #{Webpacker.config.source_entry_path}"
copy_file "#{__dir__}/examples/erb/hello_erb.js.erb",
"#{Webpacker.config.source_entry_path}/hello_erb.js.erb"
say "Installing all Erb dependencies"
run "yarn add rails-erb-loader"
say "Webpacker now supports Erb in JS 🎉", :green
webpacker-5.4.3/lib/install/template.rb 0000644 0000041 0000041 00000004551 14123265223 020077 0 ustar www-data www-data # Install Webpacker
copy_file "#{__dir__}/config/webpacker.yml", "config/webpacker.yml"
say "Copying webpack core config"
directory "#{__dir__}/config/webpack", "config/webpack"
say "Copying postcss.config.js to app root directory"
copy_file "#{__dir__}/config/postcss.config.js", "postcss.config.js"
say "Copying babel.config.js to app root directory"
copy_file "#{__dir__}/config/babel.config.js", "babel.config.js"
say "Copying .browserslistrc to app root directory"
copy_file "#{__dir__}/config/.browserslistrc", ".browserslistrc"
if Dir.exists?(Webpacker.config.source_path)
say "The JavaScript app source directory already exists"
else
say "Creating JavaScript app source directory"
directory "#{__dir__}/javascript", Webpacker.config.source_path
end
apply "#{__dir__}/binstubs.rb"
if File.exists?(".gitignore")
append_to_file ".gitignore" do
"\n" +
"/public/packs\n" +
"/public/packs-test\n" +
"/node_modules\n" +
"/yarn-error.log\n" +
"yarn-debug.log*\n" +
".yarn-integrity\n"
end
end
if Webpacker::VERSION.match?(/^[0-9]+\.[0-9]+\.[0-9]+$/)
say "Installing all JavaScript dependencies [#{Webpacker::VERSION}]"
run "yarn add @rails/webpacker@#{Webpacker::VERSION}"
else
say "Installing all JavaScript dependencies [from prerelease rails/webpacker]"
run "yarn add @rails/webpacker@next"
end
package_json = File.read("#{__dir__}/../../package.json")
webpack_version = package_json.match(/"webpack": "(.*)"/)[1]
webpack_cli_version = package_json.match(/"webpack-cli": "(.*)"/)[1]
# needed for experimental Yarn 2 support and should not harm Yarn 1
say "Installing webpack and webpack-cli as direct dependencies"
run "yarn add webpack@#{webpack_version} webpack-cli@#{webpack_cli_version}"
say "Installing dev server for live reloading"
run "yarn add --dev webpack-dev-server@^3"
if Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR > 1
say "You need to allow webpack-dev-server host as allowed origin for connect-src.", :yellow
say "This can be done in Rails 5.2+ for development environment in the CSP initializer", :yellow
say "config/initializers/content_security_policy.rb with a snippet like this:", :yellow
say "policy.connect_src :self, :https, \"http://localhost:3035\", \"ws://localhost:3035\" if Rails.env.development?", :yellow
end
say "Webpacker successfully installed 🎉 🍰", :green
webpacker-5.4.3/lib/install/vue.rb 0000644 0000041 0000041 00000004071 14123265223 017060 0 ustar www-data www-data require "webpacker/configuration"
say "Copying vue loader to config/webpack/loaders"
copy_file "#{__dir__}/loaders/vue.js", Rails.root.join("config/webpack/loaders/vue.js").to_s
say "Adding vue loader plugin to config/webpack/environment.js"
insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
"const { VueLoaderPlugin } = require('vue-loader')\n",
after: /require\(('|")@rails\/webpacker\1\);?\n/
insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
"environment.plugins.prepend('VueLoaderPlugin', new VueLoaderPlugin())\n",
before: "module.exports"
say "Adding vue loader to config/webpack/environment.js"
insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
"const vue = require('./loaders/vue')\n",
after: "require('vue-loader')\n"
insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
"environment.loaders.prepend('vue', vue)\n",
before: "module.exports"
say "Updating webpack paths to include .vue file extension"
insert_into_file Webpacker.config.config_path, "- .vue\n".indent(4), after: /\s+extensions:\n/
say "Copying the example entry file to #{Webpacker.config.source_entry_path}"
copy_file "#{__dir__}/examples/vue/hello_vue.js",
"#{Webpacker.config.source_entry_path}/hello_vue.js"
say "Copying Vue app file to #{Webpacker.config.source_entry_path}"
copy_file "#{__dir__}/examples/vue/app.vue",
"#{Webpacker.config.source_path}/app.vue"
say "Installing all Vue dependencies"
run "yarn add vue vue-loader vue-template-compiler"
if Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR > 1
say "You need to enable unsafe-eval rule.", :yellow
say "This can be done in Rails 5.2+ for development environment in the CSP initializer", :yellow
say "config/initializers/content_security_policy.rb with a snippet like this:", :yellow
say "if Rails.env.development?", :yellow
say " policy.script_src :self, :https, :unsafe_eval", :yellow
say "else", :yellow
say " policy.script_src :self, :https", :yellow
say "end", :yellow
end
say "Webpacker now supports Vue.js 🎉", :green
webpacker-5.4.3/lib/install/bin/ 0000755 0000041 0000041 00000000000 14123265223 016502 5 ustar www-data www-data webpacker-5.4.3/lib/install/bin/webpack 0000755 0000041 0000041 00000000636 14123265223 020051 0 ustar www-data www-data #!/usr/bin/env ruby
ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
ENV["NODE_ENV"] ||= "development"
require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)
require "bundler/setup"
require "webpacker"
require "webpacker/webpack_runner"
APP_ROOT = File.expand_path("..", __dir__)
Dir.chdir(APP_ROOT) do
Webpacker::WebpackRunner.run(ARGV)
end
webpacker-5.4.3/lib/install/bin/webpack-dev-server 0000755 0000041 0000041 00000000643 14123265223 022127 0 ustar www-data www-data #!/usr/bin/env ruby
ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
ENV["NODE_ENV"] ||= "development"
require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)
require "bundler/setup"
require "webpacker"
require "webpacker/dev_server_runner"
APP_ROOT = File.expand_path("..", __dir__)
Dir.chdir(APP_ROOT) do
Webpacker::DevServerRunner.run(ARGV)
end
webpacker-5.4.3/lib/install/examples/ 0000755 0000041 0000041 00000000000 14123265223 017550 5 ustar www-data www-data webpacker-5.4.3/lib/install/examples/react/ 0000755 0000041 0000041 00000000000 14123265223 020646 5 ustar www-data www-data webpacker-5.4.3/lib/install/examples/react/tsconfig.json 0000644 0000041 0000041 00000000624 14123265223 023357 0 ustar www-data www-data {
"compilerOptions": {
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": ["es6", "dom"],
"module": "es6",
"moduleResolution": "node",
"sourceMap": true,
"target": "es5",
"jsx": "react",
"noEmit": true
},
"exclude": [
"**/*.spec.ts",
"node_modules",
"vendor",
"public"
],
"compileOnSave": false
}
webpacker-5.4.3/lib/install/examples/react/babel.config.js 0000644 0000041 0000041 00000004402 14123265223 023515 0 ustar www-data www-data module.exports = function(api) {
var validEnv = ['development', 'test', 'production']
var currentEnv = api.env()
var isDevelopmentEnv = api.env('development')
var isProductionEnv = api.env('production')
var isTestEnv = api.env('test')
if (!validEnv.includes(currentEnv)) {
throw new Error(
'Please specify a valid `NODE_ENV` or ' +
'`BABEL_ENV` environment variables. Valid values are "development", ' +
'"test", and "production". Instead, received: ' +
JSON.stringify(currentEnv) +
'.'
)
}
return {
presets: [
isTestEnv && [
'@babel/preset-env',
{
targets: {
node: 'current'
},
modules: 'commonjs'
},
'@babel/preset-react'
],
(isProductionEnv || isDevelopmentEnv) && [
'@babel/preset-env',
{
forceAllTransforms: true,
useBuiltIns: 'entry',
corejs: 3,
modules: false,
exclude: ['transform-typeof-symbol']
}
],
[
'@babel/preset-react',
{
development: isDevelopmentEnv || isTestEnv,
useBuiltIns: true
}
]
].filter(Boolean),
plugins: [
'babel-plugin-macros',
'@babel/plugin-syntax-dynamic-import',
isTestEnv && 'babel-plugin-dynamic-import-node',
'@babel/plugin-transform-destructuring',
[
'@babel/plugin-proposal-class-properties',
{
loose: true
}
],
[
'@babel/plugin-proposal-object-rest-spread',
{
useBuiltIns: true
}
],
[
'@babel/plugin-proposal-private-methods',
{
loose: true
}
],
[
'@babel/plugin-proposal-private-property-in-object',
{
loose: true
}
],
[
'@babel/plugin-transform-runtime',
{
helpers: false,
regenerator: true,
corejs: false
}
],
[
'@babel/plugin-transform-regenerator',
{
async: false
}
],
isProductionEnv && [
'babel-plugin-transform-react-remove-prop-types',
{
removeImport: true
}
]
].filter(Boolean)
}
}
webpacker-5.4.3/lib/install/examples/react/hello_react.jsx 0000644 0000041 0000041 00000001204 14123265223 023652 0 ustar www-data www-data // Run this example by adding <%= javascript_pack_tag 'hello_react' %> to the head of your layout file,
// like app/views/layouts/application.html.erb. All it does is render Hello React
at the bottom
// of the page.
import React from 'react'
import ReactDOM from 'react-dom'
import PropTypes from 'prop-types'
const Hello = props => (
Hello {props.name}!
)
Hello.defaultProps = {
name: 'David'
}
Hello.propTypes = {
name: PropTypes.string
}
document.addEventListener('DOMContentLoaded', () => {
ReactDOM.render(
,
document.body.appendChild(document.createElement('div')),
)
})
webpacker-5.4.3/lib/install/examples/typescript/ 0000755 0000041 0000041 00000000000 14123265223 021756 5 ustar www-data www-data webpacker-5.4.3/lib/install/examples/typescript/tsconfig.json 0000644 0000041 0000041 00000000736 14123265223 024473 0 ustar www-data www-data {
"compilerOptions": {
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": ["es6", "dom"],
"module": "es6",
"moduleResolution": "node",
"baseUrl": ".",
"paths": {
"*": ["node_modules/*", "app/javascript/*"]
},
"sourceMap": true,
"target": "es5",
"noEmit": true
},
"exclude": [
"**/*.spec.ts",
"node_modules",
"vendor",
"public"
],
"compileOnSave": false
}
webpacker-5.4.3/lib/install/examples/typescript/hello_typescript.ts 0000644 0000041 0000041 00000000312 14123265223 025713 0 ustar www-data www-data // Run this example by adding <%= javascript_pack_tag 'hello_typescript' %> to the head of your layout file,
// like app/views/layouts/application.html.erb.
console.log('Hello world from typescript');
webpacker-5.4.3/lib/install/examples/angular/ 0000755 0000041 0000041 00000000000 14123265223 021201 5 ustar www-data www-data webpacker-5.4.3/lib/install/examples/angular/hello_angular.js 0000644 0000041 0000041 00000000314 14123265223 024351 0 ustar www-data www-data // Run this Angular example by adding the following HTML markup to your view:
//
// Loading...
//
// <%= javascript_pack_tag 'hello_angular' %>
require('../hello_angular')
webpacker-5.4.3/lib/install/examples/angular/hello_angular/ 0000755 0000041 0000041 00000000000 14123265223 024015 5 ustar www-data www-data webpacker-5.4.3/lib/install/examples/angular/hello_angular/index.ts 0000644 0000041 0000041 00000000406 14123265223 025474 0 ustar www-data www-data import './polyfills.ts';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
document.addEventListener('DOMContentLoaded', () => {
platformBrowserDynamic().bootstrapModule(AppModule);
});
webpacker-5.4.3/lib/install/examples/angular/hello_angular/app/ 0000755 0000041 0000041 00000000000 14123265223 024575 5 ustar www-data www-data webpacker-5.4.3/lib/install/examples/angular/hello_angular/app/app.component.ts 0000644 0000041 0000041 00000000262 14123265223 027726 0 ustar www-data www-data import { Component } from '@angular/core';
@Component({
selector: 'hello-angular',
template: `Hello {{name}} `
})
export class AppComponent {
name = 'Angular!';
}
webpacker-5.4.3/lib/install/examples/angular/hello_angular/app/app.module.ts 0000644 0000041 0000041 00000000472 14123265223 027214 0 ustar www-data www-data import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
webpacker-5.4.3/lib/install/examples/angular/hello_angular/polyfills.ts 0000644 0000041 0000041 00000004761 14123265223 026412 0 ustar www-data www-data /**
* This file includes polyfills needed by Angular and is loaded before the app.
* You can add your own extra polyfills to this file.
*
* This file is divided into 2 sections:
* 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
* 2. Application imports. Files imported after ZoneJS that should be loaded before your main
* file.
*
* The current setup is for so-called "evergreen" browsers; the last versions of browsers that
* automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
* Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
*
* Learn more in https://angular.io/docs/ts/latest/guide/browser-support.html
*/
/***************************************************************************************************
* BROWSER POLYFILLS
*/
/** IE9, IE10 and IE11 requires all of the following polyfills. **/
// import 'core-js/es6/symbol';
// import 'core-js/es6/object';
// import 'core-js/es6/function';
// import 'core-js/es6/parse-int';
// import 'core-js/es6/parse-float';
// import 'core-js/es6/number';
// import 'core-js/es6/math';
// import 'core-js/es6/string';
// import 'core-js/es6/date';
// import 'core-js/es6/array';
// import 'core-js/es6/regexp';
// import 'core-js/es6/map';
// import 'core-js/es6/weak-map';
// import 'core-js/es6/set';
/** IE10 and IE11 requires the following for NgClass support on SVG elements */
// import 'classlist.js'; // Run `npm install --save classlist.js`.
/** Evergreen browsers require these. **/
import 'core-js/es/reflect';
import 'core-js/proposals/reflect-metadata';
/**
* Required to support Web Animations `@angular/animation`.
* Needed for: All but Chrome, Firefox and Opera. http://caniuse.com/#feat=web-animation
**/
// import 'web-animations-js'; // Run `npm install --save web-animations-js`.
/***************************************************************************************************
* Zone JS is required by Angular itself.
*/
import 'zone.js/dist/zone';
// import 'zone.js/dist/long-stack-trace-zone' // async stack traces with zone.js
/***************************************************************************************************
* APPLICATION IMPORTS
*/
/**
* Date, currency, decimal and percent pipes.
* Needed for: All but Chrome, Firefox, Edge, IE11 and Safari 10
*/
// import 'intl'; // Run `npm install --save intl`.
/**
* Need to import at least one locale-data with intl.
*/
// import 'intl/locale-data/jsonp/en';
webpacker-5.4.3/lib/install/examples/erb/ 0000755 0000041 0000041 00000000000 14123265223 020320 5 ustar www-data www-data webpacker-5.4.3/lib/install/examples/erb/hello_erb.js.erb 0000644 0000041 0000041 00000000437 14123265223 023364 0 ustar www-data www-data // Run this example by adding <%%= javascript_pack_tag 'hello_erb' %> to the head of your layout file,
// like app/views/layouts/application.html.erb. Don't forget to uncomment erb tag after adding it to your layout file.
<% name = 'Erb' %>
console.log('Hello world from <%= name %>')
webpacker-5.4.3/lib/install/examples/stimulus/ 0000755 0000041 0000041 00000000000 14123265223 021435 5 ustar www-data www-data webpacker-5.4.3/lib/install/examples/stimulus/controllers/ 0000755 0000041 0000041 00000000000 14123265223 024003 5 ustar www-data www-data webpacker-5.4.3/lib/install/examples/stimulus/controllers/index.js 0000644 0000041 0000041 00000000614 14123265223 025451 0 ustar www-data www-data // Load all the controllers within this directory and all subdirectories.
// Controller files must be named *_controller.js.
import { Application } from "stimulus"
import { definitionsFromContext } from "stimulus/webpack-helpers"
const application = Application.start()
const context = require.context("controllers", true, /_controller\.js$/)
application.load(definitionsFromContext(context))
webpacker-5.4.3/lib/install/examples/stimulus/controllers/hello_controller.js 0000644 0000041 0000041 00000000700 14123265223 027704 0 ustar www-data www-data // Visit The Stimulus Handbook for more details
// https://stimulusjs.org/handbook/introduction
//
// This example controller works with specially annotated HTML like:
//
//
//
//
import { Controller } from "stimulus"
export default class extends Controller {
static targets = [ "output" ]
connect() {
this.outputTarget.textContent = 'Hello, Stimulus!'
}
}
webpacker-5.4.3/lib/install/examples/stimulus/application.js 0000644 0000041 0000041 00000000025 14123265223 024273 0 ustar www-data www-data import "controllers"
webpacker-5.4.3/lib/install/examples/coffee/ 0000755 0000041 0000041 00000000000 14123265223 020777 5 ustar www-data www-data webpacker-5.4.3/lib/install/examples/coffee/hello_coffee.coffee 0000644 0000041 0000041 00000000304 14123265223 024557 0 ustar www-data www-data # Run this example by adding <%= javascript_pack_tag 'hello_coffee' %> to the head of your layout file,
# like app/views/layouts/application.html.erb.
console.log 'Hello world from coffeescript'
webpacker-5.4.3/lib/install/examples/elm/ 0000755 0000041 0000041 00000000000 14123265223 020325 5 ustar www-data www-data webpacker-5.4.3/lib/install/examples/elm/Main.elm 0000644 0000041 0000041 00000001717 14123265223 021716 0 ustar www-data www-data module Main exposing (..)
import Browser
import Html exposing (Html, h1, text)
import Html.Attributes exposing (style)
-- MODEL
type alias Model =
{
}
-- INIT
init : (Model, Cmd Message)
init =
(Model, Cmd.none)
-- VIEW
view : Model -> Html Message
view model =
-- The inline style is being used for example purposes in order to keep this example simple and
-- avoid loading additional resources. Use a proper stylesheet when building your own app.
h1 [style "display" "flex", style "justify-content" "center"]
[text "Hello Elm!"]
-- MESSAGE
type Message
= None
-- UPDATE
update : Message -> Model -> (Model, Cmd Message)
update message model =
(model, Cmd.none)
-- SUBSCRIPTIONS
subscriptions : Model -> Sub Message
subscriptions model =
Sub.none
-- MAIN
main : Program (Maybe {}) Model Message
main =
Browser.element
{
init = always init,
view = view,
update = update,
subscriptions = subscriptions
}
webpacker-5.4.3/lib/install/examples/elm/hello_elm.js 0000644 0000041 0000041 00000000635 14123265223 022627 0 ustar www-data www-data // Run this example by adding <%= javascript_pack_tag "hello_elm" %> to the
// head of your layout file, like app/views/layouts/application.html.erb.
// It will render "Hello Elm!" within the page.
import {
Elm
} from '../Main'
document.addEventListener('DOMContentLoaded', () => {
const target = document.createElement('div')
document.body.appendChild(target)
Elm.Main.init({
node: target
})
})
webpacker-5.4.3/lib/install/examples/vue/ 0000755 0000041 0000041 00000000000 14123265223 020347 5 ustar www-data www-data webpacker-5.4.3/lib/install/examples/vue/hello_vue.js 0000644 0000041 0000041 00000003550 14123265223 022672 0 ustar www-data www-data /* eslint no-console: 0 */
// Run this example by adding <%= javascript_pack_tag 'hello_vue' %> (and
// <%= stylesheet_pack_tag 'hello_vue' %> if you have styles in your component)
// to the head of your layout file,
// like app/views/layouts/application.html.erb.
// All it does is render Hello Vue
at the bottom of the page.
import Vue from 'vue'
import App from '../app.vue'
document.addEventListener('DOMContentLoaded', () => {
const app = new Vue({
render: h => h(App)
}).$mount()
document.body.appendChild(app.$el)
console.log(app)
})
// The above code uses Vue without the compiler, which means you cannot
// use Vue to target elements in your existing html templates. You would
// need to always use single file components.
// To be able to target elements in your existing html/erb templates,
// comment out the above code and uncomment the below
// Add <%= javascript_pack_tag 'hello_vue' %> to your layout
// Then add this markup to your html template:
//
//
// import Vue from 'vue/dist/vue.esm'
// import App from '../app.vue'
//
// document.addEventListener('DOMContentLoaded', () => {
// const app = new Vue({
// el: '#hello',
// data: {
// message: "Can you say hello?"
// },
// components: { App }
// })
// })
//
//
//
// If the project is using turbolinks, install 'vue-turbolinks':
//
// yarn add vue-turbolinks
//
// Then uncomment the code block below:
//
// import TurbolinksAdapter from 'vue-turbolinks'
// import Vue from 'vue/dist/vue.esm'
// import App from '../app.vue'
//
// Vue.use(TurbolinksAdapter)
//
// document.addEventListener('turbolinks:load', () => {
// const app = new Vue({
// el: '#hello',
// data: () => {
// return {
// message: "Can you say hello?"
// }
// },
// components: { App }
// })
// })
webpacker-5.4.3/lib/install/examples/vue/app.vue 0000644 0000041 0000041 00000000401 14123265223 021643 0 ustar www-data www-data
webpacker-5.4.3/lib/install/examples/svelte/ 0000755 0000041 0000041 00000000000 14123265223 021052 5 ustar www-data www-data webpacker-5.4.3/lib/install/examples/svelte/hello_svelte.js 0000644 0000041 0000041 00000001056 14123265223 024077 0 ustar www-data www-data /* eslint no-console: 0 */
// Run this example by adding <%= javascript_pack_tag 'hello_svelte' %> (and
// <%= stylesheet_pack_tag 'hello_svelte' %> if you have styles in your component)
// to the head of your layout file,
// like app/views/layouts/application.html.erb.
// All it does is render Hello Svelte!
at the bottom of the page.
import App from '../app.svelte'
document.addEventListener('DOMContentLoaded', () => {
const app = new App({
target: document.body,
props: {
name: 'Svelte'
}
});
window.app = app;
})
webpacker-5.4.3/lib/install/examples/svelte/app.svelte 0000644 0000041 0000041 00000000156 14123265223 023060 0 ustar www-data www-data
Hello {name}!