Skip to content

Commit a69ddef

Browse files
* 'master' of https://github.com/rails/webpacker: (21 commits) Update Ruby versions on Travis CI (rails#1230) Make rubocop happy Fix asset helper for non-css assets in hmr mode CSP warning for Rails 5.2 use 2 spaces for indentation in template injection Update README.md (rails#1198) Remove duplicate yarn-error.log (rails#1197) 3.2.1 Revert file loader (rails#1196) Update default extensions and move to installer (rails#1181) Gitignore (rails#1195) Update uglify plugin (rails#1194) Fixes Vue root instance initialization (rails#1187) Return false in production environments (rails#1179) Fix url loader doc[ci skip] (rails#1183) Use inject_into_file to support rails 4.2 Update gems and npm deps (rails#1180) asset_pack_path + HMR fix; Closes rails#1171 (rails#1172) enhance CHANGELOG.md (rails#1170) CI against Ruby 2.5.0 ...
2 parents 25b1da0 + a3b29d3 commit a69ddef

33 files changed

+987
-512
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44
node_modules
55
.byebug_history
66
/test/test_app/tmp
7+
yarn-debug.log*
8+
yarn-error.log*
9+
.yarn-integrity

.travis.yml

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
sudo: false
22
language: ruby
3+
before_install:
4+
- gem update --system
35
rvm:
4-
- 2.2.8
5-
- 2.3.5
6-
- 2.4.2
6+
- 2.2.9
7+
- 2.3.6
8+
- 2.4.3
9+
- 2.5.0
710
- ruby-head
811
gemfile:
912
- gemfiles/Gemfile-rails.4.2.x

CHANGELOG.md

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
**Please note that Webpacker 3.1.0 and 3.1.1 has some serious bugs so please consider using either 3.0.2 or 3.2.0**
22

