Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[webpack] break CSS and JS files while webpackin' #3262

Merged
merged 2 commits into from
Aug 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions superset/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,21 @@
app.config.from_object(CONFIG_MODULE)
conf = app.config

# Handling manifest file logic at app start
MANIFEST_FILE = APP_DIR + '/static/assets/dist/manifest.json'
get_manifest_file = lambda x: x
manifest = {}
try:
with open(MANIFEST_FILE, 'r') as f:
manifest = json.load(f)
get_manifest_file = lambda x: '/static/assets/dist/' + manifest.get(x, '')
except Exception:
print("no manifest file found at " + MANIFEST_FILE)


@app.context_processor
def get_js_manifest():
manifest = {}
try:
with open(APP_DIR + '/static/assets/dist/manifest.json', 'r') as f:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This happened at every request :(

manifest = json.load(f)
except Exception as e:
print(
"no manifest file found at " +
APP_DIR + "/static/assets/dist/manifest.json"
)
return dict(js_manifest=manifest)
return dict(js_manifest=get_manifest_file)


for bp in conf.get('BLUEPRINTS'):
Expand Down
2 changes: 1 addition & 1 deletion superset/assets/javascripts/SqlLab/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { initJQueryAjax } from '../modules/utils';
import App from './components/App';
import { appSetup } from '../common';

import './main.css';
import './main.less';
import '../../stylesheets/reactable-pagination.css';
import '../components/FilterableTable/FilterableTableStyles.css';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ div.Workspace {
margin: 0px;
border: none;
font-size: 12px;
line-height: @line-height-base;
background-color: transparent !important;
}

Expand Down
2 changes: 1 addition & 1 deletion superset/assets/javascripts/explore/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import '../../stylesheets/reactable-pagination.css';
appSetup();
initJQueryAjax();

const exploreViewContainer = document.getElementById('js-explore-view-container');
const exploreViewContainer = document.getElementById('app');
const bootstrapData = JSON.parse(exploreViewContainer.getAttribute('data-bootstrap'));
const controls = getControlsState(bootstrapData, bootstrapData.form_data);
delete bootstrapData.form_data;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
import '../stylesheets/less/index.less';
import '../stylesheets/react-select/select.less';
import '../stylesheets/superset.less';
1 change: 1 addition & 0 deletions superset/assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
"eslint-plugin-jsx-a11y": "^5.0.3",
"eslint-plugin-react": "^7.0.1",
"exports-loader": "^0.6.3",
"extract-text-webpack-plugin": "2.1.2",
"file-loader": "^0.11.1",
"github-changes": "^1.0.4",
"ignore-styles": "^5.0.1",
Expand Down
27 changes: 18 additions & 9 deletions superset/assets/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const webpack = require('webpack');
const path = require('path');
const ManifestPlugin = require('webpack-manifest-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');

// input dir
const APP_DIR = path.resolve(__dirname, './');
Expand All @@ -14,7 +15,7 @@ const config = {
fs: 'empty',
},
entry: {
'css-theme': APP_DIR + '/javascripts/css-theme.js',
theme: APP_DIR + '/javascripts/theme.js',
common: APP_DIR + '/javascripts/common.js',
addSlice: ['babel-polyfill', APP_DIR + '/javascripts/addSlice/index.jsx'],
dashboard: ['babel-polyfill', APP_DIR + '/javascripts/dashboard/Dashboard.jsx'],
Expand Down Expand Up @@ -64,11 +65,24 @@ const config = {
include: APP_DIR + '/node_modules/mapbox-gl/js',
loader: 'babel-loader',
},
/* for require('*.css') */
// Extract css files
{
test: /\.css$/,
include: APP_DIR,
loader: 'style-loader!css-loader',
loader: ExtractTextPlugin.extract({
use: ['css-loader'],
fallback: 'style-loader',
}),
},
// Optionally extract less files
// or any other compile-to-css language
{
test: /\.less$/,
include: APP_DIR,
loader: ExtractTextPlugin.extract({
use: ['css-loader', 'less-loader'],
fallback: 'style-loader',
}),
},
/* for css linking images */
{
Expand All @@ -92,12 +106,6 @@ const config = {
test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'file-loader',
},
/* for require('*.less') */
{
test: /\.less$/,
include: APP_DIR,
loader: 'style-loader!css-loader!less-loader',
},
/* for mapbox */
{
test: /\.json$/,
Expand All @@ -123,6 +131,7 @@ const config = {
NODE_ENV: JSON.stringify(process.env.NODE_ENV),
},
}),
new ExtractTextPlugin('[name].[chunkhash].css'),
],
};
if (process.env.NODE_ENV === 'production') {
Expand Down
15 changes: 3 additions & 12 deletions superset/templates/superset/base.html
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
{% extends "appbuilder/baselayout.html" %}

{% block head_css %}
<link rel="icon" type="image/png" href="/static/assets/images/favicon.png">
<link rel="stylesheet" type="text/css" href="/static/assets/stylesheets/superset.css" />
{{super()}}
{% endblock %}

{% block head_js %}
{{super()}}
{% with filename="css-theme" %}
{% include "superset/partials/_script_tag.html" %}
{% endwith %}
<link rel="icon" type="image/png" href="/static/assets/images/favicon.png">
<link rel="stylesheet" type="text/css" href="{{ js_manifest('theme.css') }}" />
{% endblock %}

{% block tail_js %}
{{super()}}
{% with filename="common" %}
{% include "superset/partials/_script_tag.html" %}
{% endwith %}
<script src="{{ js_manifest('common.js') }}"></script>
{% endblock %}
16 changes: 10 additions & 6 deletions superset/templates/superset/basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@
</title>
{% block head_meta %}{% endblock %}
{% block head_css %}
<link rel="stylesheet" type="text/css" href="/static/appbuilder/css/font-awesome.min.css" />
<link rel="stylesheet" type="text/css" href="/static/assets/stylesheets/superset.css" />
<link rel="stylesheet" type="text/css" href="/static/appbuilder/css/flags/flags16.css" />
<link rel="icon" type="image/png" href="/static/assets/images/favicon.png">
<link rel="stylesheet" type="text/css" href="/static/appbuilder/css/flags/flags16.css" />
<link rel="stylesheet" type="text/css" href="{{ js_manifest('theme.css') }}" />
<link rel="stylesheet" type="text/css" href="/static/appbuilder/css/font-awesome.min.css">
{% if entry %}
<link rel="stylesheet" type="text/css" href="{{ js_manifest(entry + '.css') }}" />
{% endif %}
{% endblock %}
{% block head_js %}
{% with filename="css-theme" %}
{% include "superset/partials/_script_tag.html" %}
{% endwith %}
<script src="{{ js_manifest('common.js') }}"></script>
{% endblock %}
<input
type="hidden"
Expand Down Expand Up @@ -65,6 +66,9 @@ <h4 class="modal-title"></h4>
</div>
</div>
{% block tail_js %}
{% if entry %}
<script src="{{ js_manifest(entry + '.js') }}"></script>
{% endif %}
{% endblock %}
</body>
</html>
8 changes: 0 additions & 8 deletions superset/templates/superset/dashboard.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
{% extends "superset/basic.html" %}

{% block head_js %}
{{ super() }}
{% with filename="dashboard" %}
{% include "superset/partials/_script_tag.html" %}
{% endwith %}
{% endblock %}
{% block title %}[dashboard] {{ dashboard_title }}{% endblock %}
{% block body %}

<div
class="dashboard container-fluid"
data-bootstrap="{{ bootstrap_data }}"
Expand Down
23 changes: 0 additions & 23 deletions superset/templates/superset/explore.html

This file was deleted.

6 changes: 0 additions & 6 deletions superset/templates/superset/index.html

This file was deleted.

2 changes: 1 addition & 1 deletion superset/templates/superset/partials/_script_tag.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% block tail_js %}
<script
src="{{ '/static/assets/dist/' + js_manifest.get(filename + '.js', '') }}">
src="{{ js_manifest(filename + '.js') }}">
</script>
{% endblock %}
8 changes: 0 additions & 8 deletions superset/templates/superset/profile.html

