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

[js] version js file names using webpack chunkhash #2951

Merged
merged 8 commits into from
Jun 13, 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
15 changes: 15 additions & 0 deletions superset/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@
app.config.from_object(CONFIG_MODULE)
conf = app.config


@app.context_processor
def get_js_manifest():
manifest = {}
try:
with open(APP_DIR + '/static/assets/dist/manifest.json', 'r') as f:
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)


for bp in conf.get('BLUEPRINTS'):
try:
print("Registering blueprint: '{}'".format(bp.name))
Expand Down
2 changes: 2 additions & 0 deletions superset/assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
"babel-preset-es2015": "^6.14.0",
"babel-preset-react": "^6.11.1",
"chai": "^4.0.2",
"clean-webpack-plugin": "^0.1.16",
"codeclimate-test-reporter": "^0.5.0",
"css-loader": "^0.28.0",
"enzyme": "^2.0.0",
Expand Down Expand Up @@ -134,6 +135,7 @@
"transform-loader": "^0.2.3",
"url-loader": "^0.5.7",
"webpack": "^2.3.3",
"webpack-manifest-plugin": "1.1.0",
"webworkify-webpack": "2.0.4"
}
}
10 changes: 6 additions & 4 deletions superset/assets/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
const webpack = require('webpack');
const path = require('path');
const fs = require('fs');
const ManifestPlugin = require('webpack-manifest-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');

// input dir
const APP_DIR = path.resolve(__dirname, './');

// output dir
const BUILD_DIR = path.resolve(__dirname, './dist');

const VERSION_STRING = JSON.parse(fs.readFileSync('package.json')).version;

const config = {
entry: {
'css-theme': APP_DIR + '/javascripts/css-theme.js',
Expand All @@ -23,7 +22,8 @@ const config = {
},
output: {
path: BUILD_DIR,
filename: `[name].${VERSION_STRING}.entry.js`,
filename: '[name].[chunkhash].entry.js',
chunkFilename: '[name].[chunkhash].entry.js',
},
resolve: {
extensions: [
Expand Down Expand Up @@ -115,6 +115,8 @@ const config = {
'react/lib/ReactContext': true,
},
plugins: [
new ManifestPlugin(),
new CleanWebpackPlugin(['dist']),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(process.env.NODE_ENV),
Expand Down
5 changes: 3 additions & 2 deletions superset/templates/superset/partials/_script_tag.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% set VERSION_STRING = appbuilder.get_app.config.get("VERSION_STRING") %}
{% block tail_js %}
<script src="/static/assets/dist/{{filename}}.{{VERSION_STRING}}.entry.js"></script>
<script
src="{{ '/static/assets/dist/' + js_manifest.get(filename + '.js', '') }}">
</script>
{% endblock %}