3+
## [3.2.1] - 2018-01-21
4+
5+
- Disable dev server running? check if no dev server config is present in that environment [#1179](https://github.com/rails/webpacker/pull/1179)
6+
7+
- Fix checking 'webpack' binstub on Windows [#1123](https://github.com/rails/webpacker/pull/1123)
8+
9+
- silence yarn output if checking is successfull [#1131](https://github.com/rails/webpacker/pull/1131)
10+
11+
- Update uglifyJs plugin to support ES6 [#1194](https://github.com/rails/webpacker/pull/1194)
12+
13+
- Add typescript installer [#1145](https://github.com/rails/webpacker/pull/1145)
14+
15+
- Update default extensions and move to installer [#1181](https://github.com/rails/webpacker/pull/1181)
16+
17+
- Revert file loader [#1196](https://github.com/rails/webpacker/pull/1196)
18+
19+
320
## [3.2.0] - 2017-12-16
421

522
### To upgrade:
@@ -151,7 +168,7 @@ files.
151168
const sassLoader = environment.loaders.get('sass')
152169
const cssLoader = sassLoader.use.find(loader => loader.loader === 'css-loader')
153170
154-
cssLoader.options = Object.assign(cssLoader.options, {
171+
cssLoader.options = Object.assign({}, cssLoader.options, {
155172
modules: true,
156173
localIdentName: '[path][name]__[local]--[hash:base64:5]'
157174
})

Gemfile.lock

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
webpacker (3.2.0)
4+
webpacker (3.2.1)
55
activesupport (>= 4.2)
66
rack-proxy (>= 0.6.1)
77
railties (>= 4.2)
@@ -65,11 +65,11 @@ GEM
6565
method_source (0.9.0)
6666
mini_mime (1.0.0)
6767
mini_portile2 (2.3.0)
68-
minitest (5.10.3)
69-
nio4r (2.1.0)
68+
minitest (5.11.1)
69+
nio4r (2.2.0)
7070
nokogiri (1.8.1)
7171
mini_portile2 (~> 2.3.0)
72-
parallel (1.12.0)
72+
parallel (1.12.1)
7373
parser (2.4.0.2)
7474
ast (~> 2.3)
7575
powerpack (0.1.1)
@@ -101,14 +101,13 @@ GEM
101101
method_source
102102
rake (>= 0.8.7)
103103
thor (>= 0.18.1, < 2.0)
104-
rainbow (2.2.2)
105-
rake
104+
rainbow (3.0.0)
106105
rake (12.3.0)
107-
rubocop (0.51.0)
106+
rubocop (0.52.1)
108107
parallel (~> 1.10)
109-
parser (>= 2.3.3.1, < 3.0)
108+
parser (>= 2.4.0.2, < 3.0)
110109
powerpack (~> 0.1)
111-
rainbow (>= 2.2.2, < 3.0)
110+
rainbow (>= 2.2.2, < 4.0)
112111
ruby-progressbar (~> 1.7)
113112
unicode-display_width (~> 1.0, >= 1.0.1)
114113
ruby-progressbar (1.9.0)

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ configuration:
306306
p.script_src :self, :https
307307
end
308308
```
309-
You can read more this in [Vue docs](https://vuejs.org/v2/guide/installation.html#CSP-environments).
309+
You can read more about this in the [Vue docs](https://vuejs.org/v2/guide/installation.html#CSP-environments).
310310

311311

312312
### Elm

docs/typescript.md

+5-33
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,15 @@
33

44
## Typescript with React
55

6-
1. Setup react using Webpacker [react installer](#react). Then add required depedencies
7-
for using typescript with React:
6+
1. Setup react using Webpacker [react installer](#react). Then run the typescript installer
87

98
```bash
10-
yarn add ts-loader typescript @types/react @types/react-dom
9+
bundle exec rails webpacker:install:typescript
10+
yarn add @types/react @types/react-dom
1111
```
1212

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-
13+
2. Rename the generated `hello_react.js` to `hello_react.tsx`. Make the file valid typescript and
14+
now you can use typescript, JSX with React.
4315

4416

4517
## HTML templates with Typescript and Angular

docs/webpack.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,10 @@ environment.loaders.insert('svg', {
142142
}
143143
}
144144
])
145-
}, { before: 'file' })
145+
}, { after: 'file' })
146+
147+
const fileLoader = environment.loaders.get('file')
148+
fileLoader.exclude = /\.(svg)$/i
146149
```
147150

148151

@@ -151,16 +154,13 @@ environment.loaders.insert('svg', {
151154
```js
152155
// config/webpack/loaders/url.js
153156

154-
const { assetHost } = require('@rails/webpacker')
155-
156157
module.exports = {
157158
test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
158159
use: [{
159160
loader: 'url-loader',
160161
options: {
161162
limit: 10000,
162-
name: '[name]-[hash].[ext]',
163-
publicPath: assetHost.publicPathWithHost
163+
name: '[name]-[hash].[ext]'
164164
}
165165
}]
166166
}

lib/install/angular.rb

+14-18
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
11
require "webpacker/configuration"
22

3-
say "Copying angular loader to config/webpack/loaders"
4-
copy_file "#{__dir__}/loaders/typescript.js", Rails.root.join("config/webpack/loaders/typescript.js").to_s
5-
6-
say "Adding typescript loader to config/webpack/environment.js"
7-
insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
8-
"const typescript = require('./loaders/typescript')\n",
9-
after: "require('@rails/webpacker')\n"
10-
11-
insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
12-
"environment.loaders.append('typescript', typescript)\n",
13-
before: "module.exports"
14-
153
say "Copying angular example entry file to #{Webpacker.config.source_entry_path}"
164
copy_file "#{__dir__}/examples/angular/hello_angular.js", "#{Webpacker.config.source_entry_path}/hello_angular.js"
175

186
say "Copying hello_angular app to #{Webpacker.config.source_path}"
197
directory "#{__dir__}/examples/angular/hello_angular", "#{Webpacker.config.source_path}/hello_angular"
208

21-
say "Copying tsconfig.json to the Rails root directory for typescript"
22-
copy_file "#{__dir__}/examples/angular/tsconfig.json", "tsconfig.json"
23-
249
say "Installing all angular dependencies"
25-
run "yarn add typescript ts-loader core-js zone.js rxjs @angular/core @angular/common @angular/compiler @angular/platform-browser @angular/platform-browser-dynamic"
26-
27-
say "Webpacker now supports angular and typescript 🎉", :green
10+
run "yarn add core-js zone.js rxjs @angular/core @angular/common @angular/compiler @angular/platform-browser @angular/platform-browser-dynamic"
11+
12+
if Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR > 1
13+
say "You need to enable unsafe-eval rule.", :yellow
14+
say "This can be done in Rails 5.2+ for development environment in the CSP initializer", :yellow
15+
say "config/initializers/content_security_policy.rb with a snippet like this:", :yellow
16+
say "if Rails.env.development?", :yellow
17+
say " p.script_src :self, :https, :unsafe_eval", :yellow
18+
say "else", :yellow
19+
say " p.script_src :self, :https", :yellow
20+
say "end", :yellow
21+
end
22+
23+
say "Webpacker now supports angular 🎉", :green

lib/install/coffee.rb

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
"environment.loaders.append('coffee', coffee)\n",
1313
before: "module.exports"
1414

15+
say "Updating webpack paths to include .coffee file extension"
16+
insert_into_file Webpacker.config.config_path, " - .coffee\n", after: /extensions:\n/
17+
1518
say "Copying the example entry file to #{Webpacker.config.source_entry_path}"
1619
copy_file "#{__dir__}/examples/coffee/hello_coffee.coffee",
1720
"#{Webpacker.config.source_entry_path}/hello_coffee.coffee"

lib/install/config/webpacker.yml

-5
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,7 @@ default: &default
1414
cache_manifest: false
1515

1616
extensions:
17-
- .coffee
18-
- .erb
1917
- .js
20-
- .jsx
21-
- .ts
22-
- .vue
2318
- .sass
2419
- .scss
2520
- .css

lib/install/elm.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
run "yarn add --dev elm-hot-loader"
2626
run "yarn run elm package install -- --yes"
2727

28-
say "Updating webpack paths to include Elm file extension"
28+
say "Updating webpack paths to include .elm file extension"
2929
insert_into_file Webpacker.config.config_path, " - .elm\n", after: /extensions:\n/
3030

3131
say "Updating Elm source location"

lib/install/erb.rb

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
"environment.loaders.append('erb', erb)\n",
1313
before: "module.exports"
1414

15+
say "Updating webpack paths to include .erb file extension"
16+
insert_into_file Webpacker.config.config_path, " - .erb\n", after: /extensions:\n/
17+
1518
say "Copying the example entry file to #{Webpacker.config.source_entry_path}"
1619
copy_file "#{__dir__}/examples/erb/hello_erb.js.erb",
1720
"#{Webpacker.config.source_entry_path}/hello_erb.js.erb"
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"compilerOptions": {
3+
"declaration": false,
4+
"emitDecoratorMetadata": true,
5+
"experimentalDecorators": true,
6+
"lib": ["es6", "dom"],
7+
"module": "es6",
8+
"moduleResolution": "node",
9+
"sourceMap": true,
10+
"target": "es5",
11+
"jsx": "react"
12+
},
13+
"exclude": [
14+
"**/*.spec.ts",
15+
"node_modules",
16+
"vendor",
17+
"public"
18+
],
19+
"compileOnSave": false
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Run this example by adding <%%= javascript_pack_tag 'hello_typescript' %> to the head of your layout file,
2+
// like app/views/layouts/application.html.erb.
3+
4+
console.log('Hello world from typescript');

lib/install/examples/vue/hello_vue.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ import Vue from 'vue'
99
import App from '../app.vue'
1010

1111
document.addEventListener('DOMContentLoaded', () => {
12-
document.body.appendChild(document.createElement('hello'))
12+
const el = document.body.appendChild(document.createElement('hello'))
1313
const app = new Vue({
14+
el,
1415
render: h => h(App)
15-
}).$mount('hello')
16+
})
1617

1718
console.log(app)
1819
})

lib/install/react.rb

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
say "Copying react example entry file to #{Webpacker.config.source_entry_path}"
2323
copy_file "#{__dir__}/examples/react/hello_react.jsx", "#{Webpacker.config.source_entry_path}/hello_react.jsx"
2424

25+
say "Updating webpack paths to include .jsx file extension"
26+
insert_into_file Webpacker.config.config_path, " - .jsx\n", after: /extensions:\n/
27+
2528
say "Installing all react dependencies"
2629
run "yarn add react react-dom babel-preset-react prop-types"
2730

lib/install/template.rb

+14-9
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,32 @@
1717
run "bundle binstubs webpacker"
1818

1919
say "Adding configurations"
20-
environment <<CONFIG, env: :development
21-
# Verifies that versions and hashed value of the package contents in the project's package.json
22-
config.webpacker.check_yarn_integrity = true
23-
CONFIG
24-
environment <<CONFIG, env: :production
25-
# Verifies that versions and hashed value of the package contents in the project's package.json
26-
config.webpacker.check_yarn_integrity = false
27-
CONFIG
20+
21+
# Verifies that versions and hashed value of the package contents in the project's package.json
22+
inject_into_file "config/environments/development.rb", " config.webpacker.check_yarn_integrity = true", after: "Rails.application.configure do\n", verbose: false
23+
inject_into_file "config/environments/production.rb", " config.webpacker.check_yarn_integrity = false", after: "Rails.application.configure do\n", verbose: false
2824

2925
if File.exists?(".gitignore")
3026
append_to_file ".gitignore", <<-EOS
3127
/public/packs
3228
/public/packs-test
3329
/node_modules
30+
yarn-debug.log*
31+
.yarn-integrity
3432
EOS
3533
end
3634

3735
say "Installing all JavaScript dependencies"
38-
run "yarn add @rails/webpacker [email protected]"
36+
run "yarn add @rails/webpacker"
3937

4038
say "Installing dev server for live reloading"
4139
run "yarn add --dev webpack-dev-server"
4240

41+
if Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR > 1
42+
say "You need to allow webpack-dev-server host as allowed origin for connect-src.", :yellow
43+
say "This can be done in Rails 5.2+ for development environment in the CSP initializer", :yellow
44+
say "config/initializers/content_security_policy.rb with a snippet like this:", :yellow
45+
say "p.connect_src :self, :https, \"http://localhost:3035\", \"ws://localhost:3035\" if Rails.env.development?", :yellow
46+
end
47+
4348
say "Webpacker successfully installed 🎉 🍰", :green

0 commit comments

Comments
 (0)