webpacker 3.0.0 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/CHANGELOG.md +26 -0
- data/README.md +10 -1
- data/docs/env.md +9 -6
- data/docs/webpack.md +66 -18
- data/lib/install/bin/webpack-dev-server.tt +8 -7
- data/lib/install/config/webpacker.yml +1 -1
- data/lib/install/examples/angular/hello_angular/index.ts +3 -1
- data/lib/install/examples/angular/hello_angular/polyfills.ts +70 -16
- data/lib/tasks/webpacker/check_node.rake +8 -4
- data/lib/tasks/webpacker/check_yarn.rake +14 -5
- data/lib/webpacker/commands.rb +3 -2
- data/lib/webpacker/compiler.rb +2 -0
- data/lib/webpacker/dev_server_proxy.rb +2 -1
- data/lib/webpacker/manifest.rb +1 -1
- data/lib/webpacker/railtie.rb +5 -1
- data/lib/webpacker/version.rb +1 -1
- data/package.json +4 -3
- data/package/environments/development.js +0 -1
- data/test/command_test.rb +27 -0
- data/test/manifest_test.rb +1 -17
- metadata +4 -4
- data/Gemfile.lock +0 -144
- data/yarn.lock +0 -5137
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6509ab0499053e37d9af22b79262832b33f8cd91
|
4
|
+
data.tar.gz: 869403b35f9178ea48884343782822282b91afde
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8fd1e44cf21efb3ab7cb0e581c09e7ace7e3cb73412b227592885db69b5ffb57379f4386635f3937d1211e52aca75e907b4a417c7f2d255b2419e75681716cbc
|
7
|
+
data.tar.gz: 1c2cf1efddda9af825334f9e1cace219082ab6b24dbb1db307721c516533474b7451363c3b089819082adec696daea40967a0c55d4cfbe82d66d664b51b645a9
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,29 @@
|
|
1
|
+
## [3.0.1] - 2017-09-01
|
2
|
+
|
3
|
+
### Fixed
|
4
|
+
|
5
|
+
- Missing `node_modules/.bin/*` files by bumping minimum Yarn version to 0.25.2 [#727](https://github.com/rails/webpacker/pull/727)
|
6
|
+
|
7
|
+
- `webpacker:compile` task so that fails properly when webpack compilation fails [#728](https://github.com/rails/webpacker/pull/728)
|
8
|
+
|
9
|
+
- 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
|
10
|
+
|
11
|
+
- Make sure tagged logger works with rails < 5 [#716](https://github.com/rails/webpacker/pull/716)
|
12
|
+
|
13
|
+
### Added
|
14
|
+
|
15
|
+
- Allow webpack dev server listen host/ip to be configurable using additional `--listen-host` option
|
16
|
+
|
17
|
+
```bash
|
18
|
+
./bin/webpack-dev-server --listen-host 0.0.0.0 --host localhost
|
19
|
+
```
|
20
|
+
|
21
|
+
### Removed
|
22
|
+
|
23
|
+
- `watchContentBase` from devServer config so it doesn't unncessarily trigger
|
24
|
+
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.
|
25
|
+
|
26
|
+
|
1
27
|
## [3.0.0] - 2017-08-30
|
2
28
|
|
3
29
|
### Added
|
data/README.md
CHANGED
@@ -42,7 +42,7 @@ in which case you may not even need the asset pipeline. This is mostly relevant
|
|
42
42
|
* Ruby 2.2+
|
43
43
|
* Rails 4.2+
|
44
44
|
* Node.js 6.0.0+
|
45
|
-
* Yarn 0.
|
45
|
+
* Yarn 0.25.2+
|
46
46
|
|
47
47
|
|
48
48
|
## Features
|
@@ -162,6 +162,15 @@ precedence over the ones already set in the configuration file.
|
|
162
162
|
./bin/webpack-dev-server --host example.com --inline true --hot false
|
163
163
|
```
|
164
164
|
|
165
|
+
By default, webpack dev server listens on `localhost` in development for security
|
166
|
+
but if you want your app to be available over local LAN IP or VM instance like vagrant
|
167
|
+
you can pass an additional config option `--listen-host`
|
168
|
+
when running `./bin/webpack-dev-server` binstub:
|
169
|
+
|
170
|
+
```bash
|
171
|
+
./bin/webpack-dev-server --listen-host 0.0.0.0
|
172
|
+
```
|
173
|
+
|
165
174
|
**Note:** Don't forget to prefix `ruby` when running these binstubs on windows
|
166
175
|
|
167
176
|
## Integrations
|
data/docs/env.md
CHANGED
@@ -35,20 +35,23 @@ yarn add dotenv
|
|
35
35
|
// config/webpack/environment.js
|
36
36
|
|
37
37
|
...
|
38
|
-
const
|
38
|
+
const { environment } = require('@rails/webpacker')
|
39
|
+
const webpack = require('webpack')
|
40
|
+
const dotenv = require('dotenv')
|
39
41
|
|
40
42
|
const dotenvFiles = [
|
41
43
|
`.env.${process.env.NODE_ENV}.local`,
|
42
44
|
'.env.local',
|
43
45
|
`.env.${process.env.NODE_ENV}`,
|
44
46
|
'.env'
|
45
|
-
]
|
47
|
+
]
|
46
48
|
dotenvFiles.forEach((dotenvFile) => {
|
47
|
-
dotenv.config({ path: dotenvFile, silent: true })
|
48
|
-
})
|
49
|
+
dotenv.config({ path: dotenvFile, silent: true })
|
50
|
+
})
|
49
51
|
|
50
|
-
|
51
|
-
|
52
|
+
environment.plugins.set('Environment', new webpack.EnvironmentPlugin(JSON.parse(JSON.stringify(process.env))))
|
53
|
+
|
54
|
+
module.exports = environment
|
52
55
|
```
|
53
56
|
|
54
57
|
**Warning:** using Foreman/Invoker and npm dotenv at the same time can result in
|
data/docs/webpack.md
CHANGED
@@ -12,6 +12,33 @@ By default, you shouldn't have to make any changes to `config/webpack/*.js`
|
|
12
12
|
files since it's all standard production-ready configuration. However,
|
13
13
|
if you do need to customize or add a new loader, this is where you would go.
|
14
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/development.js
|
32
|
+
const merge = require('webpack-merge')
|
33
|
+
const environment = require('./environment')
|
34
|
+
const customConfig = require('./custom')
|
35
|
+
|
36
|
+
module.exports = merge(environment.toWebpackConfig(), customConfig)
|
37
|
+
```
|
38
|
+
|
39
|
+
**Note:** You will have to merge custom config to all env where you want that config
|
40
|
+
to be available. In above case, it will be applied to development environment.
|
41
|
+
|
15
42
|
|
16
43
|
## Loaders
|
17
44
|
|
@@ -26,7 +53,7 @@ yarn add json-loader
|
|
26
53
|
// config/webpack/environment.js
|
27
54
|
const { environment } = require('@rails/webpacker')
|
28
55
|
|
29
|
-
environment.loaders.
|
56
|
+
environment.loaders.set('json', {
|
30
57
|
test: /\.json$/,
|
31
58
|
use: 'json-loader'
|
32
59
|
})
|
@@ -60,12 +87,25 @@ for loaders above:
|
|
60
87
|
```js
|
61
88
|
// config/webpack/environment.js
|
62
89
|
const { environment } = require('@rails/webpacker')
|
90
|
+
const webpack = require('webpack')
|
63
91
|
|
64
92
|
// Get a pre-configured plugin
|
65
93
|
environment.plugins.get('ExtractText') // Is an ExtractTextPlugin instance
|
66
94
|
|
67
|
-
// Add an additional plugin of your choosing
|
68
|
-
environment.plugins.
|
95
|
+
// Add an additional plugin of your choosing : ProvidePlugin
|
96
|
+
environment.plugins.set(
|
97
|
+
'Provide',
|
98
|
+
new webpack.ProvidePlugin({
|
99
|
+
$: 'jquery',
|
100
|
+
jQuery: 'jquery',
|
101
|
+
jquery: 'jquery',
|
102
|
+
'window.Tether': 'tether',
|
103
|
+
Popper: ['popper.js', 'default'],
|
104
|
+
ActionCable: 'actioncable',
|
105
|
+
Vue: 'vue',
|
106
|
+
VueResource: 'vue-resource',
|
107
|
+
})
|
108
|
+
)
|
69
109
|
|
70
110
|
module.exports = environment
|
71
111
|
```
|
@@ -78,18 +118,26 @@ The CommonsChunkPlugin is an opt-in feature that creates a separate file (known
|
|
78
118
|
Add the plugins in `config/webpack/environment.js`:
|
79
119
|
|
80
120
|
```js
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
121
|
+
const webpack = require('webpack')
|
122
|
+
|
123
|
+
environment.plugins.set(
|
124
|
+
'CommonsChunkVendor',
|
125
|
+
new webpack.optimize.CommonsChunkPlugin({
|
126
|
+
name: 'vendor',
|
127
|
+
minChunks: (module) => {
|
128
|
+
// this assumes your vendor imports exist in the node_modules directory
|
129
|
+
return module.context && module.context.indexOf('node_modules') !== -1;
|
130
|
+
}
|
131
|
+
})
|
132
|
+
)
|
133
|
+
|
134
|
+
environment.plugins.set(
|
135
|
+
'CommonsChunkManifest',
|
136
|
+
new webpack.optimize.CommonsChunkPlugin({
|
137
|
+
name: 'manifest',
|
138
|
+
minChunks: Infinity
|
139
|
+
})
|
140
|
+
)
|
93
141
|
```
|
94
142
|
|
95
143
|
Now, add these files to your `layouts/application.html.erb`:
|
@@ -97,12 +145,12 @@ Now, add these files to your `layouts/application.html.erb`:
|
|
97
145
|
```erb
|
98
146
|
<%# Head %>
|
99
147
|
|
100
|
-
<%= javascript_pack_tag
|
101
|
-
<%= javascript_pack_tag
|
148
|
+
<%= javascript_pack_tag "manifest" %>
|
149
|
+
<%= javascript_pack_tag "vendor" %>
|
102
150
|
|
103
151
|
<%# If importing any styles from node_modules in your JS app %>
|
104
152
|
|
105
|
-
<%= stylesheet_pack_tag
|
153
|
+
<%= stylesheet_pack_tag "vendor" %>
|
106
154
|
```
|
107
155
|
|
108
156
|
More detailed guides available here: [Webpack guides](https://webpack.js.org/guides/)
|
@@ -16,7 +16,7 @@ CONFIG_FILE = File.join(APP_PATH, "config/webpacker.yml")
|
|
16
16
|
NODE_MODULES_PATH = File.join(APP_PATH, "node_modules")
|
17
17
|
WEBPACK_CONFIG = File.join(APP_PATH, "config/webpack/#{NODE_ENV}.js")
|
18
18
|
|
19
|
-
|
19
|
+
DEFAULT_LISTEN_HOST_ADDR = NODE_ENV == 'development' ? 'localhost' : '0.0.0.0'
|
20
20
|
|
21
21
|
def args(key)
|
22
22
|
index = ARGV.index(key)
|
@@ -26,10 +26,11 @@ end
|
|
26
26
|
begin
|
27
27
|
dev_server = YAML.load_file(CONFIG_FILE)[RAILS_ENV]["dev_server"]
|
28
28
|
|
29
|
-
HOSTNAME
|
30
|
-
PORT
|
31
|
-
HTTPS
|
32
|
-
DEV_SERVER_ADDR
|
29
|
+
HOSTNAME = args('--host') || dev_server["host"]
|
30
|
+
PORT = args('--port') || dev_server["port"]
|
31
|
+
HTTPS = ARGV.include?('--https') || dev_server["https"]
|
32
|
+
DEV_SERVER_ADDR = "http#{"s" if HTTPS}://#{HOSTNAME}:#{PORT}"
|
33
|
+
LISTEN_HOST_ADDR = args('--listen-host') || DEFAULT_LISTEN_HOST_ADDR
|
33
34
|
|
34
35
|
rescue Errno::ENOENT, NoMethodError
|
35
36
|
$stdout.puts "Webpack dev_server configuration not found in #{CONFIG_FILE}."
|
@@ -46,8 +47,8 @@ rescue Errno::EADDRINUSE
|
|
46
47
|
exit!
|
47
48
|
end
|
48
49
|
|
49
|
-
# Delete supplied host and
|
50
|
-
["--host", "--port"].each do |arg|
|
50
|
+
# Delete supplied host, port and listen-host CLI arguments
|
51
|
+
["--host", "--port", "--listen-host"].each do |arg|
|
51
52
|
ARGV.delete(args(arg))
|
52
53
|
ARGV.delete(arg)
|
53
54
|
end
|
@@ -49,7 +49,7 @@ test:
|
|
49
49
|
production:
|
50
50
|
<<: *default
|
51
51
|
|
52
|
-
# Production
|
52
|
+
# Production depends on precompilation of packs prior to booting for performance.
|
53
53
|
compile: false
|
54
54
|
|
55
55
|
# Cache manifest.json for performance
|
@@ -3,4 +3,6 @@ import './polyfills.ts';
|
|
3
3
|
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
|
4
4
|
import { AppModule } from './app/app.module';
|
5
5
|
|
6
|
-
|
6
|
+
document.addEventListener('DOMContentLoaded', () => {
|
7
|
+
platformBrowserDynamic().bootstrapModule(AppModule);
|
8
|
+
});
|
@@ -1,19 +1,73 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
1
|
+
/**
|
2
|
+
* This file includes polyfills needed by Angular and is loaded before the app.
|
3
|
+
* You can add your own extra polyfills to this file.
|
4
|
+
*
|
5
|
+
* This file is divided into 2 sections:
|
6
|
+
* 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
|
7
|
+
* 2. Application imports. Files imported after ZoneJS that should be loaded before your main
|
8
|
+
* file.
|
9
|
+
*
|
10
|
+
* The current setup is for so-called "evergreen" browsers; the last versions of browsers that
|
11
|
+
* automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
|
12
|
+
* Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
|
13
|
+
*
|
14
|
+
* Learn more in https://angular.io/docs/ts/latest/guide/browser-support.html
|
15
|
+
*/
|
16
|
+
|
17
|
+
/***************************************************************************************************
|
18
|
+
* BROWSER POLYFILLS
|
19
|
+
*/
|
20
|
+
|
21
|
+
/** IE9, IE10 and IE11 requires all of the following polyfills. **/
|
22
|
+
// import 'core-js/es6/symbol';
|
23
|
+
// import 'core-js/es6/object';
|
24
|
+
// import 'core-js/es6/function';
|
25
|
+
// import 'core-js/es6/parse-int';
|
26
|
+
// import 'core-js/es6/parse-float';
|
27
|
+
// import 'core-js/es6/number';
|
28
|
+
// import 'core-js/es6/math';
|
29
|
+
// import 'core-js/es6/string';
|
30
|
+
// import 'core-js/es6/date';
|
31
|
+
// import 'core-js/es6/array';
|
32
|
+
// import 'core-js/es6/regexp';
|
33
|
+
// import 'core-js/es6/map';
|
34
|
+
// import 'core-js/es6/weak-map';
|
35
|
+
// import 'core-js/es6/set';
|
36
|
+
|
37
|
+
/** IE10 and IE11 requires the following for NgClass support on SVG elements */
|
38
|
+
// import 'classlist.js'; // Run `npm install --save classlist.js`.
|
17
39
|
|
40
|
+
/** Evergreen browsers require these. **/
|
41
|
+
import 'core-js/es6/reflect';
|
18
42
|
import 'core-js/es7/reflect';
|
43
|
+
|
44
|
+
|
45
|
+
/**
|
46
|
+
* Required to support Web Animations `@angular/animation`.
|
47
|
+
* Needed for: All but Chrome, Firefox and Opera. http://caniuse.com/#feat=web-animation
|
48
|
+
**/
|
49
|
+
// import 'web-animations-js'; // Run `npm install --save web-animations-js`.
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
/***************************************************************************************************
|
54
|
+
* Zone JS is required by Angular itself.
|
55
|
+
*/
|
19
56
|
import 'zone.js/dist/zone';
|
57
|
+
// import 'zone.js/dist/long-stack-trace-zone' // async stack traces with zone.js
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
/***************************************************************************************************
|
62
|
+
* APPLICATION IMPORTS
|
63
|
+
*/
|
64
|
+
|
65
|
+
/**
|
66
|
+
* Date, currency, decimal and percent pipes.
|
67
|
+
* Needed for: All but Chrome, Firefox, Edge, IE11 and Safari 10
|
68
|
+
*/
|
69
|
+
// import 'intl'; // Run `npm install --save intl`.
|
70
|
+
/**
|
71
|
+
* Need to import at least one locale-data with intl.
|
72
|
+
*/
|
73
|
+
// import 'intl/locale-data/jsonp/en';
|
@@ -4,12 +4,16 @@ namespace :webpacker do
|
|
4
4
|
begin
|
5
5
|
node_version = `node -v`
|
6
6
|
node_version = `nodejs -v` if node_version.blank?
|
7
|
-
required_node_version = "6.0"
|
8
|
-
|
9
7
|
raise Errno::ENOENT if node_version.blank?
|
10
8
|
|
11
|
-
|
12
|
-
|
9
|
+
pkg_path = Pathname.new("#{__dir__}/../../../package.json").realpath
|
10
|
+
node_requirement = JSON.parse(pkg_path.read)["engines"]["node"]
|
11
|
+
|
12
|
+
requirement = Gem::Requirement.new(node_requirement)
|
13
|
+
version = Gem::Version.new(node_version.strip.tr("v", ""))
|
14
|
+
|
15
|
+
unless requirement.satisfied_by?(version)
|
16
|
+
$stderr.puts "Webpacker requires Node.js #{requirement} and you are using #{version}"
|
13
17
|
$stderr.puts "Please upgrade Node.js https://nodejs.org/en/download/"
|
14
18
|
$stderr.puts "Exiting!" && exit!
|
15
19
|
end
|
@@ -1,14 +1,23 @@
|
|
1
1
|
namespace :webpacker do
|
2
|
-
desc "Verifies if
|
2
|
+
desc "Verifies if Yarn is installed"
|
3
3
|
task :check_yarn do
|
4
|
-
required_yarn_version = "0.20.1"
|
5
|
-
|
6
4
|
begin
|
7
5
|
yarn_version = `yarn --version`
|
6
|
+
raise Errno::ENOENT if yarn_version.blank?
|
7
|
+
|
8
|
+
pkg_path = Pathname.new("#{__dir__}/../../../package.json").realpath
|
9
|
+
yarn_requirement = JSON.parse(pkg_path.read)["engines"]["yarn"]
|
10
|
+
|
11
|
+
requirement = Gem::Requirement.new(yarn_requirement)
|
12
|
+
version = Gem::Version.new(yarn_version)
|
8
13
|
|
9
|
-
|
14
|
+
unless requirement.satisfied_by?(version)
|
15
|
+
$stderr.puts "Webpacker requires Yarn #{requirement} and you are using #{version}"
|
16
|
+
$stderr.puts "Please upgrade Yarn https://yarnpkg.com/lang/en/docs/install/"
|
17
|
+
$stderr.puts "Exiting!" && exit!
|
18
|
+
end
|
10
19
|
rescue Errno::ENOENT
|
11
|
-
$stderr.puts "
|
20
|
+
$stderr.puts "Yarn not installed. Please download and install Yarn from https://yarnpkg.com/lang/en/docs/install/"
|
12
21
|
$stderr.puts "Exiting!" && exit!
|
13
22
|
end
|
14
23
|
end
|
data/lib/webpacker/commands.rb
CHANGED