forked from swrobel/meta-surf-forecast
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert javascript from sprockets to webpacker
- Loading branch information
Showing
31 changed files
with
5,636 additions
and
431 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"presets": [ | ||
["env", { | ||
"modules": false, | ||
"targets": { | ||
"browsers": "> 1%", | ||
"uglify": true | ||
}, | ||
"useBuiltIns": true | ||
}] | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,3 +18,5 @@ | |
|
||
.env* | ||
!invoker.ini | ||
/public/packs | ||
/node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
plugins: | ||
postcss-smart-import: {} | ||
precss: {} | ||
autoprefixer: {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const Highcharts = require('highcharts') | ||
window.Highcharts = Highcharts | ||
|
||
const Chartkick = require('chartkick') | ||
window.Chartkick = Chartkick |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/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__) | ||
NODE_MODULES_PATH = File.join(APP_PATH, "node_modules") | ||
WEBPACK_CONFIG = File.join(APP_PATH, "config/webpack/#{NODE_ENV}.js") | ||
|
||
unless File.exist?(WEBPACK_CONFIG) | ||
puts "Webpack configuration not found." | ||
puts "Please run bundle exec rails webpacker:install to install webpacker" | ||
exit! | ||
end | ||
|
||
newenv = { "NODE_PATH" => NODE_MODULES_PATH.shellescape } | ||
cmdline = ["yarn", "run", "webpack", "--", "--config", WEBPACK_CONFIG] + ARGV | ||
|
||
Dir.chdir(APP_PATH) do | ||
exec newenv, *cmdline | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/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_FILE = File.join(APP_PATH, "config/webpacker.yml") | ||
NODE_MODULES_PATH = File.join(APP_PATH, "node_modules") | ||
WEBPACK_CONFIG = File.join(APP_PATH, "config/webpack/development.js") | ||
|
||
def args(key) | ||
index = ARGV.index(key) | ||
index ? ARGV[index + 1] : nil | ||
end | ||
|
||
begin | ||
dev_server = YAML.load_file(CONFIG_FILE)["development"]["dev_server"] | ||
|
||
DEV_SERVER_HOST = "http#{"s" if args('--https') || dev_server["https"]}://#{args('--host') || dev_server["host"]}:#{args('--port') || dev_server["port"]}" | ||
|
||
rescue Errno::ENOENT, NoMethodError | ||
puts "Webpack dev_server configuration not found in #{CONFIG_FILE}." | ||
puts "Please run bundle exec rails webpacker:install to install webpacker" | ||
exit! | ||
end | ||
|
||
newenv = { | ||
"NODE_PATH" => NODE_MODULES_PATH.shellescape, | ||
"ASSET_HOST" => DEV_SERVER_HOST.shellescape | ||
}.freeze | ||
|
||
cmdline = ["yarn", "run", "webpack-dev-server", "--", "--progress", "--color", "--config", WEBPACK_CONFIG] + ARGV | ||
|
||
Dir.chdir(APP_PATH) do | ||
exec newenv, *cmdline | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/usr/bin/env ruby | ||
VENDOR_PATH = File.expand_path('..', __dir__) | ||
Dir.chdir(VENDOR_PATH) do | ||
begin | ||
exec "yarnpkg #{ARGV.join(" ")}" | ||
rescue Errno::ENOENT | ||
$stderr.puts "Yarn executable was not detected in the system." | ||
$stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install" | ||
exit 1 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Common configuration for webpacker loaded from config/webpacker.yml | ||
|
||
const { join, resolve } = require('path') | ||
const { env } = require('process') | ||
const { safeLoad } = require('js-yaml') | ||
const { readFileSync } = require('fs') | ||
|
||
const configPath = resolve('config', 'webpacker.yml') | ||
const loadersDir = join(__dirname, 'loaders') | ||
const settings = safeLoad(readFileSync(configPath), 'utf8')[env.NODE_ENV] | ||
|
||
function removeOuterSlashes(string) { | ||
return string.replace(/^\/*/, '').replace(/\/*$/, '') | ||
} | ||
|
||
function formatPublicPath(host = '', path = '') { | ||
let formattedHost = removeOuterSlashes(host) | ||
if (formattedHost && !/^http/i.test(formattedHost)) { | ||
formattedHost = `//${formattedHost}` | ||
} | ||
const formattedPath = removeOuterSlashes(path) | ||
return `${formattedHost}/${formattedPath}/` | ||
} | ||
|
||
const output = { | ||
path: resolve('public', settings.public_output_path), | ||
publicPath: formatPublicPath(env.ASSET_HOST, settings.public_output_path) | ||
} | ||
|
||
module.exports = { | ||
settings, | ||
env, | ||
loadersDir, | ||
output | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Note: You must restart bin/webpack-dev-server for changes to take effect | ||
|
||
const merge = require('webpack-merge') | ||
const sharedConfig = require('./shared.js') | ||
const { settings, output } = require('./configuration.js') | ||
|
||
module.exports = merge(sharedConfig, { | ||
devtool: 'cheap-eval-source-map', | ||
|
||
stats: { | ||
errorDetails: true | ||
}, | ||
|
||
output: { | ||
pathinfo: true | ||
}, | ||
|
||
devServer: { | ||
clientLogLevel: 'none', | ||
https: settings.dev_server.https, | ||
host: settings.dev_server.host, | ||
port: settings.dev_server.port, | ||
contentBase: output.path, | ||
publicPath: output.publicPath, | ||
compress: true, | ||
headers: { 'Access-Control-Allow-Origin': '*' }, | ||
historyApiFallback: true, | ||
watchOptions: { | ||
ignored: /node_modules/ | ||
} | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const { env, publicPath } = require('../configuration.js') | ||
|
||
module.exports = { | ||
test: /\.(jpg|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]' | ||
} | ||
}] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
test: /\.js(\.erb)?$/, | ||
exclude: /node_modules/, | ||
loader: 'babel-loader' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
test: /\.coffee(\.erb)?$/, | ||
loader: 'coffee-loader' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: 'bin/rails runner' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const ExtractTextPlugin = require('extract-text-webpack-plugin') | ||
const { env } = require('../configuration.js') | ||
|
||
module.exports = { | ||
test: /\.(scss|sass|css)$/i, | ||
use: ExtractTextPlugin.extract({ | ||
fallback: 'style-loader', | ||
use: [ | ||
{ loader: 'css-loader', options: { minimize: env.NODE_ENV === 'production' } }, | ||
{ loader: 'postcss-loader', options: { sourceMap: true } }, | ||
'resolve-url-loader', | ||
{ loader: 'sass-loader', options: { sourceMap: true } } | ||
] | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Note: You must restart bin/webpack-dev-server for changes to take effect | ||
|
||
/* eslint global-require: 0 */ | ||
|
||
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|html|json|ico|svg|eot|otf|ttf)$/ | ||
}) | ||
] | ||
}) |
Oops, something went wrong.