Include Webpack and use it for jQuery, Bootstrap and chosen.js

This commit is contained in:
Sebastian Serth
2018-10-07 23:53:16 +02:00
parent 9666683bd7
commit 4d1cf972e4
28 changed files with 7177 additions and 35 deletions

18
.babelrc Normal file
View File

@ -0,0 +1,18 @@
{
"presets": [
["env", {
"modules": false,
"targets": {
"browsers": "> 1%",
"uglify": true
},
"useBuiltIns": true
}]
],
"plugins": [
"syntax-dynamic-import",
"transform-object-rest-spread",
["transform-class-properties", { "spec": true }]
]
}

5
.gitignore vendored
View File

@ -25,3 +25,8 @@
*.iml *.iml
*.DS_Store *.DS_Store
/node_modules /node_modules
/public/packs
/public/packs-test
/node_modules
yarn-debug.log*
.yarn-integrity

3
.postcssrc.yml Normal file
View File

@ -0,0 +1,3 @@
plugins:
postcss-import: {}
postcss-cssnext: {}

View File

@ -3,6 +3,13 @@ sudo: required
services: services:
- docker - docker
language: ruby
rvm:
- 2.5.1
cache:
bundler: true
yarn: true
addons: addons:
code_climate: code_climate:
repo_token: repo_token:
@ -25,6 +32,10 @@ before_install:
- chmod +x ~/geckodriver/geckodriver - chmod +x ~/geckodriver/geckodriver
- export PATH=~/geckodriver/:$PATH - export PATH=~/geckodriver/:$PATH
install:
- bundle install --jobs=3 --retry=3 --deployment --path=${BUNDLE_PATH:-vendor/bundle}
- yarn install
before_script: before_script:
- cp .rspec.travis .rspec - cp .rspec.travis .rspec
- cp config/action_mailer.yml.travis config/action_mailer.yml - cp config/action_mailer.yml.travis config/action_mailer.yml
@ -36,9 +47,4 @@ before_script:
- psql --command='CREATE DATABASE travis_ci_test;' --username=postgres - psql --command='CREATE DATABASE travis_ci_test;' --username=postgres
- bundle exec rake db:schema:load RAILS_ENV=test - bundle exec rake db:schema:load RAILS_ENV=test
cache: bundler
language: ruby
rvm:
- 2.5.1
script: bundle exec rspec --color --format documentation --require spec_helper --require rails_helper && bundle exec codeclimate-test-reporter script: bundle exec rspec --color --format documentation --require spec_helper --require rails_helper && bundle exec codeclimate-test-reporter

View File

@ -23,7 +23,7 @@ gem 'ransack'
gem 'rubytree' gem 'rubytree'
gem 'sass-rails' gem 'sass-rails'
gem 'slim-rails' gem 'slim-rails'
gem 'bootstrap_pagedown' gem 'pagedown-bootstrap-rails'
gem 'sorcery' gem 'sorcery'
gem 'turbolinks' gem 'turbolinks'
gem 'uglifier' gem 'uglifier'
@ -31,6 +31,7 @@ gem 'tubesock', git: 'https://github.com/gosukiwi/tubesock', branch: 'patch-1' #
gem 'faye-websocket' gem 'faye-websocket'
gem 'nokogiri' gem 'nokogiri'
gem 'd3-rails' gem 'd3-rails'
gem 'webpacker'
gem 'rest-client' gem 'rest-client'
gem 'rubyzip' gem 'rubyzip'
gem 'mnemosyne-ruby' gem 'mnemosyne-ruby'

View File

