Skip to content

Commit

Permalink
fixed vue:support bug, added slm support
Browse files Browse the repository at this point in the history
  • Loading branch information
eGust committed Mar 16, 2019
1 parent 24a7e24 commit 22b6e6c
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 18 deletions.
22 changes: 11 additions & 11 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
PATH
remote: .
specs:
vue_cli-rails (0.2.0)
vue_cli-rails (0.3.1)
activesupport (>= 4.2)
rack-proxy (>= 0.6)
railties (>= 4.2)

GEM
remote: https://rubygems.org/
specs:
actionpack (5.2.2)
actionview (= 5.2.2)
activesupport (= 5.2.2)
actionpack (5.2.2.1)
actionview (= 5.2.2.1)
activesupport (= 5.2.2.1)
rack (~> 2.0)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (5.2.2)
activesupport (= 5.2.2)
actionview (5.2.2.1)
activesupport (= 5.2.2.1)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.3)
activesupport (5.2.2)
activesupport (5.2.2.1)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
builder (3.2.3)
byebug (11.0.0)
coderay (1.1.2)
concurrent-ruby (1.1.4)
concurrent-ruby (1.1.5)
crass (1.0.4)
diff-lcs (1.3)
erubi (1.8.0)
Expand Down Expand Up @@ -60,9 +60,9 @@ GEM
nokogiri (>= 1.6)
rails-html-sanitizer (1.0.4)
loofah (~> 2.2, >= 2.2.2)
railties (5.2.2)
actionpack (= 5.2.2)
activesupport (= 5.2.2)
railties (5.2.2.1)
actionpack (= 5.2.2.1)
activesupport (= 5.2.2.1)
method_source
rake (>= 0.8.7)
thor (>= 0.19.0, < 2.0)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ Feel free to update `vue.config.js` by yourself. There are some lines of boiler-

- `vue:support[formats]`

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`.
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`.

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

Expand Down
3 changes: 2 additions & 1 deletion lib/helpers/scripts/vue_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class VueCommand

SUPPORED_FORMATS = {
'pug' => %w[pug-plain-loader pug],
'slm' => %w[slm-loader slm],
'sass' => SASS,
'scss' => SASS,
'less' => %w[less-loader less],
Expand Down Expand Up @@ -62,7 +63,7 @@ def add_scripts(package_json, commands = {})
end

def group_formats(formats)
formats.each_with_object([[], []]) do |result, fmt|
formats.each_with_object([[], []]) do |fmt, result|
fmts = SUPPORED_FORMATS[fmt.downcase]
if fmts
result[0] += fmts
Expand Down
50 changes: 47 additions & 3 deletions lib/source/vue.rails.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,57 @@
const { env } = require('process');
const { readFileSync } = require('fs');
const { resolve } = require('path');

module.exports = (() => {
let settings = {};
const assets = {};
const slmModule = (() => {
try {
const packageJson = readFileSync(resolve(__dirname, 'package.json')) || '{}';
const { dependencies, devDependencies } = JSON.parse(packageJson) || {};
const deps = { ...dependencies, ...devDependencies };
return !(deps.slm && deps['slm-loader']);
} catch (_e) {
return true;
}
})() ? {} : {
module: {
rules: [
{
test: /\.slm$/,
oneOf: [
{
resourceQuery: /^\?vue/,
use: [
{
loader: 'slm-loader',
},
],
},
{
use: [
{
loader: 'raw-loader',
},
{
loader: 'slm-loader',
},
],
},
],
},
],
},
};

try {
/* eslint-disable global-require,import/no-extraneous-dependencies */
const yaml = require('js-yaml');
const { readFileSync, readdirSync, lstatSync } = require('fs');
const { resolve } = require('path');
const { readdirSync, lstatSync } = require('fs');
/* eslint-enable global-require,import/no-extraneous-dependencies */

const railsEnv = env.RAILS_ENV || 'development';
const config = yaml.safeLoad(readFileSync(resolve('config/vue.yml'), 'utf8'))[railsEnv];
const config = yaml.safeLoad(readFileSync(resolve('config', 'vue.yml'), 'utf8'))[railsEnv];
const root = resolve(__dirname);
const pop = (config.public_output_path || 'vue_assets').replace(/(^\/+|\/+$)/g, '');
const {
Expand Down Expand Up @@ -72,6 +111,7 @@ module.exports = (() => {
[key]: resolve(root, alias[key]),
}), {}),
},
...(slmModule || {}),
},

jestModuleNameMapper: Object.keys(alias).reduce((obj, key) => ({
Expand Down Expand Up @@ -110,6 +150,10 @@ module.exports = (() => {
cwd: __dirname,
encoding: 'utf8',
}));

if (slmModule) {
Object.assign(settings.configureWebpack, slmModule);
}
}

const getSettingsFromKeys = keys => [].concat(keys).filter(s => s)
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/vue.rake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace :vue do
VueCreate.run!
end

desc 'Add template/style support: formats=pug,sass,less,stylus'
desc 'Add template/style support: formats=pug,slm,sass,less,stylus'
task :support, [:formats] do |_t, args|
require_relative '../helpers/scripts/vue_command'
VueCommand.new.install_format_support(args.formats&.split(/\W/))
Expand Down
2 changes: 1 addition & 1 deletion lib/vue_cli/rails/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module VueCli
module Rails
VERSION = '0.3.0'.freeze
VERSION = '0.3.1'.freeze
end
end

0 comments on commit 22b6e6c

Please sign in to comment.