add webpack config for dashboard static view

pull/12784/head
Carlos Matallín 7 years ago
parent 1de75d070a
commit 23e26e6f65

1
.gitignore vendored

@ -15,6 +15,7 @@ public/stylesheets
public/images
public/fonts
public/flash
public/static
app/assets/stylesheets/tmp/
app/assets/fonts/icon_font/svgs
db/schema.rb

@ -58,7 +58,9 @@ class Admin::VisualizationsController < Admin::AdminController
skip_before_filter :verify_authenticity_token, only: [:show_protected_public_map, :show_protected_embed_map]
def index
@first_time = !current_user.dashboard_viewed?
return render(file: "public/static/dashboard/index.html", layout: false) if current_user.has_feature_flag?('static_frontend')
@first_time = !current_user.dashboard_viewed?
@just_logged_in = !!flash['logged']
@google_maps_query_string = current_user.google_maps_query_string

@ -0,0 +1,11 @@
# coding: UTF-8
class StaticController < ApplicationController
layout false
ssl_allowed :index
def index
render :file => 'public/static/dashboard/index.html'
end
end

@ -0,0 +1,70 @@
const Carto = require('../carto-node/index');
const PACKAGE = require('../../../../package.json');
const version = PACKAGE.version;
window.StaticConfig = window.StaticConfig || {};
window.CartoConfig = window.CartoConfig || {};
(function (window, document) {
var client = new Carto.AuthenticatedClient();
function getAssetsVersion () {
var query = window.location.search.substring(1);
var vars = query.split('&');
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split('=');
if (pair[0] === 'v') {
return pair[1];
}
}
return window.StaticConfig.assetVersion || window.CartoConfig.data.user_frontend_version || version;
}
function getAssetsBaseUrl () {
var data = window.CartoConfig.data;
var userAssetsHost = data.asset_host;
return (window.StaticConfig.assetsBaseUrl || userAssetsHost && userAssetsHost + '/assets' || data.config.app_assets_base_url) + '/';
}
client.getConfig(function (err, response, data) {
window.CartoConfig.data = data;
if (err) {
console.error('Error getting the config:\n', err);
} else {
if (response.statusCode !== 200) {
window.location.href = '/login';
}
var assetsUrl = getAssetsBaseUrl() + getAssetsVersion();
(function (w, d, a, favicon, stylesheets, scripts, l, h, s, t) {
l = d.createElement('link');
l.rel = 'shortcut icon';
l.href = a + favicon;
h = d.getElementsByTagName('head')[0];
h.parentNode.insertBefore(l, h);
stylesheets.forEach(function (src) {
l = d.createElement('link');
l.rel = 'stylesheet';
l.href = a + src;
h = d.getElementsByTagName('head')[0];
h.parentNode.insertBefore(l, h);
});
scripts.forEach(function (src) {
s = d.createElement('script');
t = d.getElementsByTagName('script')[0];
s.async = false;
s.src = a + src;
t.parentNode.insertBefore(s, t);
});
})(window, document, assetsUrl, '/favicons/favicon.ico', window.StaticConfig.stylesheets, window.StaticConfig.scripts);
}
});
})(window, document);

@ -0,0 +1,70 @@
<!DOCTYPE html>
<html>
<head>
<title></title>
<style>
#initial_startup {
width: 100%;
height: 100%;
position: fixed;
-moz-user-select: none;
-webkit-user-select: none;
display: flex;
align-items: center;
justify-content: center;
display: -webkit-box;
display: -webkit-flex;
-webkit-align-items: center;
-webkit-justify-content: center;
flex-direction: column;
-webkit-flex-direction: column;
}
.spinner {
position: relative;
margin: 0 auto;
border-top: 2px solid #ddd;
border-right: 2px solid #ddd;
border-bottom: 2px solid #ddd;
border-left: 2px solid #0090d7;
-webkit-animation: load8 1.1s infinite linear;
-khtml-animation: load8 1.1s infinite linear;
-moz-animation: load8 1.1s infinite linear;
-ms-animation: load8 1.1s infinite linear;
-o-animation: load8 1.1s infinite linear;
animation: load8 1.1s infinite linear;
}
.spinner,
.spinner:after {
width: 36px;
height: 36px;
border-radius: 50%;
}
@keyframes load8 {
100% { transform: rotate(360deg); }
}
@-webkit-keyframes load8 {
100% { -webkit-transform: rotate(360deg); }
}
</style>
</head>
<body>
<div id="app"></div>
<div id="initial_startup">
<div class="spinner"></div>
</div>
<script>
window.StaticConfig = <%= JSON.stringify(htmlWebpackPlugin.options.config) %>
</script>
<% if (!htmlWebpackPlugin.options.inject) { %>
<% htmlWebpackPlugin.files.js.forEach(function(jsFile) { %>
<script>
<%= compilation.assets[jsFile.substr(htmlWebpackPlugin.files.publicPath.length)].source() %>
</script>
<% }); %>
<% } %>
</body>
</html>

