Skip to content

Commit e01cffb

Browse files
authored
Merge pull request #370 from matestack/sf/webpacker-part-2
Sf/webpacker part 2
2 parents 0b65c13 + 1ce7685 commit e01cffb

File tree

13 files changed

+221
-42
lines changed

13 files changed

+221
-42
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ spec/dummy/db/*.sqlite3
66
spec/dummy/db/*.sqlite3-journal
77
spec/dummy/log/*.log
88
spec/dummy/node_modules/
9+
spec/dummy/public/packs/
910
spec/dummy/yarn-error.log
1011
spec/dummy/storage/
1112
spec/dummy/tmp/

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,12 @@ We love to see more and more people using and contributing to matestack-ui-core.
2727
* core refactoring, increased core maintainability and code quality
2828
* better integration in existing rails apps
2929
* improved documentation
30-
* webpacker support and npm based js dependecy management
3130
* improved dynamic core components (especially form components)
3231

3332

3433
### Installation:
3534

36-
Click here to see how you can add Matestack UI to your existing Rails application: [Installation Guide](https://www.matestack.org/docs/install)
35+
Click here to see how you can add Matestack UI to your existing Rails application: [Installation Guide](./docs/install)
3736

3837
### Features:
3938

Rakefile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,30 +37,30 @@ task :webpack => 'webpack:build'
3737

3838
namespace :webpack do
3939
task :build => ['build:development', 'build:production']
40-
40+
4141
namespace :build do
4242
task :development => 'yarn:install' do
43-
Bundler.with_clean_env do
43+
Bundler.with_unbundled_env do
4444
sh "cd builder && bin/webpack"
4545
end
4646
end
4747
task :production => 'yarn:install' do
48-
Bundler.with_clean_env do
48+
Bundler.with_unbundled_env do
4949
sh "cd builder && bin/rake webpacker:compile"
5050
end
5151
end
5252
end
53-
53+
5454
task :watch => 'yarn:install' do
55-
Bundler.with_clean_env do
55+
Bundler.with_unbundled_env do
5656
sh "cd builder && bin/webpack --watch"
5757
end
5858
end
59-
59+
6060
namespace :yarn do
6161
task :install do
6262
sh "yarn install && cd builder && yarn install"
6363
end
6464
end
65-
end
65+
end
6666

docs/install/README.md

Lines changed: 67 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Install
22

3-
If your're using the classic Rails assets pipeline, this guide shows you how to
4-
add matestack to your Rails app.
3+
This guide shows you how to add matestack-ui-core to an existing rails application.
54

65
## Gemfile
76

@@ -19,15 +18,56 @@ $ bundle install
1918

2019
## Javascript
2120

22-
Require 'matestack-ui-core' in your `assets/javascript/application.js`
21+
Matestack uses javascripts and, in particular, [vuejs](http://vuejs.org). To include these into your existing rails app, matestack supports both, [webpack](https://webpack.js.org/)([er](https://github.com/rails/webpacker/)) and the [asset pipeline](https://guides.rubyonrails.org/asset_pipeline.html).
22+
23+
Rails 6+ apps, by default, use webpacker, rails 5 apps, by default, use the asset pipeline.
24+
25+
### Webpacker
26+
27+
Add 'matestack-ui-core' to your `package.json` by running:
28+
29+
```
30+
$ yarn add https://github.com/matestack/matestack-ui-core#v0.7.4
31+
$ yarn install
32+
```
33+
34+
This adds the npm package that provides the javascript files corresponding to matestack-ui-core ruby gem. Make sure that the npm package version matches the gem version. To find out what gem version you are using, you may use `bundle info matestack-ui-core`.
35+
36+
Next, import 'matestack-ui-core' in your `app/javascript/packs/application.js`
37+
38+
```js
39+
import MatestackUiCore from 'matestack-ui-core'
40+
```
41+
42+
and compile the javascript code with webpack:
43+
44+
```
45+
$ bin/webpack
46+
```
47+
48+
When, in the future, you update the matestack-ui-core gem, make also sure to update the npm package as well.
49+
50+
### Asset Pipeline
51+
52+
If you are not using webpacker but the asset pipeline, you don't need to install a separate npm package. All required javascript libraries including vuejs are provided by matestack-ui-core ready-to-use via the asset pipeline.
53+
54+
Require 'matestack-ui-core' in your `app/assets/javascript/application.js`
2355

2456
```javascript
2557
//= require matestack-ui-core
2658
```
27-
Note:
2859

29-
- **Remove turbolinks! Currently, matestack can't be used with turbolinks. This will be fixed soon**
30-
- Additional Webpacker integration is coming soon
60+
Require 'matestack-ui-core' in your `app/assets/stylesheets/application.css`
61+
62+
```css
63+
/*
64+
*= require matestack-ui-core
65+
*/
66+
```
67+
68+
### Turbolinks Coming Soon
69+
70+
At the moment, matestack-ui-core is not compatible with [turbolinks](https://github.com/turbolinks/turbolinks). Please remove or deactive turbolinks for now. We are working on turbolinks support and will add it soon. ([Issue #232](https://github.com/matestack/matestack-ui-core/issues/232))
3171

3272
## Matestack Folder
3373

@@ -54,7 +94,7 @@ You need to add the ID "matestack_ui" to some part of your application layout (o
5494

5595
For Example, your `app/views/layouts/application.html.erb` should look like this:
5696

57-
```html+erb
97+
```erb
5898
<!DOCTYPE html>
5999
<html>
60100
<head>
@@ -63,6 +103,11 @@ For Example, your `app/views/layouts/application.html.erb` should look like this
63103
<%= csp_meta_tag %>
64104
65105
<%= stylesheet_link_tag 'application', media: 'all' %>
106+
107+
<!-- if you are using webpacker: -->
108+
<%= javascript_pack_tag 'application' %>
109+
110+
<!-- if you are using the asset pipeline: -->
66111
<%= javascript_include_tag 'application' %>
67112
</head>
68113
@@ -75,13 +120,25 @@ For Example, your `app/views/layouts/application.html.erb` should look like this
75120
```
76121
Don't apply the matestack_ui ID to the body tag.
77122

