Skip to content

Commit

Permalink
Add webpacker, move to ui-classic
Browse files Browse the repository at this point in the history
This is the result of `rake webpacker:install` and `webpacker:install:angular`, except moved to ui-classic.

(This does not add bin/yarn, nor the rake tasks by itself)
  • Loading branch information
himdel committed Aug 3, 2017
1 parent b4434ff commit 48e9dde
Show file tree
Hide file tree
Showing 26 changed files with 409 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .postcssrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
plugins:
postcss-smart-import: {}
precss: {}
autoprefixer: {}
9 changes: 9 additions & 0 deletions app/javascript/hello_angular/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Component } from '@angular/core';

@Component({
selector: 'hello-angular',
template: `<h1>Hello {{name}}</h1>`
})
export class AppComponent {
name = 'Angular!';
}
16 changes: 16 additions & 0 deletions app/javascript/hello_angular/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';

@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
6 changes: 6 additions & 0 deletions app/javascript/hello_angular/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import './polyfills.ts';

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';

platformBrowserDynamic().bootstrapModule(AppModule);
19 changes: 19 additions & 0 deletions app/javascript/hello_angular/polyfills.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// This file includes polyfills needed by Angular and is loaded before
// the app. You can add your own extra polyfills to this file.
import 'core-js/es6/symbol';
import 'core-js/es6/object';
import 'core-js/es6/function';
import 'core-js/es6/parse-int';
import 'core-js/es6/parse-float';
import 'core-js/es6/number';
import 'core-js/es6/math';
import 'core-js/es6/string';
import 'core-js/es6/date';
import 'core-js/es6/array';
import 'core-js/es6/regexp';
import 'core-js/es6/map';
import 'core-js/es6/set';
import 'core-js/es6/reflect';

import 'core-js/es7/reflect';
import 'zone.js/dist/zone';
10 changes: 10 additions & 0 deletions app/javascript/packs/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* 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.erb

console.log('Hello World from Webpacker')
7 changes: 7 additions & 0 deletions app/javascript/packs/hello_angular.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Run this Angular example by adding the following HTML markup to your view:
//
// <hello-angular>Loading...</hello-angular>
//
// <%= javascript_pack_tag 'hello_angular' %>

require('../hello_angular')
40 changes: 40 additions & 0 deletions bin/webpack
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env ruby
$stdout.sync = true

require "shellwords"
require "yaml"

ENV["RAILS_ENV"] ||= "development"
RAILS_ENV = ENV["RAILS_ENV"]

ENV["NODE_ENV"] ||= RAILS_ENV
NODE_ENV = ENV["NODE_ENV"]

APP_PATH = File.expand_path("../", __dir__)
CONFIG_PATH = File.join(APP_PATH, "config/webpack/paths.yml")
DEV_SERVER_CONFIG_PATH = File.join(APP_PATH, "config/webpack/development.server.yml")

begin
paths = YAML.load(File.read(CONFIG_PATH))
dev_server = YAML.load(File.read(DEV_SERVER_CONFIG_PATH))

NODE_MODULES_PATH = File.join(APP_PATH.shellescape, paths["node_modules"])
WEBPACK_CONFIG_PATH = File.join(APP_PATH.shellescape, paths["config"])

if NODE_ENV == "development" && dev_server["enabled"]
puts "Warning: webpack-dev-server is currently enabled in #{DEV_SERVER_CONFIG_PATH}. " \
"Disable to serve assets directly from public/packs directory"
end
rescue Errno::ENOENT, NoMethodError
puts "Configuration not found in config/webpack/paths.yml or config/webpack/development.server.yml."
puts "Please run bundle exec rails webpacker:install to install webpacker"
exit!
end

WEBPACK_BIN = "#{NODE_MODULES_PATH}/.bin/webpack"
WEBPACK_CONFIG = "#{WEBPACK_CONFIG_PATH}/#{NODE_ENV}.js"

Dir.chdir(APP_PATH) do
exec "NODE_PATH=#{NODE_MODULES_PATH} #{WEBPACK_BIN} --config #{WEBPACK_CONFIG}" \
" #{ARGV.join(" ")}"
end
33 changes: 33 additions & 0 deletions bin/webpack-dev-server
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env ruby
$stdout.sync = true

require "shellwords"
require "yaml"

ENV["RAILS_ENV"] ||= "development"
RAILS_ENV = ENV["RAILS_ENV"]