@ -73,8 +73,6 @@ GEM
msgpack (~> 1.0) msgpack (~> 1.0)
bootstrap-will_paginate (1.0.0) bootstrap-will_paginate (1.0.0)
will_paginate will_paginate
bootstrap_pagedown (1.1.0)
rails (>= 3.2)
builder (3.2.3) builder (3.2.3)
bunny (2.12.0) bunny (2.12.0)
amq-protocol (~> 2.3, >= 2.3.0) amq-protocol (~> 2.3, >= 2.3.0)
@ -118,7 +116,7 @@ GEM
coderay (1.1.2) coderay (1.1.2)
concurrent-ruby (1.0.5) concurrent-ruby (1.0.5)
crass (1.0.4) crass (1.0.4)
d3-rails (5.5.0) d3-rails (5.7.0)
railties (>= 3.1) railties (>= 3.1)
database_cleaner (1.7.0) database_cleaner (1.7.0)
debug_inspector (0.0.3) debug_inspector (0.0.3)
@ -210,6 +208,8 @@ GEM
multi_json (~> 1.3) multi_json (~> 1.3)
multi_xml (~> 0.5) multi_xml (~> 0.5)
rack (>= 1.2, < 3) rack (>= 1.2, < 3)
pagedown-bootstrap-rails (2.1.4)
railties (> 3.1)
parallel (1.12.1) parallel (1.12.1)
parser (2.5.1.2) parser (2.5.1.2)
ast (~> 2.4.0) ast (~> 2.4.0)
@ -228,6 +228,8 @@ GEM
rack (2.0.5) rack (2.0.5)
rack-mini-profiler (1.0.0) rack-mini-profiler (1.0.0)
rack (>= 1.2.0) rack (>= 1.2.0)
rack-proxy (0.6.5)
rack
rack-test (1.1.0) rack-test (1.1.0)
rack (>= 1.0, < 3) rack (>= 1.0, < 3)
rails (5.2.1) rails (5.2.1)
@ -377,6 +379,10 @@ GEM
activemodel (>= 5.0) activemodel (>= 5.0)
bindex (>= 0.4.0) bindex (>= 0.4.0)
railties (>= 5.0) railties (>= 5.0)
webpacker (3.5.5)
activesupport (>= 4.2)
rack-proxy (>= 0.6.1)
railties (>= 4.2)
websocket (1.2.8) websocket (1.2.8)
websocket-driver (0.7.0) websocket-driver (0.7.0)
websocket-extensions (>= 0.1.0) websocket-extensions (>= 0.1.0)
@ -397,7 +403,6 @@ DEPENDENCIES
binding_of_caller binding_of_caller
bootsnap bootsnap
bootstrap-will_paginate bootstrap-will_paginate
bootstrap_pagedown
capistrano capistrano
capistrano-rails capistrano-rails
capistrano-rvm capistrano-rvm
@ -424,6 +429,7 @@ DEPENDENCIES
newrelic_rpm newrelic_rpm
nokogiri nokogiri
nyan-cat-formatter nyan-cat-formatter
pagedown-bootstrap-rails
pg pg
pry-byebug pry-byebug
puma puma
@ -450,6 +456,7 @@ DEPENDENCIES
turbolinks turbolinks
uglifier uglifier
web-console web-console
webpacker
whenever whenever
BUNDLED WITH BUNDLED WITH

1
Vagrantfile vendored
View File

@ -7,6 +7,7 @@ Vagrant.configure(2) do |config|
v.memory = 8192 v.memory = 8192
end end
config.vm.network "private_network", ip: "192.168.59.104" config.vm.network "private_network", ip: "192.168.59.104"
config.vm.network "forwarded_port", guest: 3035, host: 3035
# config.vm.synced_folder "../data", "/vagrant_data" # config.vm.synced_folder "../data", "/vagrant_data"
config.vm.provision "shell", path: "provision.sh", privileged: false config.vm.provision "shell", path: "provision.sh", privileged: false
end end

View File

@ -10,10 +10,9 @@
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
// about supported directives. // about supported directives.
// //
//= require jquery
//= require jquery_ujs //= require jquery_ujs
//= require turbolinks //= require turbolinks
//= require bootstrap_pagedown //= require pagedown_bootstrap
//= require d3 //= require d3
// //
// lib/assets // lib/assets
@ -24,8 +23,6 @@
//= require ace/ace //= require ace/ace
//= require ace/ext-language_tools //= require ace/ext-language_tools
//= require jstree/jstree.min //= require jstree/jstree.min
//= require bootstrap.min
//= require chosen.jquery.min
//= require jquery-ui.min //= require jquery-ui.min
//= require underscore.min //= require underscore.min
//= require_tree . //= require_tree .

View File

