webpacker 6.0.0.beta.2 → 6.0.0.pre.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -18
- data/Gemfile.lock +1 -1
- data/README.md +96 -219
- data/docs/assets.md +135 -0
- data/docs/cloud9.md +310 -0
- data/docs/css.md +303 -0
- data/docs/deployment.md +148 -0
- data/docs/docker.md +68 -0
- data/docs/engines.md +213 -0
- data/docs/env.md +68 -0
- data/docs/es6.md +72 -0
- data/docs/folder-structure.md +66 -0
- data/docs/integrations.md +220 -0
- data/docs/misc.md +23 -0
- data/docs/props.md +187 -0
- data/docs/react.md +183 -0
- data/docs/target.md +22 -0
- data/docs/testing.md +147 -0
- data/docs/troubleshooting.md +158 -0
- data/docs/typescript.md +190 -0
- data/docs/v4-upgrade.md +142 -0
- data/docs/webpack-dev-server.md +94 -0
- data/docs/webpack.md +315 -0
- data/docs/yarn.md +23 -0
- data/lib/install/examples/vue3/app.vue +27 -0
- data/lib/install/examples/vue3/hello_vue.js +15 -0
- data/lib/install/javascript/packs/application.js +1 -3
- data/lib/webpacker/compiler.rb +2 -8
- data/lib/webpacker/version.rb +1 -1
- data/package.json +1 -1
- data/package/babel/preset-react.js +62 -0
- data/package/babel/preset.js +13 -24
- data/package/environments/__tests__/base.js +1 -1
- data/package/environments/base.js +19 -19
- data/package/environments/production.js +30 -28
- data/package/index.js +2 -7
- data/package/rules/coffee.js +5 -5
- data/package/rules/erb.js +3 -5
- data/package/rules/file.js +3 -5
- data/package/rules/index.js +17 -9
- data/package/rules/less.js +10 -14
- data/package/rules/sass.js +9 -13
- data/package/rules/svg.js +23 -0
- data/package/utils/get_style_rule.js +31 -27
- data/package/utils/helpers.js +0 -23
- metadata +29 -7
- data/6_0_upgrade.md +0 -43
- data/package/rules/raw.js +0 -5
- data/package/rules/stylus.js +0 -26
data/docs/react.md
ADDED
@@ -0,0 +1,183 @@
|
|
1
|
+
# React
|
2
|
+
|
3
|
+
## Props Hydration and Server-Side Rendering (SSR)
|
4
|
+
You only _need_ props hydration if you need SSR. However, there's no good reason to
|
5
|
+
have your app make a second round trip to the Rails server to get initialization props.
|
6
|
+
|
7
|
+
Server-Side Rendering (SSR) results in Rails rendering HTML for your React components.
|
8
|
+
The main reasons to use SSR are better SEO and pages display more quickly.
|
9
|
+
|
10
|
+
### Rails and React Integration Gems
|
11
|
+
If you desire more advanced React-integration, like server-side rendering, SSR with react-router, SSR with code splitting, then you should consider these gems:
|
12
|
+
|
13
|
+
| Gem | Props Hydration | Server-Side-Rendering (SSR) | SSR with HMR | SSR with React-Router | SSR with Code Splitting | Node SSR |
|
14
|
+
| --- | --------------- | --- | --------------------- | ----------------------| ------------------------|----|
|
15
|
+
| [shakacode/react_on_rails](https://github.com/shakacode/react_on_rails) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
|
16
|
+
| [react-rails](https://github.com/reactjs/react-rails) | ✅ | ✅ | | | | | |
|
17
|
+
| [webpacker-react](https://github.com/renchap/webpacker-react) | ✅ | | | | | | |
|
18
|
+
|
19
|
+
Note, Node SSR for React on Rails requires [React on Rails Pro](https://www.shakacode.com/react-on-rails-pro).
|
20
|
+
|
21
|
+
### Hydration of Props the Manual Way
|
22
|
+
|
23
|
+
If you're not concerned with view helpers to pass props or server-side rendering, you can do it like this:
|
24
|
+
|
25
|
+
```erb
|
26
|
+
<%# views/layouts/application.html.erb %>
|
27
|
+
|
28
|
+
<%= content_tag :div,
|
29
|
+
id: "hello-react",
|
30
|
+
data: {
|
31
|
+
message: 'Hello!',
|
32
|
+
name: 'David'
|
33
|
+
}.to_json do %>
|
34
|
+
<% end %>
|
35
|
+
```
|
36
|
+
|
37
|
+
```js
|
38
|
+
// app/javascript/packs/hello_react.js
|
39
|
+
|
40
|
+
const Hello = props => (
|
41
|
+
<div className='react-app-wrapper'>
|
42
|
+
<img src={clockIcon} alt="clock" />
|
43
|
+
<h5 className='hello-react'>
|
44
|
+
{props.message} {props.name}!
|
45
|
+
</h5>
|
46
|
+
</div>
|
47
|
+
)
|
48
|
+
|
49
|
+
// Render component with data
|
50
|
+
document.addEventListener('DOMContentLoaded', () => {
|
51
|
+
const node = document.getElementById('hello-react')
|
52
|
+
const data = JSON.parse(node.getAttribute('data'))
|
53
|
+
|
54
|
+
ReactDOM.render(<Hello {...data} />, node)
|
55
|
+
})
|
56
|
+
```
|
57
|
+
|
58
|
+
----
|
59
|
+
|
60
|
+
## HMR and React Hot Reloading
|
61
|
+
|
62
|
+
Before turning HMR on, consider upgrading to the latest stable gems and packages:
|
63
|
+
https://github.com/rails/webpacker#upgrading
|
64
|
+
|
65
|
+
Configure `config/webpacker.yml` file:
|
66
|
+
|
67
|
+
```yaml
|
68
|
+
development:
|
69
|
+
extract_css: false
|
70
|
+
dev_server:
|
71
|
+
hmr: true
|
72
|
+
inline: true
|
73
|
+
```
|
74
|
+
|
75
|
+
This basic configuration alone will have HMR working with the default webpacker setup. However, an code saves will trigger a full page refresh each time you save a file.
|
76
|
+
|
77
|
+
Webpack's HMR allows the replacement of modules for React in-place without reloading the browser. To do this, you have two options:
|
78
|
+
|
79
|
+
1. Steps below for the [github.com/pmmmwh/react-refresh-webpack-plugin](https://github.com/pmmmwh/react-refresh-webpack-plugin).
|
80
|
+
1. Deprecated steps below for using the [github.com/gaearon/react-hot-loader](https://github.com/gaearon/react-hot-loader).
|
81
|
+
|
82
|
+
### React Refresh Webpack Plugin
|
83
|
+
[github.com/pmmmwh/react-refresh-webpack-plugin](https://github.com/pmmmwh/react-refresh-webpack-plugin)
|
84
|
+
|
85
|
+
You can see an example commit of adding this [here](https://github.com/shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh/commit/7e53803fce7034f5ecff335db1f400a5743a87e7).
|
86
|
+
|
87
|
+
1. Add react refresh packages:
|
88
|
+
`yarn add @pmmmwh/react-refresh-webpack-plugin react-refresh -D`
|
89
|
+
2. Update `babel.config.js` adding
|
90
|
+
```js
|
91
|
+
plugins: [
|
92
|
+
process.env.WEBPACK_DEV_SERVER && 'react-refresh/babel',
|
93
|
+
// other plugins
|
94
|
+
```
|
95
|
+
3. Update `config/webpack/development.js`, only including the plugin if running the WEBPACK_DEV_SERVER
|
96
|
+
```js
|
97
|
+
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
|
98
|
+
const environment = require('./environment')
|
99
|
+
|
100
|
+
const isWebpackDevServer = process.env.WEBPACK_DEV_SERVER;
|
101
|
+
|
102
|
+
//plugins
|
103
|
+
if (isWebpackDevServer) {
|
104
|
+
environment.plugins.append(
|
105
|
+
'ReactRefreshWebpackPlugin',
|
106
|
+
new ReactRefreshWebpackPlugin({
|
107
|
+
overlay: {
|
108
|
+
sockPort: 3035
|
109
|
+
}
|
110
|
+
})
|
111
|
+
);
|
112
|
+
}
|
113
|
+
```
|
114
|
+
|
115
|
+
### React Hot Loader (Deprecated)
|
116
|
+
|
117
|
+
1. Add the `react-hot-loader` and ` @hot-loader/react-dom` npm packages.
|
118
|
+
```sh
|
119
|
+
yarn add --dev react-hot-loader @hot-loader/react-dom
|
120
|
+
```
|
121
|
+
|
122
|
+
2. Update your babel config, `babel.config.js`. Add the plugin `react-hot-loader/babel`
|
123
|
+
with option `"safetyNet": false`:
|
124
|
+
|
125
|
+
```
|
126
|
+
{
|
127
|
+
"plugins": [
|
128
|
+
[
|
129
|
+
"react-hot-loader/babel",
|
130
|
+
{
|
131
|
+
"safetyNet": false
|
132
|
+
}
|
133
|
+
]
|
134
|
+
]
|
135
|
+
}
|
136
|
+
```
|
137
|
+
|
138
|
+
3. Add changes like this to your entry points:
|
139
|
+
|
140
|
+
```diff
|
141
|
+
// app/javascript/app.jsx
|
142
|
+
|
143
|
+
import React from 'react';
|
144
|
+
+ import { hot } from 'react-hot-loader/root';
|
145
|
+
|
146
|
+
const App = () => <SomeComponent(s) />
|
147
|
+
|
148
|
+
- export default App;
|
149
|
+
+ export default hot(App);
|
150
|
+
```
|
151
|
+
|
152
|
+
4. Adjust your webpack configuration for development so that `sourceMapContents` option for the sass
|
153
|
+
loader is `false`:
|
154
|
+
|
155
|
+
```diff
|
156
|
+
// config/webpack/development.js
|
157
|
+
|
158
|
+
process.env.NODE_ENV = process.env.NODE_ENV || 'development'
|
159
|
+
|
160
|
+
const environment = require('./environment')
|
161
|
+
|
162
|
+
// allows for editing sass/scss files directly in browser
|
163
|
+
+ if (!module.hot) {
|
164
|
+
+ environment.loaders.get('sass').use.find(item => item.loader === 'sass-loader').options.sourceMapContents = false
|
165
|
+
+ }
|
166
|
+
+
|
167
|
+
module.exports = environment.toWebpackConfig()
|
168
|
+
```
|
169
|
+
|
170
|
+
5. Adjust your `config/webpack/environment.js` for a
|
171
|
+
|
172
|
+
```diff
|
173
|
+
// config/webpack/environment.js
|
174
|
+
|
175
|
+
// ...
|
176
|
+
|
177
|
+
// Fixes: React-Hot-Loader: react-🔥-dom patch is not detected. React 16.6+ features may not work.
|
178
|
+
// https://github.com/gaearon/react-hot-loader/issues/1227#issuecomment-482139583
|
179
|
+
+ environment.config.merge({ resolve: { alias: { 'react-dom': '@hot-loader/react-dom' } } });
|
180
|
+
|
181
|
+
module.exports = environment;
|
182
|
+
```
|
183
|
+
|
data/docs/target.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# Target browsers
|
2
|
+
|
3
|
+
By default webpacker provides these front-end tools:
|
4
|
+
- [@babel/preset-env](https://github.com/babel/babel/tree/master/packages/babel-preset-env)
|
5
|
+
- [Autoprefixer](https://github.com/postcss/autoprefixer)
|
6
|
+
- [postcss-preset-env](https://github.com/csstools/postcss-preset-env)
|
7
|
+
|
8
|
+
All these tools use [Browserslist](https://github.com/browserslist/browserslist) to detect which environment your users have
|
9
|
+
|
10
|
+
Webpacker browserslist default target:
|
11
|
+
```
|
12
|
+
defaults
|
13
|
+
```
|
14
|
+
|
15
|
+
`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.
|
16
|
+
|
17
|
+
To keep browsers data up to date, you need to run:
|
18
|
+
```bash
|
19
|
+
yarn upgrade caniuse-lite
|
20
|
+
```
|
21
|
+
|
22
|
+
at least once every few months, to prevent such [problems](https://github.com/browserslist/browserslist/issues/492)
|
data/docs/testing.md
ADDED
@@ -0,0 +1,147 @@
|
|
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
|
+
},
|
15
|
+
"devDependencies": {
|
16
|
+
"karma": "^1.7.1",
|
17
|
+
"karma-webpack": "^2.0.4",
|
18
|
+
"karma-chrome-launcher": "^2.2.0",
|
19
|
+
"karma-jquery": "^0.2.2",
|
20
|
+
"karma-jasmine": "^1.1.0",
|
21
|
+
"karma-jasmine-jquery": "^0.1.1",
|
22
|
+
"jasmine-core": "^2.8.0",
|
23
|
+
[optional] "karma-coverage": "^1.1.1",
|
24
|
+
[optional] "karma-coverage-istanbul-reporter": "^1.3.0",
|
25
|
+
[optional] "karma-spec-reporter": "0.0.31",
|
26
|
+
[optional] "istanbul-instrumenter-loader": "^3.0.0",
|
27
|
+
}
|
28
|
+
```
|
29
|
+
|
30
|
+
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.
|
31
|
+
|
32
|
+
```js
|
33
|
+
// config/webpack/test.js
|
34
|
+
const environment = require('./environment')
|
35
|
+
environment.plugins.get('Manifest').options.writeToFileEmit = process.env.NODE_ENV !== 'test'
|
36
|
+
environment.loaders.append('istanbul-instrumenter', {
|
37
|
+
test: /\.ts$/,
|
38
|
+
enforce: "post",
|
39
|
+
loader: "istanbul-instrumenter-loader",
|
40
|
+
query: {
|
41
|
+
esModules: true
|
42
|
+
},
|
43
|
+
exclude: ["node_modules", /\.test\.ts$/]
|
44
|
+
}) /* optional */
|
45
|
+
module.exports = environment.toWebpackConfig()
|
46
|
+
```
|
47
|
+
|
48
|
+
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).
|
49
|
+
|
50
|
+
```js
|
51
|
+
// karma.conf.js
|
52
|
+
const webpackConfig = require('./config/webpack/test.js')
|
53
|
+
module.exports = function(config) {
|
54
|
+
config.set({
|
55
|
+
basePath: "",
|
56
|
+
frameworks: ["jquery-3.2.1", "jasmine-jquery", "jasmine"],
|
57
|
+
plugins: [
|
58
|
+
"karma-jquery",
|
59
|
+
"karma-jasmine-jquery",
|
60
|
+
"karma-jasmine",
|
61
|
+
"karma-webpack",
|
62
|
+
"karma-chrome-launcher",
|
63
|
+
"karma-coverage-istanbul-reporter" /* optional */,
|
64
|
+
"karma-spec-reporter" /* optional */
|
65
|
+
],
|
66
|
+
files: [ "/* add spec files */" ],
|
67
|
+
exclude: [],
|
68
|
+
webpack: webpackConfig,
|
69
|
+
preprocessors: {"/* add spec files */" : ["webpack"]},
|
70
|
+
mime: { "text/x-typescript": ["ts"] },
|
71
|
+
reporters: ["progress", "coverage-istanbul" /* optional */],
|
72
|
+
coverageIstanbulReporter: {
|
73
|
+
reports: [ 'html', 'lcovonly', 'text-summary' ],
|
74
|
+
fixWebpackSourcePaths: true
|
75
|
+
} /* optional */,
|
76
|
+
port: 9876,
|
77
|
+
colors: true,
|
78
|
+
logLevel: config.LOG_INFO,
|
79
|
+
autoWatch: true,
|
80
|
+
browsers: ["Chrome"],
|
81
|
+
singleRun: true
|
82
|
+
});
|
83
|
+
};
|
84
|
+
```
|
85
|
+
|
86
|
+
## Lazy compilation
|
87
|
+
|
88
|
+
Webpacker lazily compiles assets in test env so you can write your tests without any extra
|
89
|
+
setup and everything will just work out of the box.
|
90
|
+
|
91
|
+
Here is a sample system test case with hello_react example component:
|
92
|
+
|
93
|
+
```js
|
94
|
+
// Example React component
|
95
|
+
|
96
|
+
import React from 'react'
|
97
|
+
import ReactDOM from 'react-dom'
|
98
|
+
import PropTypes from 'prop-types'
|
99
|
+
|
100
|
+
const Hello = props => (
|
101
|
+
<div>Hello David</div>
|
102
|
+
)
|
103
|
+
|
104
|
+
document.addEventListener('DOMContentLoaded', () => {
|
105
|
+
ReactDOM.render(
|
106
|
+
<Hello />,
|
107
|
+
document.body.appendChild(document.createElement('div')),
|
108
|
+
)
|
109
|
+
})
|
110
|
+
```
|
111
|
+
|
112
|
+
```erb
|
113
|
+
<%# views/pages/home.html.erb %>
|
114
|
+
|
115
|
+
<%= javascript_pack_tag "hello_react" %>
|
116
|
+
```
|
117
|
+
|
118
|
+
```rb
|
119
|
+
# Tests example React component
|
120
|
+
require "application_system_test_case"
|
121
|
+
class HomesTest < ApplicationSystemTestCase
|
122
|
+
test "can see the hello message" do
|
123
|
+
visit root_url
|
124
|
+
assert_selector "h5", text: "Hello! David"
|
125
|
+
end
|
126
|
+
end
|
127
|
+
```
|
128
|
+
|
129
|
+
## Capybara setup for Rails
|
130
|
+
Make sure you configure Rails to serve static files from the public directory in the test environment.
|
131
|
+
|
132
|
+
```rb
|
133
|
+
# config/environments/test.rb
|
134
|
+
# Configure public file server for tests with Cache-Control for performance.
|
135
|
+
config.public_file_server.enabled = true
|
136
|
+
```
|
137
|
+
|
138
|
+
## Webpacker Configuration and Rails Tests
|
139
|
+
|
140
|
+
Webpacker ships with three javascript configuration files: `test.js`,
|
141
|
+
`development.js`, and `production.js`. The `NODE_ENV` environment
|
142
|
+
variable determines which config will be used. `NODE_ENV` is
|
143
|
+
independent of `RAILS_ENV` and is set to `development` by [default](/lib/install/bin/webpack#L4).
|
144
|
+
This means that `rails test` or `rspec` will use `development.js`
|
145
|
+
by default, _not_ `test.js`.
|
146
|
+
|
147
|
+
For more information see [Why doesn't Webpacker use my test config when I run Rails tests?](https://rossta.net/blog/why-doesnt-webpacker-use-my-test-config-when-i-run-rails-tests.html)
|
@@ -0,0 +1,158 @@
|
|
1
|
+
# Troubleshooting
|
2
|
+
|
3
|
+
## Debugging your webpack config
|
4
|
+
|
5
|
+
1. Read the error message carefully. The error message will tell you the precise key value
|
6
|
+
that is not matching what Webpack expects.
|
7
|
+
2. Put a `debugger` statement in your Webpack configuration and run `bin/webpack --debug-webpacker`.
|
8
|
+
If you have a node debugger installed, you'll see the Chrome debugger for your webpack
|
9
|
+
config. For example, install the Chrome extension [NiM](https://chrome.google.com/webstore/detail/nodejs-v8-inspector-manag/gnhhdgbaldcilmgcpfddgdbkhjohddkj) and
|
10
|
+
set the option for the dev tools to open automatically. For more details on debugging,
|
11
|
+
see the official [Webpack docs on debugging](https://webpack.js.org/contribute/debugging/#devtools)
|
12
|
+
3. Any arguments that you add to bin/webpack get sent to webpack. For example, you can pass `--debug` to switch loaders to debug mode. See [webpack CLI debug options](https://webpack.js.org/api/cli/#debug-options) for more information on the available options.
|
13
|
+
4. You can also pass additional options to the command to run the webpack-dev-server and start the webpack-dev-server with the option `--debug-webpacker`
|
14
|
+
|
15
|
+
## ENOENT: no such file or directory - node-sass
|
16
|
+
|
17
|
+
If you get the error `ENOENT: no such file or directory - node-sass` on deploy with
|
18
|
+
`assets:precompile` or `bundle exec rails webpacker:compile` you may need to
|
19
|
+
move Sass to production `dependencies`.
|
20
|
+
|
21
|
+
Move any packages that related to Sass (e.g. `node-sass` or `sass-loader`) from
|
22
|
+
`devDependencies` to `dependencies` in `package.json`. This is because
|
23
|
+
webpacker is running on a production system with the Rails workflow to build
|
24
|
+
the assets. Particularly on hosting providers that try to detect and do the right
|
25
|
+
thing, like Heroku.
|
26
|
+
|
27
|
+
However, if you get this on local development, or not during a deploy then you
|
28
|
+
may need to rebuild `node-sass`. It's a bit of a weird error; basically, it
|
29
|
+
can't find the `node-sass` binary. An easy solution is to create a postinstall
|
30
|
+
hook to ensure `node-sass` is rebuilt whenever new modules are installed.
|
31
|
+
|
32
|
+
In `package.json`:
|
33
|
+
|
34
|
+
```json
|
35
|
+
"scripts": {
|
36
|
+
"postinstall": "npm rebuild node-sass"
|
37
|
+
}
|
38
|
+
```
|
39
|
+
|
40
|
+
## Can't find hello_react.js in manifest.json
|
41
|
+
|
42
|
+
* If you get this error `Can't find hello_react.js in manifest.json`
|
43
|
+
when loading a view in the browser it's because webpack is still compiling packs.
|
44
|
+
Webpacker uses a `manifest.json` file to keep track of packs in all environments,
|
45
|
+
however since this file is generated after packs are compiled by webpack. So,
|
46
|
+
if you load a view in browser whilst webpack is compiling you will get this error.
|
47
|
+
Therefore, make sure webpack
|
48
|
+
(i.e `./bin/webpack-dev-server`) is running and has
|
49
|
+
completed the compilation successfully before loading a view.
|
50
|
+
|
51
|
+
|
52
|
+
## throw er; // Unhandled 'error' event
|
53
|
+
|
54
|
+
* If you get this error while trying to use Elm, try rebuilding Elm. You can do
|
55
|
+
so with a postinstall hook in your `package.json`:
|
56
|
+
|
57
|
+
```
|
58
|
+
"scripts": {
|
59
|
+
"postinstall": "npm rebuild elm"
|
60
|
+
}
|
61
|
+
```
|
62
|
+
|
63
|
+
|
64
|
+
## webpack or webpack-dev-server not found
|
65
|
+
|
66
|
+
* This could happen if `webpacker:install` step is skipped. Please run `bundle exec rails webpacker:install` to fix the issue.
|
67
|
+
|
68
|
+
* 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:
|
69
|
+
|
70
|
+
```bash
|
71
|
+
bundle config --delete bin
|
72
|
+
./bin/rails app:update:bin # or rails app:update:bin
|
73
|
+
```
|
74
|
+
|
75
|
+
|
76
|
+
## Running webpack on Windows
|
77
|
+
|
78
|
+
If you are running webpack on Windows, your command shell may not be able to interpret the preferred interpreter
|
79
|
+
for the scripts generated in `bin/webpack` and `bin/webpack-dev-server`. Instead you'll want to run the scripts
|
80
|
+
manually with Ruby:
|
81
|
+
|
82
|
+
```
|
83
|
+
C:\path>ruby bin\webpack
|
84
|
+
C:\path>ruby bin\webpack-dev-server
|
85
|
+
```
|
86
|
+
|
87
|
+
|
88
|
+
## Invalid configuration object. webpack has been initialised using a configuration object that does not match the API schema.
|
89
|
+
|
90
|
+
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`.
|
91
|
+
|
92
|
+
## Running Elm on Continuous Integration (CI) services such as CircleCI, CodeShip, Travis CI
|
93
|
+
|
94
|
+
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)
|
95
|
+
|
96
|
+
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.
|
97
|
+
|
98
|
+
Basic fix involves:
|
99
|
+
|
100
|
+
```bash
|
101
|
+
# install sysconfcpus on CI
|
102
|
+
git clone https://github.com/obmarg/libsysconfcpus.git $HOME/dependencies/libsysconfcpus
|
103
|
+
cd libsysconfcpus
|
104
|
+
.configure --prefix=$HOME/dependencies/sysconfcpus
|
105
|
+
make && make install
|
106
|
+
|
107
|
+
# use sysconfcpus with elm-make
|
108
|
+
mv $HOME/your_rails_app/node_modules/.bin/elm-make $HOME/your_rails_app/node_modules/.bin/elm-make-old
|
109
|
+
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
|
110
|
+
chmod +x $HOME/your_rails_app/node_modules/.bin/elm-make
|
111
|
+
```
|
112
|
+
|
113
|
+
## Rake assets:precompile fails. ExecJS::RuntimeError
|
114
|
+
This error occurs because you are trying to minify by terser 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:
|
115
|
+
|
116
|
+
```ruby
|
117
|
+
// production.rb
|
118
|
+
# From
|
119
|
+
|
120
|
+
Rails.application.config.assets.js_compressor = :uglifier
|
121
|
+
|
122
|
+
# To
|
123
|
+
|
124
|
+
Rails.application.config.assets.js_compressor = Uglifier.new(harmony: true)
|
125
|
+
|
126
|
+
```
|
127
|
+
|
128
|
+
### Angular: WARNING in ./node_modules/@angular/core/esm5/core.js, Critical dependency: the request of a dependency is an expression
|
129
|
+
|
130
|
+
To silent these warnings, please update `config/webpack/environment.js`
|
131
|
+
|
132
|
+
```js
|
133
|
+
// environment.js
|
134
|
+
const webpack = require('webpack')
|
135
|
+
const { resolve } = require('path')
|
136
|
+
const { environment, config } = require('@rails/webpacker')
|
137
|
+
|
138
|
+
environment.plugins.append('ContextReplacement',
|
139
|
+
new webpack.ContextReplacementPlugin(
|
140
|
+
/angular(\\|\/)core(\\|\/)(@angular|esm5)/,
|
141
|
+
resolve(config.source_path)
|
142
|
+
)
|
143
|
+
)
|
144
|
+
```
|
145
|
+
|
146
|
+
### Compilation Fails Silently
|
147
|
+
|
148
|
+
If compiling is not producing output files and there are no error messages to help troubleshoot. Setting the webpack_compile_output configuration variable to 'true' in webpacker.yml may add some helpful error information to your log file (Rails log/development.log or log/production.log)
|
149
|
+
|
150
|
+
```yml
|
151
|
+
# webpacker.yml
|
152
|
+
default: &default
|
153
|
+
source_path: app/javascript
|
154
|
+
source_entry_path: packs
|
155
|
+
public_root_path: public
|
156
|
+
public_output_path: complaints_packs
|
157
|
+
webpack_compile_output: true
|
158
|
+
```
|