ENV["NODE_ENV"] ||= RAILS_ENV
NODE_ENV = ENV["NODE_ENV"]

APP_PATH = File.expand_path("../", __dir__)
CONFIG_PATH = File.join(APP_PATH, "config/webpack/paths.yml")

begin
paths = YAML.load(File.read(CONFIG_PATH))

NODE_MODULES_PATH = File.join(APP_PATH.shellescape, paths["node_modules"])
WEBPACK_CONFIG_PATH = File.join(APP_PATH.shellescape, paths["config"])

WEBPACK_BIN = "#{NODE_MODULES_PATH}/.bin/webpack-dev-server"
DEV_SERVER_CONFIG = "#{WEBPACK_CONFIG_PATH}/development.server.js"
rescue Errno::ENOENT, NoMethodError
puts "Configuration not found in config/webpacker/paths.yml."
puts "Please run bundle exec rails webpacker:install to install webpacker"
exit!
end

Dir.chdir(APP_PATH) do
exec "NODE_PATH=#{NODE_MODULES_PATH} #{WEBPACK_BIN} --progress --color " \
"--config #{DEV_SERVER_CONFIG}"
end
10 changes: 10 additions & 0 deletions bin/webpack-watcher
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env ruby

ENV['RAILS_ENV'] ||= 'development'
ENV['NODE_ENV'] ||= ENV['RAILS_ENV']

BIN_PATH = File.expand_path('.', __dir__)

Dir.chdir(BIN_PATH) do
exec "./webpack --watch --progress --color #{ARGV.join(" ")}"
end
21 changes: 21 additions & 0 deletions config/webpack/configuration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Common configuration for webpacker loaded from config/webpack/paths.yml

const { join, resolve } = require('path')
const { env } = require('process')
const { safeLoad } = require('js-yaml')
const { readFileSync } = require('fs')

const configPath = resolve('config', 'webpack')
const loadersDir = join(__dirname, 'loaders')
const paths = safeLoad(readFileSync(join(configPath, 'paths.yml'), 'utf8'))
const devServer = safeLoad(readFileSync(join(configPath, 'development.server.yml'), 'utf8'))
const publicPath = env.NODE_ENV !== 'production' && devServer.enabled ?
`http://${devServer.host}:${devServer.port}/` : `/${paths.entry}/`

module.exports = {
devServer,
env,
paths,
loadersDir,
publicPath
}
16 changes: 16 additions & 0 deletions config/webpack/development.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Note: You must restart bin/webpack-watcher for changes to take effect

const merge = require('webpack-merge')
const sharedConfig = require('./shared.js')

module.exports = merge(sharedConfig, {
devtool: 'sourcemap',

stats: {
errorDetails: true
},

output: {
pathinfo: true
}
})
17 changes: 17 additions & 0 deletions config/webpack/development.server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Note: You must restart bin/webpack-dev-server for changes to take effect

const { resolve } = require('path')
const merge = require('webpack-merge')
const devConfig = require('./development.js')
const { devServer, publicPath, paths } = require('./configuration.js')

module.exports = merge(devConfig, {
devServer: {
host: devServer.host,
port: devServer.port,
compress: true,
historyApiFallback: true,
contentBase: resolve(paths.output, paths.entry),
publicPath
}
})
4 changes: 4 additions & 0 deletions config/webpack/development.server.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Restart webpack-dev-server if you make changes here
enabled: true
host: localhost
port: 8080
4 changes: 4 additions & 0 deletions config/webpack/loaders/angular.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
test: /.ts$/,
loader: 'ts-loader'
}
12 changes: 12 additions & 0 deletions config/webpack/loaders/assets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const { env, publicPath } = require('../configuration.js')

module.exports = {
test: /\.(jpeg|png|gif|svg|eot|ttf|woff|woff2)$/i,
use: [{
loader: 'file-loader',
options: {
publicPath,
name: env.NODE_ENV === 'production' ? '[name]-[hash].[ext]' : '[name].[ext]'
}
}]
}
10 changes: 10 additions & 0 deletions config/webpack/loaders/babel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
test: /\.js(\.erb)?$/,
exclude: /node_modules/,
loader: 'babel-loader',
options: {
presets: [
['env', { modules: false }]
]
}
}
4 changes: 4 additions & 0 deletions config/webpack/loaders/coffee.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
test: /\.coffee(\.erb)?$/,
loader: 'coffee-loader'
}
9 changes: 9 additions & 0 deletions config/webpack/loaders/erb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
test: /\.erb$/,
enforce: 'pre',
exclude: /node_modules/,
loader: 'rails-erb-loader',
options: {
runner: 'DISABLE_SPRING=1 bin/rails runner'
}
}
9 changes: 9 additions & 0 deletions config/webpack/loaders/sass.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const ExtractTextPlugin = require('extract-text-webpack-plugin')