This file was deleted.

8 changes: 0 additions & 8 deletions superset/templates/superset/sqllab.html

This file was deleted.

7 changes: 0 additions & 7 deletions superset/templates/superset/welcome.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
{% extends "superset/basic.html" %}

{% block head_js %}
{{ super() }}
{% with filename="welcome" %}
{% include "superset/partials/_script_tag.html" %}
{% endwith %}
{% endblock %}

{% block title %}{{ _("Welcome!") }}{% endblock %}

{% block body %}
Expand Down
24 changes: 16 additions & 8 deletions superset/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1093,12 +1093,16 @@ def explore(self, datasource_type, datasource_id):
table_name = datasource.table_name \
if datasource_type == 'table' \
else datasource.datasource_name
if slc:
title = "[slice] " + slc.slice_name
else:
title = "[explore] " + table_name
return self.render_template(
"superset/explore.html",
"superset/basic.html",
bootstrap_data=json.dumps(bootstrap_data),
slice=slc,
standalone_mode=standalone,
table_name=table_name)
entry='explore',
title=title,
standalone_mode=standalone)

@api
@has_access_api
Expand Down Expand Up @@ -1723,7 +1727,8 @@ def dashboard(**kwargs): # noqa

return self.render_template(
"superset/dashboard.html",
dashboard_title=dash.dashboard_title,
entry='dashboard',
title='[dashboard] ' + dash.dashboard_title,
bootstrap_data=json.dumps(bootstrap_data),
)

Expand Down Expand Up @@ -2232,7 +2237,8 @@ def welcome(self):
"""Personalized welcome page"""
if not g.user or not g.user.get_id():
return redirect(appbuilder.get_url_for_login)
return self.render_template('superset/welcome.html', utils=utils)
return self.render_template(
'superset/welcome.html', entry='welcome', utils=utils)

@has_access
@expose("/profile/<username>/")
Expand Down Expand Up @@ -2273,9 +2279,10 @@ def profile(self, username):
}
}
return self.render_template(
'superset/profile.html',
'superset/basic.html',
title=user.username + "'s profile",
navbar_container=True,
entry='profile',
bootstrap_data=json.dumps(payload, default=utils.json_iso_dttm_ser)
)

Expand All @@ -2287,7 +2294,8 @@ def sqllab(self):
'defaultDbId': config.get('SQLLAB_DEFAULT_DBID'),
}
return self.render_template(
'superset/sqllab.html',
'superset/basic.html',
entry='sqllab',
bootstrap_data=json.dumps(d, default=utils.json_iso_dttm_ser)
)
appbuilder.add_view_no_menu(Superset)
Expand Down