@ -10,14 +10,12 @@
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
* file per style scope. * file per style scope.
* *
*= require bootstrap_pagedown *= require pagedown_bootstrap
* *
* lib/assets * lib/assets
*= require flash *= require flash
* *
* vendor/assets * vendor/assets
*= require bootstrap.min
*= require chosen.min
*= require font-awesome.min *= require font-awesome.min
*= require google_opensans *= require google_opensans
*= require jquery-ui.min *= require jquery-ui.min

View File

@ -0,0 +1,16 @@
/* eslint no-console:0 */
// This file is automatically compiled by Webpack, along with any other files
// present in this directory. You're encouraged to place your actual application logic in
// a relevant structure within app/javascript and only use these pack files to reference
// that code so it'll be compiled.
//
// To reference this file, add <%= javascript_pack_tag 'application' %> to the appropriate
// layout file, like app/views/layouts/application.html.slim
// JS
import 'jquery'
import 'bootstrap/dist/js/bootstrap.bundle.min';
import 'chosen-js/chosen.jquery';
// CSS
import 'chosen-js/chosen.css';

View File

@ -0,0 +1,12 @@
/* eslint no-console:0 */
// This file is automatically compiled by Webpack, along with any other files
// present in this directory. You're encouraged to place your actual application logic in
// a relevant structure within app/javascript and only use these pack files to reference
// that code so it'll be compiled.
//
// To reference this file, add <%= stylesheet_pack_tag 'stylesheets' %> to the appropriate
// layout file, like app/views/layouts/application.html.slim
@import '~bootswatch/dist/yeti/variables';
@import '~bootstrap/scss/bootstrap';
@import '~bootswatch/dist/yeti/bootswatch';

View File

@ -5,8 +5,11 @@ html lang='en'
meta name='viewport' content='width=device-width, initial-scale=1' meta name='viewport' content='width=device-width, initial-scale=1'
title = application_name title = application_name
link href=asset_path('favicon.png') rel='icon' type='image/png' link href=asset_path('favicon.png') rel='icon' type='image/png'
= stylesheet_link_tag('application', media: 'all', 'data-turbolinks-track' => true) = stylesheet_pack_tag('application', media: 'all', 'data-turbolinks-track': true)
= javascript_include_tag('application', 'data-turbolinks-track' => true) = stylesheet_pack_tag('stylesheets', media: 'all', 'data-turbolinks-track': true)
= stylesheet_link_tag('application', media: 'all', 'data-turbolinks-track': true)
= javascript_pack_tag('application', 'data-turbolinks-track': true)
= javascript_include_tag('application', 'data-turbolinks-track': true)
= yield(:head) = yield(:head)
= csrf_meta_tags = csrf_meta_tags
body body

15
bin/webpack Executable file
View File

@ -0,0 +1,15 @@
#!/usr/bin/env ruby
ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
ENV["NODE_ENV"] ||= "development"
require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)
require "rubygems"
require "bundler/setup"
require "webpacker"
require "webpacker/webpack_runner"
Webpacker::WebpackRunner.run(ARGV)

15
bin/webpack-dev-server Executable file
View File

@ -0,0 +1,15 @@
#!/usr/bin/env ruby
ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
ENV["NODE_ENV"] ||= "development"
require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)
require "rubygems"
require "bundler/setup"
require "webpacker"
require "webpacker/dev_server_runner"
Webpacker::DevServerRunner.run(ARGV)

View File

@ -1,4 +1,6 @@
Rails.application.configure do Rails.application.configure do
# Verifies that versions and hashed value of the package contents in the project's package.json
config.webpacker.check_yarn_integrity = true
# Settings specified here will take precedence over those in config/application.rb. # Settings specified here will take precedence over those in config/application.rb.
config.web_console.whitelisted_ips = '192.168.0.0/16' config.web_console.whitelisted_ips = '192.168.0.0/16'

View File

@ -1,4 +1,6 @@
Rails.application.configure do Rails.application.configure do
# Verifies that versions and hashed value of the package contents in the project's package.json
config.webpacker.check_yarn_integrity = false
# Settings specified here will take precedence over those in config/application.rb. # Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests. # Code is not reloaded between requests.

View File