module.exports = {
test: /\.(scss|sass|css)$/i,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: ['css-loader', 'postcss-loader', 'sass-loader']
})
}
19 changes: 19 additions & 0 deletions config/webpack/paths.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Restart webpack-watcher or webpack-dev-server if you make changes here
config: config/webpack
entry: packs
output: public
node_modules: node_modules
source: app/javascript
extensions:
- .coffee
- .js
- .jsx
- .ts
- .vue
- .sass
- .scss
- .css
- .png
- .svg
- .gif
- .jpeg
20 changes: 20 additions & 0 deletions config/webpack/production.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* eslint global-require: 0 */
// Note: You must run bin/webpack for changes to take effect

const webpack = require('webpack')
const merge = require('webpack-merge')
const CompressionPlugin = require('compression-webpack-plugin')
const sharedConfig = require('./shared.js')

module.exports = merge(sharedConfig, {
output: { filename: '[name]-[chunkhash].js' },

plugins: [
new webpack.optimize.UglifyJsPlugin(),
new CompressionPlugin({
asset: '[path].gz[query]',
algorithm: 'gzip',
test: /\.(js|css|svg|eot|ttf|woff|woff2)$/
})
]
})
51 changes: 51 additions & 0 deletions config/webpack/shared.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Note: You must restart bin/webpack-watcher for changes to take effect
/* eslint global-require: 0 */
/* eslint import/no-dynamic-require: 0 */

const webpack = require('webpack')
const { basename, join, resolve } = require('path')
const { sync } = require('glob')
const { readdirSync } = require('fs')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const ManifestPlugin = require('webpack-manifest-plugin')
const extname = require('path-complete-extname')
const { env, paths, publicPath, loadersDir } = require('./configuration.js')

const extensionGlob = `*{${paths.extensions.join(',')}}*`
const packPaths = sync(join(paths.source, paths.entry, extensionGlob))

module.exports = {
entry: packPaths.reduce(
(map, entry) => {
const localMap = map
localMap[basename(entry, extname(entry))] = resolve(entry)
return localMap
}, {}
),

output: { filename: '[name].js', path: resolve(paths.output, paths.entry) },

module: {
rules: readdirSync(loadersDir).map(file => (
require(join(loadersDir, file))
))
},

plugins: [
new webpack.EnvironmentPlugin(JSON.parse(JSON.stringify(env))),
new ExtractTextPlugin(env.NODE_ENV === 'production' ? '[name]-[hash].css' : '[name].css'),
new ManifestPlugin({ fileName: 'manifest.json', publicPath, writeToFileEmit: true })
],

resolve: {
extensions: paths.extensions,
modules: [
resolve(paths.source),
resolve(paths.node_modules)
]
},

resolveLoader: {
modules: [paths.node_modules]
}
}
7 changes: 4 additions & 3 deletions manageiq-ui-classic.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ Gem::Specification.new do |s|
s.add_dependency "rails", "~> 5.0.0", ">= 5.0.0.1"

s.add_dependency "coffee-rails"
s.add_dependency "high_voltage", "~> 3.0.0"
s.add_dependency "jquery-hotkeys-rails"
s.add_dependency "lodash-rails", "~>3.10.0"
s.add_dependency "more_core_extensions", "~>3.2"
s.add_dependency "novnc-rails", "~>0.2"
s.add_dependency "patternfly-sass", "~> 3.23.1"
s.add_dependency "sass-rails"
s.add_dependency "high_voltage", "~> 3.0.0"
s.add_dependency "novnc-rails", "~>0.2"
s.add_dependency "uglifier", "~>3.0.0"
s.add_dependency "uglifier", "~>3.0.0"
s.add_dependency "webpacker", "~>1.2.0"

s.add_development_dependency "codeclimate-test-reporter", "~> 1.0.0"
s.add_development_dependency "guard-rspec", '~> 4.7.3'
Expand Down
Loading

0 comments on commit 48e9dde

Please sign in to comment.