Skip to content

Update components build tools. #93

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

Closed
T4rk1n opened this issue Dec 7, 2018 · 5 comments
Closed

Update components build tools. #93

T4rk1n opened this issue Dec 7, 2018 · 5 comments

Comments

@T4rk1n
Copy link

T4rk1n commented Dec 7, 2018

Install dash>=0.31.1 then add this command to package.json:

"build:py": "dash-generate-components ./src/lib/components dash_bootstap_components"

Dash must be installed on the current environment when you run the command. Or you can make sure the environment is activated with this, assuming you have a venv directory in the project root:

(. venv/bin/activate || venv\\scripts\\activate && dash-generate-components ./src/lib/components dash_bootstap_components)

Then change dash_bootstrap_components/__init__.py to:

from __future__ import print_function as _

import os as _os
import sys as _sys
import json

import dash as _dash

# noinspection PyUnresolvedReferences
from ._imports_ import *
from ._imports_ import __all__

if not hasattr(_dash, 'development'):
    print('Dash was not successfully imported. '
          'Make sure you don\'t have a file '
          'named \n"dash.py" in your current directory.', file=_sys.stderr)
    _sys.exit(1)

_basepath = _os.path.dirname(__file__)
_filepath = _os.path.abspath(_os.path.join(_basepath, 'package.json'))
with open(_filepath) as f:
    package = json.load(f)

package_name = package['name'].replace(' ', '_').replace('-', '_')
__version__ = package['version']

_current_path = _os.path.dirname(_os.path.abspath(__file__))

_this_module = _sys.modules[__name__]


_js_dist = [
    {
        'relative_package_path': 'dash_bootstap_components.min.js',
        'dev_package_path': 'dash_bootstap_components.dev.js',
        'external_url': 'https://unpkg.com/{0}@{2}/{1}/{1}.min.js'.format(
            package_name, __name__, __version__),
        'namespace': package_name
    }
]

_css_dist = []


for _component in __all__:
    setattr(locals()[_component], '_js_dist', _js_dist)
    setattr(locals()[_component], '_css_dist', _css_dist)

Please commit all the files generated (metadata.json, _imports_.py, bundles).

@pbugnion
Copy link
Contributor

pbugnion commented Dec 8, 2018

Thanks for submitting this! @tcbegley -- I'm happy to look at this since I put some of the initial infrastructure in place.

@pbugnion
Copy link
Contributor

pbugnion commented Dec 9, 2018

@T4rk1n Under what conditions do _js_dist["dev_package_path"] and _js_dist["external_url"] get used?

At the moment, we don't publish dash_bootstrap_components to NPM, so having a link to unpkg seems a bit meaningless. While we do want to publish to NPM, I think we will probably publish a bundle that is optimized for building additional JS components, not as a faithful representation of the current bundle.

@T4rk1n
Copy link
Author

T4rk1n commented Dec 9, 2018

They are optional keys.

  • dev_package_path is used for serving the dev bundle for debugging the front end and more dev features. It is served when the key is found in _js_dist and app.run_server(debug=True).
  • external_url is used when found in the _js_dist and app.scripts.config.serve_locally=False, it is the current default of dash when found.
  • relative_package_path is the main path to the local resources and used by default when other conditions are false.

So if you don't want to publish on npm just don't include the external_url, with dash 1.0.0 the default will be to serve the resources locally.

@pbugnion
Copy link
Contributor

pbugnion commented Dec 9, 2018

Perfect, thank you for the explanation.

I suggest we try to include a dev bundle, probably as a new PR separate to #94.

@pbugnion
Copy link
Contributor

I've opened issue #100 for creating a development bundle. Everything else in this issue is addressed in PR #94, so I'm closing this.

Thanks for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants