-
Notifications
You must be signed in to change notification settings - Fork 76
[wip] Use yarn to manage frontend dependencies #314
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
base: develop
Are you sure you want to change the base?
Changes from 14 commits
420e3f9
8881d16
948edff
07ca35a
33c5412
37ca918
92a1673
e740f91
38153e2
974edcb
80abfea
b9d9871
6231b2c
45c61f7
f84eecb
2baaee9
4f8a90d
49b0d74
78f0564
5cdd63e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -72,3 +72,9 @@ player/static/mfr/* | |
| !.gitkeep | ||
|
|
||
| .cache | ||
|
|
||
| # JS | ||
| ####################### | ||
|
|
||
| node_modules | ||
| node_modules/* | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,6 +64,10 @@ ENV GIT_COMMIT ${GIT_COMMIT} | |
|
|
||
| RUN python setup.py develop | ||
|
|
||
| RUN apt-get install nodejs \ | ||
| apt-get install npm \ | ||
| && npm run build | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to check, should install all deps and build everything into dist |
||
| EXPOSE 7778 | ||
|
|
||
| CMD ["gosu", "www-data", "invoke", "server"] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,6 +47,14 @@ invoke install | |
| invoke server | ||
| ``` | ||
|
|
||
| Also set up node for frontend packages. The recommended package manager is `yarn`. | ||
| Webpack is used to build the packages. A script is included in `package.json` for convenience. | ||
|
|
||
| ```bash | ||
| yarn | ||
| yarn build | ||
| ``` | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some instructions |
||
|
|
||
| ### Configuring | ||
|
|
||
| MFR configuration is done through a JSON file (`mfr-test.json`) that lives in the `.cos` directory of your home directory. If this is your first time setting up MFR or its sister project, [WaterButler](https://github.com/CenterForOpenScience/waterbutler/), you probably do not have this directory and will need to create it: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| /* Copyright 2017 Mozilla Foundation | ||
|
||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| 'use strict'; | ||
|
|
||
| (function () { | ||
| var baseLocation; | ||
| if (typeof document !== 'undefined') { | ||
| baseLocation = new URL('./', document.currentScript.src); | ||
| } else if (typeof location !== 'undefined') { | ||
| // Probably worker -- walking subfolders until we will reach root. | ||
| baseLocation = location; | ||
| while (baseLocation.href.includes('/src/')) { | ||
| baseLocation = new URL('..', baseLocation); | ||
| } | ||
| } else { | ||
| throw new Error('Cannot configure SystemJS'); | ||
| } | ||
|
|
||
| var PluginBabelPath = 'node_modules/systemjs-plugin-babel/plugin-babel.js'; | ||
| var SystemJSPluginBabelPath = | ||
| 'node_modules/systemjs-plugin-babel/systemjs-babel-browser.js'; | ||
| var PluginBabelCachePath = 'external/systemjs/plugin-babel-cached.js'; | ||
|
|
||
| var isCachingPossible = typeof indexedDB !== 'undefined' && | ||
| typeof TextEncoder !== 'undefined' && | ||
| typeof crypto !== 'undefined' && | ||
| typeof crypto.subtle !== 'undefined'; | ||
|
|
||
| // When we create a bundle, webpack is run on the source and it will replace | ||
| // require with __webpack_require__. When we want to use the real require, | ||
| // __non_webpack_require__ has to be used. | ||
| // In this target, we don't create a bundle, so we have to replace the | ||
| // occurences of __non_webpack_require__ ourselves. | ||
| function babelPluginReplaceNonWebPackRequire(babel) { | ||
| return { | ||
| visitor: { | ||
| Identifier(path, state) { | ||
| if (path.node.name === '__non_webpack_require__') { | ||
| path.replaceWith(babel.types.identifier('require')); | ||
| } | ||
| }, | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| SystemJS.config({ | ||
| packages: { | ||
| '': { | ||
| defaultExtension: 'js', | ||
| }, | ||
| }, | ||
| paths: { | ||
| 'pdfjs': new URL('src', baseLocation).href, | ||
| 'pdfjs-web': new URL('web', baseLocation).href, | ||
| 'pdfjs-test': new URL('test', baseLocation).href, | ||
| 'pdfjs-lib': new URL('src/pdf', baseLocation).href, | ||
| 'core-js': new URL('node_modules/core-js', baseLocation).href, | ||
| }, | ||
| meta: { | ||
| '*': { | ||
| scriptLoad: false, | ||
| esModule: true, | ||
| babelOptions: { | ||
| env: false, | ||
| plugins: [babelPluginReplaceNonWebPackRequire], | ||
| }, | ||
| }, | ||
| }, | ||
| map: { | ||
| 'plugin-babel': new URL(PluginBabelPath, baseLocation).href, | ||
| 'systemjs-babel-build': | ||
| new URL(SystemJSPluginBabelPath, baseLocation).href, | ||
| 'plugin-babel-cached': new URL(PluginBabelCachePath, baseLocation).href, | ||
| }, | ||
| transpiler: isCachingPossible ? 'plugin-babel-cached' : 'plugin-babel', | ||
| }); | ||
| })(); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,5 +3,4 @@ | |
| Your browser does not support the audio tag. | ||
| </audio> | ||
|
|
||
| <script src="/static/js/mfr.js"></script> | ||
| <script src="/static/js/mfr.child.js"></script> | ||
| <script src="/assets/mfr.child.js"></script> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only reason mfr.js was included prior was to get pym.js library in the iframe. Webpack builds it in now. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,7 +66,7 @@ pre { | |
| overflow: auto; | ||
| display: block; | ||
| padding: 9.5px; | ||
| margin: 0px 0px 10px; | ||
| margin: 0px 0px 0px 0px; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix some broken css |
||
| font-size: 13px; | ||
| line-height: 1.42857; | ||
| background-color: #F5F5F5; | ||
|
|
@@ -80,4 +80,4 @@ code, kbd, pre, samp { | |
|
|
||
| * { | ||
| box-sizing: border-box; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,7 @@ | ||
| <link rel="stylesheet" href="${base}/css/default.css"> | ||
| <script src="/assets/codepygments.js"></script> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. webpacked script to get the css on the page. This is probably not worth it for this extension, but it would make sense to keep consistency |
||
|
|
||
| <div style="word-wrap: break-word;" class="mfrViewer"> | ||
| ${body} | ||
| </div> | ||
|
|
||
| <script src="/static/js/mfr.js"></script> | ||
| <script src="/static/js/mfr.child.js"></script> | ||
| <script src="/assets/mfr.child.js"></script> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,3 @@ | ||
| <img style="max-width: 100%;" src="${url}"> | ||
|
|
||
| <script src="/static/js/mfr.js"></script> | ||
| <script src="/static/js/mfr.child.js"></script> | ||
| <script src="/assets/mfr.child.js"></script> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| <link href="https://fonts.googleapis.com/css?family=Open+Sans:400,600,300,700" rel="stylesheet" type="text/css"> | ||
| <link rel="stylesheet" href="${base}/css/ipynb.css"> | ||
| <link rel="stylesheet" href="/assets/ipynb.css"> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to finish this. location of /static/css/default does'nt make sense to be in mfr/server, and is used as a dep in multiple extensions so need to decide on better location. Thinking /styles or /src/styles as is convention with other js apps |
||
| <link rel="stylesheet" href="${base}/css/pygments.css"> | ||
| <link rel="stylesheet" href="/static/css/default.css"> | ||
|
|
||
|
|
@@ -8,8 +8,7 @@ | |
| </div> | ||
|
|
||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js"></script> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mathjax can't easily be webpacked yet, so leaving this on their cdn for now is fine. the script inlined below can be webpacked though. |
||
| <script src="/static/js/mfr.js"></script> | ||
| <script src="/static/js/mfr.child.js"></script> | ||
| <script src="/assets/mfr.child.js"></script> | ||
| <script> | ||
| (function () { | ||
| MathJax.Hub.Config({ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't want node_modules committed