@ -0,0 +1,18 @@
var files = {
dashboard: {
stylesheets: [
'/stylesheets/cartodb.css',
'/stylesheets/common.css',
'/stylesheets/dashboard.css'
],
scripts: [
'/javascripts/cdb_static.js',
'/javascripts/models_static.js',
'/javascripts/dashboard_templates_static.js',
'/javascripts/dashboard_deps_static.js',
'/javascripts/dashboard_static.js'
]
}
};
module.exports = files;

@ -1,6 +1,6 @@
{
"name": "cartodb-ui",
"version": "4.9.43",
"version": "4.9.44-frontend.1",
"description": "CARTO UI frontend",
"repository": {
"type": "git",
@ -39,7 +39,8 @@
"tangram": "cartodb/tangram-1#master",
"torque.js": "CartoDB/torque#master",
"underscore": "1.8.3",
"webpack": "2.3.2"
"webpack": "2.3.2",
"request": "2.81.0"
},
"devDependencies": {
"autoprefixer-core": "5.2.1",
@ -76,6 +77,7 @@
"grunt-postcss": "0.5.5",
"grunt-sass": "2.0.0",
"grunt-timer": "0.3.3",
"html-webpack-plugin": "^2.30.1",
"jasmine": "2.5.2",
"jasmine-ajax": "CartoDB/jasmine-ajax#master",
"jstify": "0.13.0",
@ -174,9 +176,6 @@
"/vendor"
]
},
"config": {
"npmJsDir": "lib/assets"
},
"engine": {
"node": "6.9.2"
},
@ -185,9 +184,11 @@
"update-internal-deps": "rm -rf node_modules && npm install --production --no-shrinkwrap && npm dedupe && npm prune && npm shrinkwrap && npm install",
"branch-files": "node lib/build/branchFiles/branchFiles.js",
"affected_specs": "node lib/build/branchFiles/branchFiles.js | xargs node lib/build/affectedFiles/affectedFiles.js",
"build": "NODE_ENV=production webpack --config webpack.prod.config.js",
"build": "NODE_ENV=production webpack --config webpack.prod.config.js && npm run build:dashboard",
"build:dashboard": "webpack -p --config webpack/webpack.dev.config.js",
"build:stats": "webpack --env.stats --progress --config webpack.dev.config.js",
"start": "grunt watch:css & webpack --progress --watch --config webpack.dev.config.js",
"start": "grunt watch:css & webpack --progress --watch --config webpack.dev.config.js & npm run start:dashboard",
"start:dashboard": "webpack --progress --watch --config webpack/webpack.dev.config.js",
"dev": "webpack --progress --config webpack.dev.config.js"
}
}

@ -0,0 +1,44 @@
const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');
var webpack_files = require('../lib/build/files/webpack_files');
const PACKAGE = require('./../package.json');
const version = PACKAGE.version;
module.exports = {
entry: './lib/assets/javascripts/cartodb/static.js',
output: {
filename: `${version}/javascripts/[name].js`,
path: path.resolve(__dirname, '../public/assets'),
publicPath: '/assets/'
},
devtool: 'source-map',
plugins: Object.keys(webpack_files).map(function (entryName) {
return new HtmlWebpackPlugin({
inject: false,
cache: false,
filename: path.resolve(__dirname, '../public/static/' + entryName + '/index.html'),
template: path.resolve(__dirname, '../lib/assets/javascripts/cartodb/static/index.jst.ejs'),
config: webpack_files[entryName]
});
}),
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
include: [
path.resolve(__dirname, '../lib/assets/javascripts/carto-node')
],
options: {
presets: ['es2015']
}
}
]
},
node: {
fs: 'empty',
net: 'empty',
tls: 'empty'
}
};
Loading…
Cancel
Save