@ -11,7 +11,7 @@ Rails.application.config.tap do |config|
# Highlight.js # Highlight.js
config.assets.precompile += %w( highlight.min.js ) config.assets.precompile += %w( highlight.min.js )
config.assets.precompile += %w( highlight-default.min.css ) config.assets.precompile += %w( highlight-default.css )
# d3.tip # d3.tip
config.assets.precompile += %w( d3-tip.js ) config.assets.precompile += %w( d3-tip.js )
@ -19,7 +19,7 @@ Rails.application.config.tap do |config|
# Add additional assets to the asset load path. # Add additional assets to the asset load path.
# config.assets.paths << Emoji.images_path # config.assets.paths << Emoji.images_path
# Add Yarn node_modules folder to the asset load path. # Add Yarn node_modules folder to the asset load path.
# config.assets.paths << Rails.root.join('node_modules') config.assets.paths << Rails.root.join('node_modules')
# Precompile additional assets. # Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in the app/assets # application.js, application.css, and all non-JS/CSS in the app/assets

View File

@ -0,0 +1,5 @@
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
const environment = require('./environment');
module.exports = environment;

View File

@ -0,0 +1,30 @@
/*
./config/webpack/environment.js
Info for this file can be found
github.com/rails/webpacker/blob/master/docs/webpack.md
*/
const { environment } = require('@rails/webpacker');
const merge = require('webpack-merge');
const webpack = require('webpack');
// Add an additional plugin of your choosing : ProvidePlugin
environment.plugins.prepend('Provide', new webpack.ProvidePlugin({
$: 'jquery',
JQuery: 'jquery',
jquery: 'jquery',
'window.Tether': "tether",
Popper: ['popper.js', 'default'], // for Bootstrap 4
})
);
const envConfig = module.exports = environment;
const aliasConfig = module.exports = {
resolve: {
alias: {
jquery: 'jquery/src/jquery'
}
}
};
module.exports = merge(envConfig.toWebpackConfig(), aliasConfig);

View File

@ -0,0 +1,5 @@
process.env.NODE_ENV = process.env.NODE_ENV || 'production';
const environment = require('./environment');
module.exports = environment;

5
config/webpack/test.js Normal file
View File

@ -0,0 +1,5 @@
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
const environment = require('./environment');
module.exports = environment;

70
config/webpacker.yml Normal file
View File

@ -0,0 +1,70 @@
# Note: You must restart bin/webpack-dev-server for changes to take effect
default: &default
source_path: app/javascript
source_entry_path: packs
public_output_path: packs
cache_path: tmp/cache/webpacker
# Additional paths webpack should lookup modules
# ['app/assets', 'engine/foo/app/assets']
resolved_paths: []
# Reload manifest.json on all requests so we reload latest compiled packs
cache_manifest: false
extensions:
- .js
- .sass
- .scss
- .css
- .module.sass
- .module.scss
- .module.css
- .png
- .svg
- .gif
- .jpeg
- .jpg
development:
<<: *default
compile: true
# Reference: https://webpack.js.org/configuration/dev-server/
dev_server:
https: false
host: 0.0.0.0
port: 3035
public: 0.0.0.0:3035
hmr: false
# Inline should be set to true if using HMR
inline: true
overlay: true
compress: true
disable_host_check: true
use_local_ip: false
quiet: false
headers:
'Access-Control-Allow-Origin': '*'
watch_options:
ignored: /node_modules/
# File Watcher might not work inside Vagrant
poll: true
test:
<<: *default
compile: true
# Compile test packs to a separate directory
public_output_path: packs-test
production:
<<: *default
# Production depends on precompilation of packs prior to booting for performance.
compile: false
# Cache manifest.json for performance
cache_manifest: true

18
package.json Normal file
View File

@ -0,0 +1,18 @@
{
"dependencies": {
"@rails/webpacker": "3.5",
"bootstrap": "^4.1.3",
"bootswatch": "^4.1.3",
"chosen-js": "^1.8.7",
"jquery": "^3.3.1",
"popper.js": "^1.14.4",
"webpack-merge": "^4.1.4"
},
"devDependencies": {
"webpack-dev-server": "2.11.2"
},
"scripts": {
"webpack": "./bin/webpack",
"webpack-dev-server": "./bin/webpack-dev-server"
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 538 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 738 B

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

6922
yarn.lock

File diff suppressed because it is too large Load Diff