jetpacker 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.eslintignore +4 -0
- data/.eslintrc.js +14 -0
- data/.gitignore +11 -11
- data/.node-version +1 -0
- data/.rubocop.yml +125 -0
- data/.travis.yml +54 -5
- data/CHANGELOG.jetpacker.md +7 -0
- data/CHANGELOG.md +1000 -0
- data/CONTRIBUTING.md +33 -0
- data/Gemfile +9 -3
- data/Gemfile.lock +157 -21
- data/MIT-LICENSE +20 -0
- data/README.md +671 -16
- data/Rakefile +8 -3
- data/docs/assets.md +119 -0
- data/docs/cloud9.md +310 -0
- data/docs/css.md +253 -0
- data/docs/deployment.md +130 -0
- data/docs/docker.md +68 -0
- data/docs/engines.md +200 -0
- data/docs/env.md +65 -0
- data/docs/es6.md +72 -0
- data/docs/folder-structure.md +66 -0
- data/docs/misc.md +23 -0
- data/docs/props.md +223 -0
- data/docs/testing.md +137 -0
- data/docs/troubleshooting.md +156 -0
- data/docs/typescript.md +126 -0
- data/docs/v4-upgrade.md +142 -0
- data/docs/webpack-dev-server.md +92 -0
- data/docs/webpack.md +364 -0
- data/docs/yarn.md +23 -0
- data/gemfiles/Gemfile-rails-edge +12 -0
- data/gemfiles/Gemfile-rails.4.2.x +9 -0
- data/gemfiles/Gemfile-rails.5.0.x +9 -0
- data/gemfiles/Gemfile-rails.5.1.x +9 -0
- data/gemfiles/Gemfile-rails.5.2.x +9 -0
- data/gemfiles/Gemfile-rails.6.0.x +9 -0
- data/jetpacker.gemspec +28 -22
- data/lib/install/angular.rb +23 -0
- data/lib/install/bin/webpack +18 -0
- data/lib/install/bin/webpack-dev-server +18 -0
- data/lib/install/binstubs.rb +4 -0
- data/lib/install/coffee.rb +25 -0
- data/lib/install/config/.browserslistrc +1 -0
- data/lib/install/config/babel.config.js +72 -0
- data/lib/install/config/postcss.config.js +12 -0
- data/lib/install/config/webpack/development.js +5 -0
- data/lib/install/config/webpack/environment.js +3 -0
- data/lib/install/config/webpack/production.js +5 -0
- data/lib/install/config/webpack/test.js +5 -0
- data/lib/install/config/webpacker.yml +96 -0
- data/lib/install/elm.rb +39 -0
- data/lib/install/erb.rb +25 -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/coffee/hello_coffee.coffee +4 -0
- data/lib/install/examples/elm/Main.elm +55 -0
- data/lib/install/examples/elm/hello_elm.js +16 -0
- data/lib/install/examples/erb/hello_erb.js.erb +6 -0
- data/lib/install/examples/react/babel.config.js +87 -0
- data/lib/install/examples/react/hello_react.jsx +26 -0
- data/lib/install/examples/react/tsconfig.json +20 -0
- data/lib/install/examples/stimulus/application.js +1 -0
- data/lib/install/examples/stimulus/controllers/hello_controller.js +18 -0
- data/lib/install/examples/stimulus/controllers/index.js +9 -0
- data/lib/install/examples/svelte/app.svelte +11 -0
- data/lib/install/examples/svelte/hello_svelte.js +20 -0
- data/lib/install/examples/typescript/hello_typescript.ts +4 -0
- data/lib/install/examples/typescript/tsconfig.json +23 -0
- data/lib/install/examples/vue/app.vue +22 -0
- data/lib/install/examples/vue/hello_vue.js +72 -0
- data/lib/install/javascript/packs/application.js +18 -0
- data/lib/install/loaders/coffee.js +6 -0
- data/lib/install/loaders/elm.js +25 -0
- data/lib/install/loaders/erb.js +11 -0
- data/lib/install/loaders/svelte.js +9 -0
- data/lib/install/loaders/typescript.js +11 -0
- data/lib/install/loaders/vue.js +6 -0
- data/lib/install/react.rb +18 -0
- data/lib/install/stimulus.rb +12 -0
- data/lib/install/svelte.rb +29 -0
- data/lib/install/template.rb +55 -0
- data/lib/install/typescript.rb +46 -0
- data/lib/install/vue.rb +49 -0
- data/lib/jetpacker/version.rb +2 -1
- data/lib/tasks/installers.rake +37 -0
- data/lib/tasks/webpacker.rake +28 -0
- data/lib/tasks/webpacker/binstubs.rake +11 -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/clean.rake +21 -0
- data/lib/tasks/webpacker/clobber.rake +16 -0
- data/lib/tasks/webpacker/compile.rake +43 -0
- data/lib/tasks/webpacker/info.rake +20 -0
- data/lib/tasks/webpacker/install.rake +13 -0
- data/lib/tasks/webpacker/verify_install.rake +13 -0
- data/lib/tasks/webpacker/yarn_install.rake +21 -0
- data/lib/webpacker.rb +46 -0
- data/lib/webpacker/commands.rb +50 -0
- data/lib/webpacker/compiler.rb +107 -0
- data/lib/webpacker/configuration.rb +113 -0
- data/lib/webpacker/dev_server.rb +66 -0
- data/lib/webpacker/dev_server_proxy.rb +31 -0
- data/lib/webpacker/dev_server_runner.rb +72 -0
- data/lib/webpacker/env.rb +39 -0
- data/lib/webpacker/helper.rb +176 -0
- data/lib/webpacker/instance.rb +37 -0
- data/lib/webpacker/manifest.rb +118 -0
- data/lib/webpacker/railtie.rb +98 -0
- data/lib/webpacker/rake_tasks.rb +6 -0
- data/lib/webpacker/runner.rb +22 -0
- data/lib/webpacker/version.rb +4 -0
- data/lib/webpacker/webpack_runner.rb +32 -0
- data/package.json +82 -0
- data/package/__tests__/config.js +55 -0
- data/package/__tests__/dev_server.js +43 -0
- data/package/__tests__/development.js +30 -0
- data/package/__tests__/env.js +46 -0
- data/package/__tests__/production.js +29 -0
- data/package/__tests__/staging.js +29 -0
- data/package/__tests__/test.js +26 -0
- data/package/config.js +37 -0
- data/package/config_types/__tests__/config_list.js +118 -0
- data/package/config_types/__tests__/config_object.js +43 -0
- data/package/config_types/config_list.js +75 -0
- data/package/config_types/config_object.js +55 -0
- data/package/config_types/index.js +7 -0
- data/package/dev_server.js +20 -0
- data/package/env.js +19 -0
- data/package/environments/__tests__/base.js +74 -0
- data/package/environments/base.js +166 -0
- data/package/environments/development.js +51 -0
- data/package/environments/production.js +79 -0
- data/package/environments/test.js +3 -0
- data/package/index.js +24 -0
- data/package/rules/babel.js +21 -0
- data/package/rules/css.js +3 -0
- data/package/rules/file.js +20 -0
- data/package/rules/index.js +20 -0
- data/package/rules/module.css.js +3 -0
- data/package/rules/module.sass.js +8 -0
- data/package/rules/node_modules.js +24 -0
- data/package/rules/sass.js +8 -0
- data/package/utils/__tests__/deep_assign.js +32 -0
- data/package/utils/__tests__/deep_merge.js +10 -0
- data/package/utils/__tests__/get_style_rule.js +65 -0
- data/package/utils/__tests__/objectify.js +9 -0
- data/package/utils/deep_assign.js +22 -0
- data/package/utils/deep_merge.js +22 -0
- data/package/utils/get_style_rule.js +45 -0
- data/package/utils/helpers.js +58 -0
- data/package/utils/objectify.js +3 -0
- data/test/command_test.rb +33 -0
- data/test/compiler_test.rb +75 -0
- data/test/configuration_test.rb +108 -0
- data/test/dev_server_runner_test.rb +51 -0
- data/test/dev_server_test.rb +47 -0
- data/test/env_test.rb +23 -0
- data/test/helper_test.rb +142 -0
- data/test/manifest_test.rb +42 -0
- data/test/rake_tasks_test.rb +69 -0
- data/test/test_app/Rakefile +3 -0
- data/test/test_app/app/javascript/packs/application.js +10 -0
- data/test/test_app/bin/webpack +14 -0
- data/test/test_app/bin/webpack-dev-server +14 -0
- data/test/test_app/config.ru +5 -0
- data/test/test_app/config/application.rb +12 -0
- data/test/test_app/config/environment.rb +4 -0
- data/test/test_app/config/webpack/development.js +0 -0
- data/test/test_app/config/webpacker.yml +97 -0
- data/test/test_app/config/webpacker_public_root.yml +19 -0
- data/test/test_app/package.json +13 -0
- data/test/test_app/public/packs/manifest.json +31 -0
- data/test/test_app/yarn.lock +11 -0
- data/test/test_helper.rb +33 -0
- data/test/webpack_runner_test.rb +51 -0
- data/test/webpacker_test.rb +13 -0
- data/yarn.lock +8321 -0
- metadata +267 -29
- data/.rspec +0 -3
- data/LICENSE.txt +0 -21
- data/bin/console +0 -14
- data/bin/setup +0 -8
- data/lib/jetpacker.rb +0 -6
data/docs/webpack.md
ADDED
@@ -0,0 +1,364 @@
|
|
1
|
+
# webpack
|
2
|
+
|
3
|
+
|
4
|
+
## Configuration
|
5
|
+
|
6
|
+
Webpacker gives you a default set of configuration files for test, development and
|
7
|
+
production environments in `config/webpack/*.js`. You can configure each individual
|
8
|
+
environment in their respective files or configure them all in the base
|
9
|
+
`config/webpack/environment.js` file.
|
10
|
+
|
11
|
+
By default, you don't need to make any changes to `config/webpack/*.js`
|
12
|
+
files since it's all standard production-ready configuration. However,
|
13
|
+
if you do need to customize or add a new loader, this is where you would go.
|
14
|
+
|
15
|
+
Here is how you can modify webpack configuration:
|
16
|
+
|
17
|
+
```js
|
18
|
+
// config/webpack/custom.js
|
19
|
+
module.exports = {
|
20
|
+
resolve: {
|
21
|
+
alias: {
|
22
|
+
jquery: 'jquery/src/jquery',
|
23
|
+
vue: 'vue/dist/vue.js',
|
24
|
+
React: 'react',
|
25
|
+
ReactDOM: 'react-dom',
|
26
|
+
vue_resource: 'vue-resource/dist/vue-resource',
|
27
|
+
}
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
31
|
+
// config/webpack/environment.js
|
32
|
+
const { environment } = require('@rails/webpacker')
|
33
|
+
const customConfig = require('./custom')
|
34
|
+
|
35
|
+
// Set nested object prop using path notation
|
36
|
+
environment.config.set('resolve.extensions', ['.foo', '.bar'])
|
37
|
+
environment.config.set('output.filename', '[name].js')
|
38
|
+
|
39
|
+
// Merge custom config
|
40
|
+
environment.config.merge(customConfig)
|
41
|
+
environment.config.merge({ devtool: 'none' })
|
42
|
+
|
43
|
+
// Delete a property
|
44
|
+
environment.config.delete('output.chunkFilename')
|
45
|
+
|
46
|
+
module.exports = environment
|
47
|
+
```
|
48
|
+
|
49
|
+
If you need access to configs within Webpacker's configuration,
|
50
|
+
you can import them like so:
|
51
|
+
|
52
|
+
```js
|
53
|
+
const { config } = require('@rails/webpacker')
|
54
|
+
|
55
|
+
console.log(config.output_path)
|
56
|
+
console.log(config.source_path)
|
57
|
+
```
|
58
|
+
|
59
|
+
## Loaders
|
60
|
+
|
61
|
+
You can add additional loaders beyond the base set that Webpacker provides by
|
62
|
+
adding it to your environment. We'll use `json-loader` as an example:
|
63
|
+
|
64
|
+
```
|
65
|
+
yarn add json-loader
|
66
|
+
```
|
67
|
+
|
68
|
+
```js
|
69
|
+
// config/webpack/environment.js
|
70
|
+
const { environment } = require('@rails/webpacker')
|
71
|
+
|
72
|
+
const jsonLoader = {
|
73
|
+
test: /\.json$/,
|
74
|
+
use: 'json-loader'
|
75
|
+
}
|
76
|
+
|
77
|
+
// Insert json loader at the end of list
|
78
|
+
environment.loaders.append('json', jsonLoader)
|
79
|
+
|
80
|
+
// Insert json loader at the top of list
|
81
|
+
environment.loaders.prepend('json', jsonLoader)
|
82
|
+
|
83
|
+
// Insert json loader after/before a given loader
|
84
|
+
environment.loaders.insert('json', jsonLoader, { after: 'style'} )
|
85
|
+
environment.loaders.insert('json', jsonLoader, { before: 'babel'} )
|
86
|
+
|
87
|
+
module.exports = environment
|
88
|
+
```
|
89
|
+
|
90
|
+
Finally add `.json` to the list of extensions in `config/webpacker.yml`. Now if you `import()` any `.json` files inside your JavaScript
|
91
|
+
they will be processed using `json-loader`. Voila!
|
92
|
+
|
93
|
+
You can also modify the loaders that Webpacker pre-configures for you. We'll update
|
94
|
+
the `babel` loader as an example:
|
95
|
+
|
96
|
+
```js
|
97
|
+
// config/webpack/environment.js
|
98
|
+
const { environment } = require('@rails/webpacker')
|
99
|
+
|
100
|
+
const babelLoader = environment.loaders.get('babel')
|
101
|
+
babelLoader.options.cacheDirectory = false
|
102
|
+
|
103
|
+
module.exports = environment
|
104
|
+
```
|
105
|
+
|
106
|
+
### Coffeescript 2
|
107
|
+
|
108
|
+
Out of the box webpacker supports coffeescript 1,
|
109
|
+
but here is how you can use Coffeescript 2:
|
110
|
+
|
111
|
+
```
|
112
|
+
yarn add coffeescript@2.0.1
|
113
|
+
```
|
114
|
+
|
115
|
+
```js
|
116
|
+
// config/webpack/environment.js
|
117
|
+
const { environment } = require('@rails/webpacker')
|
118
|
+
|
119
|
+
const babelLoader = environment.loaders.get('babel')
|
120
|
+
|
121
|
+
// Replace existing coffee loader with CS2 version
|
122
|
+
environment.loaders.insert('coffee', {
|
123
|
+
test: /\.coffee(\.erb)?$/,
|
124
|
+
use: babelLoader.use.concat(['coffee-loader'])
|
125
|
+
})
|
126
|
+
|
127
|
+
module.exports = environment
|
128
|
+
```
|
129
|
+
|
130
|
+
### React SVG loader
|
131
|
+
|
132
|
+
To use react svg loader, you should append svg loader before file loader:
|
133
|
+
|
134
|
+
```js
|
135
|
+
const { environment } = require('@rails/webpacker')
|
136
|
+
|
137
|
+
const babelLoader = environment.loaders.get('babel')
|
138
|
+
|
139
|
+
environment.loaders.insert('svg', {
|
140
|
+
test: /\.svg$/,
|
141
|
+
use: babelLoader.use.concat([
|
142
|
+
{
|
143
|
+
loader: 'react-svg-loader',
|
144
|
+
options: {
|
145
|
+
jsx: true // true outputs JSX tags
|
146
|
+
}
|
147
|
+
}
|
148
|
+
])
|
149
|
+
}, { before: 'file' })
|
150
|
+
|
151
|
+
const fileLoader = environment.loaders.get('file')
|
152
|
+
fileLoader.exclude = /\.(svg)$/i
|
153
|
+
```
|
154
|
+
|
155
|
+
|
156
|
+
### Url Loader
|
157
|
+
|
158
|
+
```js
|
159
|
+
// config/webpack/loaders/url.js
|
160
|
+
|
161
|
+
module.exports = {
|
162
|
+
test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
|
163
|
+
use: [{
|
164
|
+
loader: 'url-loader',
|
165
|
+
options: {
|
166
|
+
limit: 10000,
|
167
|
+
name: '[name]-[hash].[ext]'
|
168
|
+
}
|
169
|
+
}]
|
170
|
+
}
|
171
|
+
|
172
|
+
// config/webpack/environment.js
|
173
|
+
|
174
|
+
const { environment } = require('@rails/webpacker')
|
175
|
+
const url = require('./loaders/url')
|
176
|
+
|
177
|
+
environment.loaders.prepend('url', url)
|
178
|
+
|
179
|
+
// avoid using both file and url loaders
|
180
|
+
environment.loaders.get('file').test = /\.(tiff|ico|svg|eot|otf|ttf|woff|woff2)$/i
|
181
|
+
```
|
182
|
+
|
183
|
+
### Overriding Loader Options in webpack 3+ (for CSS Modules etc.)
|
184
|
+
|
185
|
+
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:
|
186
|
+
|
187
|
+
```javascript
|
188
|
+
const { environment } = require('@rails/webpacker')
|
189
|
+
const merge = require('webpack-merge')
|
190
|
+
|
191
|
+
const myCssLoaderOptions = {
|
192
|
+
modules: {
|
193
|
+
localIdentName: '[name]__[local]___[hash:base64:5]'
|
194
|
+
},
|
195
|
+
sourceMap: true,
|
196
|
+
}
|
197
|
+
|
198
|
+
const CSSLoader = environment.loaders.get('sass').use.find(el => el.loader === 'css-loader')
|
199
|
+
|
200
|
+
CSSLoader.options = merge(CSSLoader.options, myCssLoaderOptions)
|
201
|
+
|
202
|
+
module.exports = environment
|
203
|
+
```
|
204
|
+
|
205
|
+
See [issue #756](https://github.com/rails/webpacker/issues/756#issuecomment-327148547) for additional discussion of this.
|
206
|
+
|
207
|
+
For this to work, don't forget to use the `stylesheet_pack_tag`, for example:
|
208
|
+
|
209
|
+
```
|
210
|
+
<%= stylesheet_pack_tag 'YOUR_PACK_NAME_HERE' %>
|
211
|
+
```
|
212
|
+
|
213
|
+
## Plugins
|
214
|
+
|
215
|
+
The process for adding or modifying webpack plugins is the same as the process
|
216
|
+
for loaders above:
|
217
|
+
|
218
|
+
```js
|
219
|
+
// config/webpack/environment.js
|
220
|
+
const { environment } = require('@rails/webpacker')
|
221
|
+
const webpack = require('webpack')
|
222
|
+
|
223
|
+
// Get a pre-configured plugin
|
224
|
+
const manifestPlugin = environment.plugins.get('Manifest')
|
225
|
+
manifestPlugin.options.writeToFileEmit = false
|
226
|
+
|
227
|
+
// Add an additional plugin of your choosing : ProvidePlugin
|
228
|
+
environment.plugins.prepend(
|
229
|
+
'Provide',
|
230
|
+
new webpack.ProvidePlugin({
|
231
|
+
$: 'jquery',
|
232
|
+
jQuery: 'jquery',
|
233
|
+
jquery: 'jquery',
|
234
|
+
'window.Tether': 'tether',
|
235
|
+
Popper: ['popper.js', 'default'],
|
236
|
+
ActionCable: 'actioncable',
|
237
|
+
Vue: 'vue',
|
238
|
+
VueResource: 'vue-resource',
|
239
|
+
})
|
240
|
+
)
|
241
|
+
|
242
|
+
// Insert before a given plugin
|
243
|
+
environment.plugins.insert('CommonChunkVendor',
|
244
|
+
new webpack.optimize.CommonsChunkPlugin({
|
245
|
+
name: 'vendor', // Vendor code
|
246
|
+
minChunks: (module) => module.context && module.context.indexOf('node_modules') !== -1
|
247
|
+
})
|
248
|
+
, { before: 'manifest' })
|
249
|
+
|
250
|
+
module.exports = environment
|
251
|
+
```
|
252
|
+
|
253
|
+
## Resolved modules
|
254
|
+
|
255
|
+
To add new paths to `resolve.modules`, the API is same as loaders and plugins:
|
256
|
+
|
257
|
+
```js
|
258
|
+
const { environment } = require('@rails/webpacker')
|
259
|
+
|
260
|
+
// Resolved modules list API - prepend, append, insert
|
261
|
+
environment.resolvedModules.append('vendor', 'vendor')
|
262
|
+
```
|
263
|
+
|
264
|
+
### Add SplitChunks (Webpack V4)
|
265
|
+
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.
|
266
|
+
|
267
|
+
Since webpack v4, the CommonsChunkPlugin was removed in favor of optimization.splitChunks.
|
268
|
+
|
269
|
+
For the full configuration options of SplitChunks, see the [Webpack documentation](https://webpack.js.org/plugins/split-chunks-plugin/).
|
270
|
+
|
271
|
+
```js
|
272
|
+
// config/webpack/environment.js
|
273
|
+
|
274
|
+
// Enable the default config
|
275
|
+
environment.splitChunks()
|
276
|
+
|
277
|
+
// or using custom config
|
278
|
+
environment.splitChunks((config) => Object.assign({}, config, { optimization: { splitChunks: false }}))
|
279
|
+
```
|
280
|
+
|
281
|
+
Then use the `javascript_packs_with_chunks_tag` and `stylesheet_packs_with_chunks_tag` helpers to include all the transpiled
|
282
|
+
packs with the chunks in your view, which creates html tags for all the chunks.
|
283
|
+
|
284
|
+
```erb
|
285
|
+
<%= javascript_packs_with_chunks_tag 'calendar', 'map', 'data-turbolinks-track': 'reload' %>
|
286
|
+
|
287
|
+
<script src="/packs/vendor-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
|
288
|
+
<script src="/packs/calendar~runtime-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
|
289
|
+
<script src="/packs/calendar-1016838bab065ae1e314.js" data-turbolinks-track="reload"></script>
|
290
|
+
<script src="/packs/map~runtime-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
|
291
|
+
<script src="/packs/map-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
|
292
|
+
```
|
293
|
+
|
294
|
+
**Important:** Pass all your pack names when using this helper otherwise you will
|
295
|
+
get duplicated chunks on the page.
|
296
|
+
|
297
|
+
```erb
|
298
|
+
<%# DO %>
|
299
|
+
<%= javascript_packs_with_chunks_tag 'calendar', 'map' %>
|
300
|
+
|
301
|
+
<%# DON'T %>
|
302
|
+
<%= javascript_packs_with_chunks_tag 'calendar' %>
|
303
|
+
<%= javascript_packs_with_chunks_tag 'map' %>
|
304
|
+
```
|
305
|
+
|
306
|
+
For the old configuration with the CommonsChunkPlugin see below. **Note** that this functionality is deprecated in Webpack V4.
|
307
|
+
|
308
|
+
#### Preloading
|
309
|
+
|
310
|
+
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).
|
311
|
+
|
312
|
+
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).
|
313
|
+
|
314
|
+
You can preload your assets with the `preload_pack_asset` helper if you have Rails >= 5.2.x.
|
315
|
+
|
316
|
+
```erb
|
317
|
+
<%= preload_pack_asset 'fonts/fa-regular-400.woff2' %>
|
318
|
+
```
|
319
|
+
|
320
|
+
**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.
|
321
|
+
|
322
|
+
### Add common chunks (deprecated in Webpack V4)
|
323
|
+
|
324
|
+
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.
|
325
|
+
|
326
|
+
Add the plugins in `config/webpack/environment.js`:
|
327
|
+
|
328
|
+
```js
|
329
|
+
const webpack = require('webpack')
|
330
|
+
|
331
|
+
environment.plugins.append(
|
332
|
+
'CommonsChunkVendor',
|
333
|
+
new webpack.optimize.CommonsChunkPlugin({
|
334
|
+
name: 'vendor',
|
335
|
+
minChunks: (module) => {
|
336
|
+
// this assumes your vendor imports exist in the node_modules directory
|
337
|
+
return module.context && module.context.indexOf('node_modules') !== -1
|
338
|
+
}
|
339
|
+
})
|
340
|
+
)
|
341
|
+
|
342
|
+
environment.plugins.append(
|
343
|
+
'CommonsChunkManifest',
|
344
|
+
new webpack.optimize.CommonsChunkPlugin({
|
345
|
+
name: 'manifest',
|
346
|
+
minChunks: Infinity
|
347
|
+
})
|
348
|
+
)
|
349
|
+
```
|
350
|
+
|
351
|
+
Now, add these files to your `layouts/application.html.erb`:
|
352
|
+
|
353
|
+
```erb
|
354
|
+
<%# Head %>
|
355
|
+
|
356
|
+
<%= javascript_pack_tag "manifest" %>
|
357
|
+
<%= javascript_pack_tag "vendor" %>
|
358
|
+
|
359
|
+
<%# If importing any styles from node_modules in your JS app %>
|
360
|
+
|
361
|
+
<%= stylesheet_pack_tag "vendor" %>
|
362
|
+
```
|
363
|
+
|
364
|
+
More detailed guides available here: [webpack guides](https://webpack.js.org/guides/)
|
data/docs/yarn.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# Yarn
|
2
|
+
|
3
|
+
Webpacker by default uses `yarn` as a package manager for `node_modules`
|
4
|
+
|
5
|
+
|
6
|
+
## Add a new npm module
|
7
|
+
|
8
|
+
To add any new JS module you can use `yarn`:
|
9
|
+
|
10
|
+
```bash
|
11
|
+
yarn add bootstrap material-ui
|
12
|
+
```
|
13
|
+
|
14
|
+
## Add an npm module to `devDependencies`
|
15
|
+
To add a new JS module that will only be available to local development:
|
16
|
+
|
17
|
+
```bash
|
18
|
+
yarn add --dev browser-sync
|
19
|
+
```
|
20
|
+
|
21
|
+
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).
|
22
|
+
|
23
|
+
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.
|
@@ -0,0 +1,12 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
|
4
|
+
|
5
|
+
gemspec path: "../"
|
6
|
+
|
7
|
+
gem "rails", github: "rails/rails"
|
8
|
+
gem "arel", github: "rails/arel"
|
9
|
+
gem "rake", ">= 11.1"
|
10
|
+
gem "rack-proxy", require: false
|
11
|
+
gem "minitest", "~> 5.0"
|
12
|
+
gem "byebug"
|