Skip to content

Commit 22b6e6c

Browse files
committed
fixed vue:support bug, added slm support
1 parent 24a7e24 commit 22b6e6c

File tree

6 files changed

+63
-18
lines changed

6 files changed

+63
-18
lines changed

Gemfile.lock

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11
PATH
22
remote: .
33
specs:
4-
vue_cli-rails (0.2.0)
4+
vue_cli-rails (0.3.1)
55
activesupport (>= 4.2)
66
rack-proxy (>= 0.6)
77
railties (>= 4.2)
88

99
GEM
1010
remote: https://rubygems.org/
1111
specs:
12-
actionpack (5.2.2)
13-
actionview (= 5.2.2)
14-
activesupport (= 5.2.2)
12+
actionpack (5.2.2.1)
13+
actionview (= 5.2.2.1)
14+
activesupport (= 5.2.2.1)
1515
rack (~> 2.0)
1616
rack-test (>= 0.6.3)
1717
rails-dom-testing (~> 2.0)
1818
rails-html-sanitizer (~> 1.0, >= 1.0.2)
19-
actionview (5.2.2)
20-
activesupport (= 5.2.2)
19+
actionview (5.2.2.1)
20+
activesupport (= 5.2.2.1)
2121
builder (~> 3.1)
2222
erubi (~> 1.4)
2323
rails-dom-testing (~> 2.0)
2424
rails-html-sanitizer (~> 1.0, >= 1.0.3)
25-
activesupport (5.2.2)
25+
activesupport (5.2.2.1)
2626
concurrent-ruby (~> 1.0, >= 1.0.2)
2727
i18n (>= 0.7, < 2)
2828
minitest (~> 5.1)
2929
tzinfo (~> 1.1)
3030
builder (3.2.3)
3131
byebug (11.0.0)
3232
coderay (1.1.2)
33-
concurrent-ruby (1.1.4)
33+
concurrent-ruby (1.1.5)
3434
crass (1.0.4)
3535
diff-lcs (1.3)
3636
erubi (1.8.0)
@@ -60,9 +60,9 @@ GEM
6060
nokogiri (>= 1.6)
6161
rails-html-sanitizer (1.0.4)
6262
loofah (~> 2.2, >= 2.2.2)
63-
railties (5.2.2)
64-
actionpack (= 5.2.2)
65-
activesupport (= 5.2.2)
63+
railties (5.2.2.1)
64+
actionpack (= 5.2.2.1)
65+
activesupport (= 5.2.2.1)
6666
method_source
6767
rake (>= 0.8.7)
6868
thor (>= 0.19.0, < 2.0)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ Feel free to update `vue.config.js` by yourself. There are some lines of boiler-
347347

348348
- `vue:support[formats]`
349349

350-
Adds template or style language support. Vue ships with supporting `pug`, `sass`, `less` and `stylus` out-of-box. How ever, you still have to install some loaders manually if you did not select that language with `vue:create`.
350+
Adds template or style language support. Vue ships with supporting `pug`, `slm`, `sass`, `less` and `stylus` out-of-box. How ever, you still have to install some loaders manually if you did not select that language with `vue:create`.
351351

352352
You can add multiple languages at the same time: `rake vue:support[pug,stylus]`
353353

lib/helpers/scripts/vue_command.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ class VueCommand
55

66
SUPPORED_FORMATS = {
77
'pug' => %w[pug-plain-loader pug],
8+
'slm' => %w[slm-loader slm],
89
'sass' => SASS,
910
'scss' => SASS,
1011
'less' => %w[less-loader less],
@@ -62,7 +63,7 @@ def add_scripts(package_json, commands = {})
6263
end
6364

6465
def group_formats(formats)
65-
formats.each_with_object([[], []]) do |result, fmt|
66+
formats.each_with_object([[], []]) do |fmt, result|
6667
fmts = SUPPORED_FORMATS[fmt.downcase]
6768
if fmts
6869
result[0] += fmts

lib/source/vue.rails.js

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,57 @@
11
const { env } = require('process');
2+
const { readFileSync } = require('fs');
3+
const { resolve } = require('path');
24

35
module.exports = (() => {
46
let settings = {};
57
const assets = {};
8+
const slmModule = (() => {
9+
try {
10+
const packageJson = readFileSync(resolve(__dirname, 'package.json')) || '{}';
11+
const { dependencies, devDependencies } = JSON.parse(packageJson) || {};
12+
const deps = { ...dependencies, ...devDependencies };
13+
return !(deps.slm && deps['slm-loader']);
14+
} catch (_e) {
15+
return true;
16+
}
17+
})() ? {} : {
18+
module: {
19+
rules: [
20+
{
21+
test: /\.slm$/,
22+
oneOf: [
23+
{
24+
resourceQuery: /^\?vue/,
25+
use: [
26+
{
27+
loader: 'slm-loader',
28+
},
29+
],
30+
},
31+
{
32+
use: [
33+
{
34+
loader: 'raw-loader',
35+
},
36+
{
37+
loader: 'slm-loader',
38+
},
39+
],
40+
},
41+
],
42+
},
43+
],
44+
},
45+
};
646

747
try {
848
/* eslint-disable global-require,import/no-extraneous-dependencies */
949
const yaml = require('js-yaml');
10-
const { readFileSync, readdirSync, lstatSync } = require('fs');
11-
const { resolve } = require('path');
50+
const { readdirSync, lstatSync } = require('fs');
1251
/* eslint-enable global-require,import/no-extraneous-dependencies */
1352

1453
const railsEnv = env.RAILS_ENV || 'development';
15-
const config = yaml.safeLoad(readFileSync(resolve('config/vue.yml'), 'utf8'))[railsEnv];
54+
const config = yaml.safeLoad(readFileSync(resolve('config', 'vue.yml'), 'utf8'))[railsEnv];
1655
const root = resolve(__dirname);
1756
const pop = (config.public_output_path || 'vue_assets').replace(/(^\/+|\/+$)/g, '');
1857
const {
@@ -72,6 +111,7 @@ module.exports = (() => {
72111
[key]: resolve(root, alias[key]),
73112
}), {}),
74113
},
114+
...(slmModule || {}),
75115
},
76116

77117
jestModuleNameMapper: Object.keys(alias).reduce((obj, key) => ({
@@ -110,6 +150,10 @@ module.exports = (() => {
110150
cwd: __dirname,
111151
encoding: 'utf8',
112152
}));
153+
154+
if (slmModule) {
155+
Object.assign(settings.configureWebpack, slmModule);
156+
}
113157
}
114158

115159
const getSettingsFromKeys = keys => [].concat(keys).filter(s => s)

lib/tasks/vue.rake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace :vue do
55
VueCreate.run!
66
end
77

8-
desc 'Add template/style support: formats=pug,sass,less,stylus'
8+
desc 'Add template/style support: formats=pug,slm,sass,less,stylus'
99
task :support, [:formats] do |_t, args|
1010
require_relative '../helpers/scripts/vue_command'
1111
VueCommand.new.install_format_support(args.formats&.split(/\W/))

lib/vue_cli/rails/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module VueCli
22
module Rails
3-
VERSION = '0.3.0'.freeze
3+
VERSION = '0.3.1'.freeze
44
end
55
end

0 commit comments

Comments
 (0)