webpacker-jets 3.2.100
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.eslintignore +4 -0
- data/.eslintrc.js +14 -0
- data/.gitignore +6 -0
- data/.rubocop.yml +124 -0
- data/.travis.yml +32 -0
- data/CHANGELOG.md +523 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +154 -0
- data/MIT-LICENSE +20 -0
- data/README.md +445 -0
- data/Rakefile +12 -0
- data/docs/assets.md +106 -0
- data/docs/cloud9.md +310 -0
- data/docs/css.md +116 -0
- data/docs/deployment.md +74 -0
- data/docs/docker.md +49 -0
- data/docs/env.md +65 -0
- data/docs/es6.md +53 -0
- data/docs/folder-structure.md +66 -0
- data/docs/misc.md +23 -0
- data/docs/props.md +223 -0
- data/docs/testing.md +128 -0
- data/docs/troubleshooting.md +119 -0
- data/docs/typescript.md +116 -0
- data/docs/webpack-dev-server.md +92 -0
- data/docs/webpack.md +297 -0
- data/docs/yarn.md +12 -0
- data/exe/webpack +8 -0
- data/exe/webpack-dev-server +8 -0
- data/gemfiles/Gemfile-rails-edge +13 -0
- data/gemfiles/Gemfile-rails.4.2.x +10 -0
- data/gemfiles/Gemfile-rails.5.0.x +10 -0
- data/gemfiles/Gemfile-rails.5.1.x +10 -0
- data/lib/install/angular.rb +27 -0
- data/lib/install/coffee.rb +22 -0
- data/lib/install/config/.babelrc +18 -0
- data/lib/install/config/.postcssrc.yml +3 -0
- data/lib/install/config/webpack/development.js +3 -0
- data/lib/install/config/webpack/environment.js +3 -0
- data/lib/install/config/webpack/production.js +3 -0
- data/lib/install/config/webpack/staging.js +3 -0
- data/lib/install/config/webpack/test.js +3 -0
- data/lib/install/config/webpacker.yml +79 -0
- data/lib/install/elm.rb +38 -0
- data/lib/install/erb.rb +22 -0
- data/lib/install/examples/angular/hello_angular.js +7 -0
- data/lib/install/examples/angular/hello_angular/app/app.component.ts +9 -0
- data/lib/install/examples/angular/hello_angular/app/app.module.ts +16 -0
- data/lib/install/examples/angular/hello_angular/index.ts +8 -0
- data/lib/install/examples/angular/hello_angular/polyfills.ts +73 -0
- data/lib/install/examples/angular/tsconfig.json +19 -0
- data/lib/install/examples/coffee/hello_coffee.coffee +4 -0
- data/lib/install/examples/elm/Main.elm +54 -0
- data/lib/install/examples/elm/hello_elm.js +12 -0
- data/lib/install/examples/erb/hello_erb.js.erb +6 -0
- data/lib/install/examples/react/.babelrc +6 -0
- data/lib/install/examples/react/hello_react.jsx +26 -0
- data/lib/install/examples/vue/app.vue +22 -0
- data/lib/install/examples/vue/hello_vue.js +70 -0
- data/lib/install/javascript/packs/application.js +10 -0
- data/lib/install/loaders/coffee.js +6 -0
- data/lib/install/loaders/elm.js +23 -0
- data/lib/install/loaders/erb.js +11 -0
- data/lib/install/loaders/typescript.js +6 -0
- data/lib/install/loaders/vue.js +13 -0
- data/lib/install/react.rb +28 -0
- data/lib/install/template.rb +37 -0
- data/lib/install/vue.rb +26 -0
- data/lib/tasks/installers.rake +24 -0
- data/lib/tasks/webpacker.rake +22 -0
- data/lib/tasks/webpacker/check_binstubs.rake +12 -0
- data/lib/tasks/webpacker/check_node.rake +24 -0
- data/lib/tasks/webpacker/check_yarn.rake +24 -0
- data/lib/tasks/webpacker/clobber.rake +16 -0
- data/lib/tasks/webpacker/compile.rake +41 -0
- data/lib/tasks/webpacker/install.rake +13 -0
- data/lib/tasks/webpacker/verify_install.rake +16 -0
- data/lib/tasks/webpacker/yarn_install.rake +6 -0
- data/lib/webpacker.rb +32 -0
- data/lib/webpacker/commands.rb +23 -0
- data/lib/webpacker/compiler.rb +88 -0
- data/lib/webpacker/configuration.rb +87 -0
- data/lib/webpacker/dev_server.rb +61 -0
- data/lib/webpacker/dev_server_proxy.rb +26 -0
- data/lib/webpacker/dev_server_runner.rb +51 -0
- data/lib/webpacker/helper.rb +66 -0
- data/lib/webpacker/instance.rb +44 -0
- data/lib/webpacker/manifest.rb +75 -0
- data/lib/webpacker/railtie.rb +82 -0
- data/lib/webpacker/rake_tasks.rb +6 -0
- data/lib/webpacker/runner.rb +22 -0
- data/lib/webpacker/version.rb +9 -0
- data/lib/webpacker/webpack_runner.rb +15 -0
- data/package.json +67 -0
- data/package/__tests__/environment.js +74 -0
- data/package/config.js +34 -0
- data/package/config_types/__tests__/config_list.js +123 -0
- data/package/config_types/__tests__/config_object.js +43 -0
- data/package/config_types/config_list.js +85 -0
- data/package/config_types/config_object.js +55 -0
- data/package/config_types/index.js +7 -0
- data/package/environment.js +116 -0
- data/package/environments/development.js +46 -0
- data/package/environments/production.js +37 -0
- data/package/environments/test.js +3 -0
- data/package/index.js +20 -0
- data/package/rules/babel.js +13 -0
- data/package/rules/css.js +39 -0
- data/package/rules/file.js +13 -0
- data/package/rules/index.js +11 -0
- data/package/rules/sass.js +15 -0
- data/package/utils/__tests__/deep_assign.js +11 -0
- data/package/utils/__tests__/deep_merge.js +10 -0
- data/package/utils/__tests__/objectify.js +9 -0
- data/package/utils/deep_assign.js +22 -0
- data/package/utils/deep_merge.js +23 -0
- data/package/utils/helpers.js +32 -0
- data/package/utils/objectify.js +4 -0
- data/test/command_test.rb +27 -0
- data/test/compiler_test.rb +35 -0
- data/test/configuration_test.rb +69 -0
- data/test/dev_server_test.rb +24 -0
- data/test/helper_test.rb +52 -0
- data/test/manifest_test.rb +28 -0
- data/test/rake_tasks_test.rb +29 -0
- data/test/test_app/Rakefile +3 -0
- data/test/test_app/app/javascript/packs/application.js +10 -0
- data/test/test_app/config/application.rb +11 -0
- data/test/test_app/config/environment.rb +4 -0
- data/test/test_app/config/webpacker.yml +65 -0
- data/test/test_app/public/packs/manifest.json +6 -0
- data/test/test_helper.rb +29 -0
- data/webpacker-jets.gemspec +29 -0
- data/yarn.lock +5768 -0
- metadata +250 -0
data/docs/testing.md
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
# Testing
|
2
|
+
|
3
|
+
## Karma setup for Typescript
|
4
|
+
|
5
|
+
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).
|
6
|
+
|
7
|
+
```js
|
8
|
+
// package.json
|
9
|
+
"scripts": {
|
10
|
+
"test": "NODE_ENV=test karma start"
|
11
|
+
},
|
12
|
+
"dependencies": {
|
13
|
+
"typescript": "^2.5.2",
|
14
|
+
"ts-loader": "^2.3.7"
|
15
|
+
},
|
16
|
+
"devDependencies": {
|
17
|
+
"karma": "^1.7.1",
|
18
|
+
"karma-webpack": "^2.0.4",
|
19
|
+
"karma-chrome-launcher": "^2.2.0",
|
20
|
+
"karma-jquery": "^0.2.2",
|
21
|
+
"karma-jasmine": "^1.1.0",
|
22
|
+
"karma-jasmine-jquery": "^0.1.1",
|
23
|
+
"jasmine-core": "^2.8.0",
|
24
|
+
[optional] "karma-coverage": "^1.1.1",
|
25
|
+
[optional] "karma-coverage-istanbul-reporter": "^1.3.0",
|
26
|
+
[optional] "karma-spec-reporter": "0.0.31",
|
27
|
+
[optional] "istanbul-instrumenter-loader": "^3.0.0",
|
28
|
+
}
|
29
|
+
```
|
30
|
+
|
31
|
+
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.
|
32
|
+
|
33
|
+
```js
|
34
|
+
// config/webpack/test.js
|
35
|
+
const environment = require('./environment')
|
36
|
+
environment.plugins.get('Manifest').opts.writeToFileEmit = process.env.NODE_ENV !== 'test'
|
37
|
+
environment.loaders.set('istanbul-instrumenter', {
|
38
|
+
test: /\.ts$/,
|
39
|
+
enforce: "post",
|
40
|
+
loader: "istanbul-instrumenter-loader",
|
41
|
+
query: {
|
42
|
+
esModules: true
|
43
|
+
},
|
44
|
+
exclude: ["node_modules", /\.test\.ts$/]
|
45
|
+
}) /* optional */
|
46
|
+
module.exports = environment.toWebpackConfig()
|
47
|
+
```
|
48
|
+
|
49
|
+
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).
|
50
|
+
|
51
|
+
```js
|
52
|
+
// karma.conf.js
|
53
|
+
const webpackConfig = require('./config/webpack/test.js')
|
54
|
+
module.exports = function(config) {
|
55
|
+
config.set({
|
56
|
+
basePath: "",
|
57
|
+
frameworks: ["jquery-3.2.1", "jasmine-jquery", "jasmine"],
|
58
|
+
plugins: [
|
59
|
+
"karma-jquery",
|
60
|
+
"karma-jasmine-jquery",
|
61
|
+
"karma-jasmine",
|
62
|
+
"karma-webpack",
|
63
|
+
"karma-chrome-launcher",
|
64
|
+
"karma-coverage-istanbul-reporter" /* optional */,
|
65
|
+
"karma-spec-reporter" /* optional */
|
66
|
+
],
|
67
|
+
files: [ "/* add spec files */" ],
|
68
|
+
exclude: [],
|
69
|
+
webpack: webpackConfig,
|
70
|
+
preprocessors: {"/* add spec files */" : ["webpack"]},
|
71
|
+
mime: { "text/x-typescript": ["ts"] },
|
72
|
+
reporters: ["progress", "coverage-istanbul" /* optional */],
|
73
|
+
coverageIstanbulReporter: {
|
74
|
+
reports: [ 'html', 'lcovonly', 'text-summary' ],
|
75
|
+
fixWebpackSourcePaths: true
|
76
|
+
} /* optional */,
|
77
|
+
port: 9876,
|
78
|
+
colors: true,
|
79
|
+
logLevel: config.LOG_INFO,
|
80
|
+
autoWatch: true,
|
81
|
+
browsers: ["Chrome"],
|
82
|
+
singleRun: true
|
83
|
+
});
|
84
|
+
};
|
85
|
+
```
|
86
|
+
|
87
|
+
## Lazy compilation
|
88
|
+
|
89
|
+
Webpacker lazily compiles assets in test env so you can write your tests without any extra
|
90
|
+
setup and everything will just work out of the box.
|
91
|
+
|
92
|
+
Here is a sample system test case with hello_react example component:
|
93
|
+
|
94
|
+
```js
|
95
|
+
// Example React component
|
96
|
+
|
97
|
+
import React from 'react'
|
98
|
+
import ReactDOM from 'react-dom'
|
99
|
+
import PropTypes from 'prop-types'
|
100
|
+
|
101
|
+
const Hello = props => (
|
102
|
+
<div>Hello David</div>
|
103
|
+
)
|
104
|
+
|
105
|
+
document.addEventListener('DOMContentLoaded', () => {
|
106
|
+
ReactDOM.render(
|
107
|
+
<Hello />,
|
108
|
+
document.body.appendChild(document.createElement('div')),
|
109
|
+
)
|
110
|
+
})
|
111
|
+
```
|
112
|
+
|
113
|
+
```erb
|
114
|
+
<%# views/pages/home.html.erb %>
|
115
|
+
|
116
|
+
<%= javascript_pack_tag "hello_react" %>
|
117
|
+
```
|
118
|
+
|
119
|
+
```rb
|
120
|
+
# Tests example React component
|
121
|
+
require "application_system_test_case"
|
122
|
+
class HomesTest < ApplicationSystemTestCase
|
123
|
+
test "can see the hello message" do
|
124
|
+
visit root_url
|
125
|
+
assert_selector "h5", text: "Hello! David"
|
126
|
+
end
|
127
|
+
end
|
128
|
+
```
|
@@ -0,0 +1,119 @@
|
|
1
|
+
# Troubleshooting
|
2
|
+
|
3
|
+
|
4
|
+
## ENOENT: no such file or directory - node-sass
|
5
|
+
|
6
|
+
* If you get this error `ENOENT: no such file or directory - node-sass` on Heroku
|
7
|
+
or elsewhere during `assets:precompile` or `jets webpacker:compile`
|
8
|
+
then you would need to rebuild node-sass. It's a bit of a weird error;
|
9
|
+
basically, it can't find the `node-sass` binary.
|
10
|
+
An easy solution is to create a postinstall hook - `npm rebuild node-sass` in
|
11
|
+
`package.json` and that will ensure `node-sass` is rebuilt whenever
|
12
|
+
you install any new modules.
|
13
|
+
|
14
|
+
|
15
|
+
## Can't find hello_react.js in manifest.json
|
16
|
+
|
17
|
+
* If you get this error `Can't find hello_react.js in manifest.json`
|
18
|
+
when loading a view in the browser it's because webpack is still compiling packs.
|
19
|
+
Webpacker uses a `manifest.json` file to keep track of packs in all environments,
|
20
|
+
however since this file is generated after packs are compiled by webpack. So,
|
21
|
+
if you load a view in browser whilst webpack is compiling you will get this error.
|
22
|
+
Therefore, make sure webpack
|
23
|
+
(i.e `./bin/webpack-dev-server`) is running and has
|
24
|
+
completed the compilation successfully before loading a view.
|
25
|
+
|
26
|
+
|
27
|
+
## throw er; // Unhandled 'error' event
|
28
|
+
|
29
|
+
* If you get this error while trying to use Elm, try rebuilding Elm. You can do
|
30
|
+
so with a postinstall hook in your `package.json`:
|
31
|
+
|
32
|
+
```
|
33
|
+
"scripts": {
|
34
|
+
"postinstall": "npm rebuild elm"
|
35
|
+
}
|
36
|
+
```
|
37
|
+
|
38
|
+
|
39
|
+
## webpack or webpack-dev-server not found
|
40
|
+
|
41
|
+
* This could happen if `webpacker:install` step is skipped. Please run `jets webpacker:install` to fix the issue.
|
42
|
+
|
43
|
+
* If you encounter the above error on heroku after upgrading from Rails 4.x to 5.1.x, then the problem might be related to missing `yarn` binstub. Please run following commands to update/add binstubs:
|
44
|
+
|
45
|
+
```bash
|
46
|
+
bundle config --delete bin
|
47
|
+
./bin/rails app:update:bin # or rails app:update:bin
|
48
|
+
```
|
49
|
+
|
50
|
+
|
51
|
+
## Running webpack on Windows
|
52
|
+
|
53
|
+
If you are running webpack on Windows, your command shell may not be able to interpret the preferred interpreter
|
54
|
+
for the scripts generated in `bin/webpack` and `bin/webpack-dev-server`. Instead you'll want to run the scripts
|
55
|
+
manually with Ruby:
|
56
|
+
|
57
|
+
```
|
58
|
+
C:\path>ruby bin\webpack
|
59
|
+
C:\path>ruby bin\webpack-dev-server
|
60
|
+
```
|
61
|
+
|
62
|
+
|
63
|
+
## Invalid configuration object. webpack has been initialised using a configuration object that does not match the API schema.
|
64
|
+
|
65
|
+
If you receive this error when running `$ ./bin/webpack-dev-server` ensure your configuration is correct; most likely the path to your "packs" folder is incorrect if you modified from the original "source_path" defined in `config/webpacker.yml`.
|
66
|
+
|
67
|
+
## Running Elm on Continuous Integration (CI) services such as CircleCI, CodeShip, Travis CI
|
68
|
+
|
69
|
+
If your tests are timing out or erroring on CI it is likely that you are experiencing the slow Elm compilation issue described here: [elm-compiler issue #1473](https://github.com/elm-lang/elm-compiler/issues/1473)
|
70
|
+
|
71
|
+
The issue is related to CPU count exposed by the underlying service. The basic solution involves using [libsysconfcpus](https://github.com/obmarg/libsysconfcpus) to change the reported CPU count.
|
72
|
+
|
73
|
+
Basic fix involves:
|
74
|
+
|
75
|
+
```bash
|
76
|
+
# install sysconfcpus on CI
|
77
|
+
git clone https://github.com/obmarg/libsysconfcpus.git $HOME/dependencies/libsysconfcpus
|
78
|
+
cd libsysconfcpus
|
79
|
+
.configure --prefix=$HOME/dependencies/sysconfcpus
|
80
|
+
make && make install
|
81
|
+
|
82
|
+
# use sysconfcpus with elm-make
|
83
|
+
mv $HOME/your_rails_app/node_modules/.bin/elm-make $HOME/your_rails_app/node_modules/.bin/elm-make-old
|
84
|
+
printf "#\041/bin/bash\n\necho \"Running elm-make with sysconfcpus -n 2\"\n\n$HOME/dependencies/sysconfcpus/bin/sysconfcpus -n 2 $HOME/your_rails_app/node_modules/.bin/elm-make-old \"\$@\"" > $HOME/your_rails_app/node_modules/.bin/elm-make
|
85
|
+
chmod +x $HOME/your_rails_app/node_modules/.bin/elm-make
|
86
|
+
```
|
87
|
+
|
88
|
+
## Rake assets:precompile fails. ExecJS::RuntimeError
|
89
|
+
This error occurs because you are trying to uglify a pack that's already been minified by Webpacker. To avoid this conflict and prevent appearing of ExecJS::RuntimeError error, you will need to disable uglifier from Rails config:
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
// production.rb
|
93
|
+
# From
|
94
|
+
|
95
|
+
Rails.application.config.assets.js_compressor = :uglifier
|
96
|
+
|
97
|
+
# To
|
98
|
+
|
99
|
+
#Rails.application.config.assets.js_compressor = :uglifier
|
100
|
+
|
101
|
+
```
|
102
|
+
|
103
|
+
### Angular: WARNING in ./node_modules/@angular/core/esm5/core.js, Critical dependency: the request of a dependency is an expression
|
104
|
+
|
105
|
+
To silent these warnings, please update `config/webpack/environment.js`
|
106
|
+
|
107
|
+
```js
|
108
|
+
// environment.js
|
109
|
+
const webpack = require('webpack')
|
110
|
+
const { resolve } = require('path')
|
111
|
+
const { environment, config } = require('@rails/webpacker')
|
112
|
+
|
113
|
+
environment.plugins.set('ContextReplacement',
|
114
|
+
new webpack.ContextReplacementPlugin(
|
115
|
+
/angular(\\|\/)core(\\|\/)(@angular|esm5)/,
|
116
|
+
resolve(config.source_path)
|
117
|
+
)
|
118
|
+
)
|
119
|
+
```
|
data/docs/typescript.md
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
# Typescript
|
2
|
+
|
3
|
+
|
4
|
+
## Typescript with React
|
5
|
+
|
6
|
+
1. Setup react using Webpacker [react installer](#react). Then add required depedencies
|
7
|
+
for using typescript with React:
|
8
|
+
|
9
|
+
```bash
|
10
|
+
yarn add ts-loader typescript @types/react @types/react-dom
|
11
|
+
```
|
12
|
+
|
13
|
+
2. Add a `tsconfig.json` to project root:
|
14
|
+
|
15
|
+
``` json
|
16
|
+
{
|
17
|
+
"compilerOptions": {
|
18
|
+
"declaration": false,
|
19
|
+
"emitDecoratorMetadata": true,
|
20
|
+
"experimentalDecorators": true,
|
21
|
+
"lib": ["es6", "dom"],
|
22
|
+
"module": "es6",
|
23
|
+
"moduleResolution": "node",
|
24
|
+
"sourceMap": true,
|
25
|
+
"jsx": "react",
|
26
|
+
"target": "es5"
|
27
|
+
},
|
28
|
+
"exclude": [
|
29
|
+
"**/*.spec.ts",
|
30
|
+
"node_modules",
|
31
|
+
"vendor",
|
32
|
+
"public"
|
33
|
+
],
|
34
|
+
"compileOnSave": false
|
35
|
+
}
|
36
|
+
```
|
37
|
+
|
38
|
+
3. Finally add `.tsx` to the list of extensions in `config/webpacker.yml`
|
39
|
+
and rename your generated `hello_react.js` using react installer
|
40
|
+
to `hello_react.tsx` and make it valid typescript and now you can use
|
41
|
+
typescript, JSX with React.
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
## HTML templates with Typescript and Angular
|
46
|
+
|
47
|
+
After you have installed Angular using `jets webpacker:install:angular`
|
48
|
+
you would need to follow these steps to add HTML templates support:
|
49
|
+
|
50
|
+
1. Use `yarn` to add html-loader
|
51
|
+
|
52
|
+
```bash
|
53
|
+
yarn add html-loader
|
54
|
+
```
|
55
|
+
|
56
|
+
2. Add html-loader to `config/webpack/environment.js`
|
57
|
+
|
58
|
+
```js
|
59
|
+
environment.loaders.set('html', {
|
60
|
+
test: /\.html$/,
|
61
|
+
use: [{
|
62
|
+
loader: 'html-loader',
|
63
|
+
options: {
|
64
|
+
minimize: true,
|
65
|
+
removeAttributeQuotes: false,
|
66
|
+
caseSensitive: true,
|
67
|
+
customAttrSurround: [ [/#/, /(?:)/], [/\*/, /(?:)/], [/\[?\(?/, /(?:)/] ],
|
68
|
+
customAttrAssign: [ /\)?\]?=/ ]
|
69
|
+
}
|
70
|
+
}]
|
71
|
+
})
|
72
|
+
```
|
73
|
+
|
74
|
+
3. Add `.html` to `config/webpacker.yml`
|
75
|
+
|
76
|
+
```yml
|
77
|
+
extensions:
|
78
|
+
- .elm
|
79
|
+
- .coffee
|
80
|
+
- .html
|
81
|
+
```
|
82
|
+
|
83
|
+
4. Setup a custom `d.ts` definition
|
84
|
+
|
85
|
+
```ts
|
86
|
+
// app/javascript/hello_angular/html.d.ts
|
87
|
+
|
88
|
+
declare module "*.html" {
|
89
|
+
const content: string
|
90
|
+
export default content
|
91
|
+
}
|
92
|
+
```
|
93
|
+
|
94
|
+
5. Add a template.html file relative to `app.component.ts`
|
95
|
+
|
96
|
+
```html
|
97
|
+
<h1>Hello {{name}}</h1>
|
98
|
+
```
|
99
|
+
|
100
|
+
6. Import template into `app.component.ts`
|
101
|
+
|
102
|
+
```ts
|
103
|
+
import { Component } from '@angular/core'
|
104
|
+
import templateString from './template.html'
|
105
|
+
|
106
|
+
@Component({
|
107
|
+
selector: 'hello-angular',
|
108
|
+
template: templateString
|
109
|
+
})
|
110
|
+
|
111
|
+
export class AppComponent {
|
112
|
+
name = 'Angular!'
|
113
|
+
}
|
114
|
+
```
|
115
|
+
|
116
|
+
That's all. Voila!
|
@@ -0,0 +1,92 @@
|
|
1
|
+
# webpack-dev-server
|
2
|
+
|
3
|
+
|
4
|
+
## HTTPS
|
5
|
+
|
6
|
+
If you're using the `webpack-dev-server` in development, you can serve your packs over HTTPS
|
7
|
+
by setting the `https` option for `webpack-dev-server` to `true` in `config/webpacker.yml`,
|
8
|
+
then start the dev server as usual with `./bin/webpack-dev-server`.
|
9
|
+
|
10
|
+
Please note that the `webpack-dev-server` will use a self-signed certificate,
|
11
|
+
so your web browser will display a warning/exception upon accessing the page. If you get
|
12
|
+
`https://localhost:3035/sockjs-node/info?t=1503127986584 net::ERR_INSECURE_RESPONSE`
|
13
|
+
in your console, simply open the link in your browser and accept the SSL exception.
|
14
|
+
Now if you refresh your Rails view everything should work as expected.
|
15
|
+
|
16
|
+
|
17
|
+
## HOT module replacement
|
18
|
+
|
19
|
+
Webpacker out-of-the-box supports HMR with `webpack-dev-server` and
|
20
|
+
you can toggle it by setting `dev_server/hmr` option inside `webpacker.yml`.
|
21
|
+
|
22
|
+
Checkout this guide for more information:
|
23
|
+
|
24
|
+
- https://webpack.js.org/configuration/dev-server/#devserver-hot
|
25
|
+
|
26
|
+
To support HMR with React you would need to add `react-hot-loader`. Checkout this guide for
|
27
|
+
more information:
|
28
|
+
|
29
|
+
- https://gaearon.github.io/react-hot-loader/getstarted/
|
30
|
+
|
31
|
+
**Note:** Don't forget to disable `HMR` if you are not running `webpack-dev-server`
|
32
|
+
otherwise you will get not found error for stylesheets.
|
33
|
+
|
34
|
+
|
35
|
+
## Nginx
|
36
|
+
|
37
|
+
If you use Nginx in development to proxy requests to your Rails server from
|
38
|
+
another domain, like `myapp.dev`, the Webpacker middleware will be able to
|
39
|
+
forward requests for "packs" to the webpack dev server.
|
40
|
+
|
41
|
+
If you're using `inline` mode behing Nginx, you may also need to provide the
|
42
|
+
hostname to webpack dev server so it can initiate the websocket connection for
|
43
|
+
live reloading ([Webpack
|
44
|
+
docs](https://webpack.js.org/configuration/dev-server/#devserver-public)).
|
45
|
+
|
46
|
+
To do so, set the `public` option in `config/webpacker.yml`:
|
47
|
+
|
48
|
+
```yaml
|
49
|
+
development:
|
50
|
+
# ...
|
51
|
+
dev_server:
|
52
|
+
# ...
|
53
|
+
public: myapp.dev
|
54
|
+
```
|
55
|
+
|
56
|
+
You may also need to add the following location block to your local Nginx server
|
57
|
+
configuration for your Rails app.
|
58
|
+
|
59
|
+
```
|
60
|
+
server {
|
61
|
+
listen 80;
|
62
|
+
server_name myapp.dev
|
63
|
+
|
64
|
+
# Proxy webpack dev server websocket requests
|
65
|
+
location /sockjs-node {
|
66
|
+
proxy_redirect off;
|
67
|
+
proxy_http_version 1.1;
|
68
|
+
proxy_set_header Upgrade $http_upgrade;
|
69
|
+
proxy_set_header Connection "upgrade";
|
70
|
+
proxy_pass http://127.0.0.1:3035; # change to match your webpack-dev-server host
|
71
|
+
}
|
72
|
+
|
73
|
+
# ...
|
74
|
+
}
|
75
|
+
```
|
76
|
+
|
77
|
+
## Customizing Logging
|
78
|
+
|
79
|
+
By default, the dev server will display a colored progress notification while
|
80
|
+
your code is being compiled. (Under the hood, we are using `webpack-dev-server
|
81
|
+
--progress --color`). However, this might cause issues if you don't use
|
82
|
+
`foreman` and/or try to log webpack-dev-server's output to a file. You can
|
83
|
+
disable this stylized output by adding `pretty: false` to your `dev_server`
|
84
|
+
config:
|
85
|
+
|
86
|
+
```yaml
|
87
|
+
development:
|
88
|
+
# ...
|
89
|
+
dev_server:
|
90
|
+
# ...
|
91
|
+
pretty: false
|
92
|
+
```
|