78-
## Extend Asset Paths
123+
## Adding Support for Custom Components
124+
125+
If you intend to write custom dynamic matestack components for your app, you need to make those accessible to the matestack-ui-core javscript code.
126+
127+
### Webpack
128+
129+
When using webpack, make sure to import your custom components in `app/javascript/packs/application.js`:
130+
131+
```js
132+
import MatestackUiCore from 'matestack-ui-core'
133+
import '../../../app/matestack/components/my_custom_component'
134+
```
79135

80-
In order to enable custom Vue.js components, add the matestack folder to the asset paths:
136+
### Asset Pipeline
81137

82-
`config/initializers/assets.rb`
138+
When using the asset pipeline, add the matestack folder to the asset paths:
83139

84140
```ruby
141+
# config/initializers/assets.rb
85142
Rails.application.config.assets.paths << Rails.root.join('app/matestack/components')
86143
```
87144

spec/dummy/.babelrc

Lines changed: 0 additions & 18 deletions
This file was deleted.

spec/dummy/.postcssrc.yml

Lines changed: 0 additions & 3 deletions
This file was deleted.

spec/dummy/app/javascript/packs/application.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@
77
// To reference this file, add <%= javascript_pack_tag 'application' %> to the appropriate
88
// layout file, like app/views/layouts/application.html.erb
99

10+
import MatestackUiCore from 'matestack-ui-core'
11+
1012
console.log('Hello World from Webpacker')
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Dummy</title>
5+
<%= csrf_meta_tags %>
6+
<%= csp_meta_tag %>
7+
8+
<%= stylesheet_link_tag 'application', media: 'all' %>
9+
<%= javascript_pack_tag 'application' %>
10+
</head>
11+
12+
<body>
13+
<div id="matestack_ui">
14+
<%= yield %>
15+
</div>
16+
</body>
17+
</html>

spec/dummy/config/webpacker.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ default: &default
88

99
# Additional paths webpack should lookup modules
1010
# ['app/assets', 'engine/foo/app/assets']
11-
resolved_paths: []
11+
resolved_paths: ['node_modules']
1212

1313
# Reload manifest.json on all requests so we reload latest compiled packs
1414
cache_manifest: false

spec/dummy/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"name": "dummy",
33
"private": true,
44
"dependencies": {
5-
"@rails/webpacker": "4.2.2"
5+
"@rails/webpacker": "4.2.2",
6+
"matestack-ui-core": "../../"
67
},
78
"devDependencies": {
89
"webpack-dev-server": "^3.10.2"

0 commit comments

Comments
 (0)