You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by GitBox <gi...@apache.org> on 2021/12/24 05:19:00 UTC
[GitHub] [echarts] pissang opened a new pull request #16276: chore: add .js extension in the import statement
pissang opened a new pull request #16276:
URL: https://github.com/apache/echarts/pull/16276
<!-- Please fill in the following information to help us review your PR more efficiently. -->
## Brief Information
This pull request is in the type of:
- [ ] bug fixing
- [ ] new feature
- [x] others
### What does this PR do?
As discussed in https://github.com/apache/echarts/issues/16054. This PR trys to add an extra transform step to add `.js` extension to the import statement after `lib` is generated.
So before the statement is:
```ts
import * as zrender from 'zrender/lib/zrender';
```
Now it becomes:
```ts
import * as zrender from 'zrender/lib/zrender.js';
```
So specific modules in the `lib` can be imported in the browsers more conveniently.
## Misc
<!-- ADD RELATED ISSUE ID WHEN APPLICABLE -->
- [ ] The API has been changed (apache/echarts-doc#xxx).
- [x] This PR depends on ZRender changes (ecomfe/zrender#862).
### Related test cases or examples to use the new APIs
Still there some required steps needs to be done before we actually importing the modules:
1. For the modules from dependencies. Import map need to be configured.
```html
<script type="importmap">
{
"imports": {
"echarts/": "https://unpkg.com/echarts@latest/",
"zrender/": "https://unpkg.com/zrender@latest/",
"tslib": "https://unpkg.com/tslib@2.3.1/tslib.es6.js"
}
}
</script>
```
2. Because the generated code use `process.env.NODE_ENV` on the dev only code. We need to define it in the browsers environment
```js
if (typeof process === "undefined" || !process.env) {
window.process = {
env: {
NODE_ENV: "development",
},
};
}
```
Then we can importing modules just like in the bundling environment.
```js
import * as echarts from "echarts/core.js";
import { PieChart } from "echarts/charts.js";
import { CanvasRenderer } from "echarts/renderers.js";
echarts.use([PieChart, CanvasRenderer]);
```
But still there are limitations. Because this API design heavliy depends on dead code removal to do the tree-shaking, which seems to be not supported by the browsers yet. So it will still import all the charts from `echarts/charts.js`, not only the pie chart we needed.
This problem not exists if we use our legacy partially importing API:
```js
import * as echarts from "echarts/lib/echarts";
import "echarts/lib/chart/pie.js";
```
It will only import the pie chart and all the modules it depends on.
## Others
### Merging options
- [ ] Please squash the commits into a single one when merging.
### Other information
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
[GitHub] [echarts] pissang merged pull request #16276: add .js extension in the import statement
Posted by GitBox <gi...@apache.org>.
pissang merged pull request #16276:
URL: https://github.com/apache/echarts/pull/16276
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
[GitHub] [echarts] plainheart commented on a change in pull request #16276: add .js extension in the import statement
Posted by GitBox <gi...@apache.org>.
plainheart commented on a change in pull request #16276:
URL: https://github.com/apache/echarts/pull/16276#discussion_r774888660
##########
File path: build/pre-publish.js
##########
@@ -272,8 +273,40 @@ async function transformDistributionFiles(rooltFolder, replacement) {
}
}
-function singleTransformZRRootFolder(code, replacement) {
- return code.replace(/([\"\'])zrender\/src\//g, `$1zrender/${replacement}/`);
+/**
+ * 1. Transform zrender/src to zrender/lib
+ * 2. Add .js extensions
+ *
+ * FIXME. Comment in the named import statement is not supported.
Review comment:
I tested it but it seems to be working?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
[GitHub] [echarts] echarts-bot[bot] commented on pull request #16276: chore: add .js extension in the import statement
Posted by GitBox <gi...@apache.org>.
echarts-bot[bot] commented on pull request #16276:
URL: https://github.com/apache/echarts/pull/16276#issuecomment-1000660366
Thanks for your contribution!
The community will review it ASAP. In the meanwhile, please checkout [the coding standard](https://echarts.apache.org/en/coding-standard.html) and Wiki about [How to make a pull request](https://github.com/apache/echarts/wiki/How-to-make-a-pull-request).
The pull request is marked to be `PR: author is committer` because you are a committer of this project.
This PR depends on [ZRender](https://github.com/ecomfe/zrender) changes. Please update the ZRender dependency to the latest nightly version including this change, which takes place everyday at 8:00 UTC (16:00 Beijing Time).
You can use `npm i zrender@npm:zrender-nightly@dev` to update package.json.
If you have any question about this, please leave a comment and we will give you extra help on this.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
[GitHub] [echarts] echarts-bot[bot] commented on pull request #16276: add .js extension in the import statement
Posted by GitBox <gi...@apache.org>.
echarts-bot[bot] commented on pull request #16276:
URL: https://github.com/apache/echarts/pull/16276#issuecomment-1000692953
Congratulations! Your PR has been merged. Thanks for your contribution! 👍
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
[GitHub] [echarts] pissang commented on a change in pull request #16276: add .js extension in the import statement
Posted by GitBox <gi...@apache.org>.
pissang commented on a change in pull request #16276:
URL: https://github.com/apache/echarts/pull/16276#discussion_r774889983
##########
File path: build/pre-publish.js
##########
@@ -272,8 +273,40 @@ async function transformDistributionFiles(rooltFolder, replacement) {
}
}
-function singleTransformZRRootFolder(code, replacement) {
- return code.replace(/([\"\'])zrender\/src\//g, `$1zrender/${replacement}/`);
+/**
+ * 1. Transform zrender/src to zrender/lib
+ * 2. Add .js extensions
+ *
+ * FIXME. Comment in the named import statement is not supported.
Review comment:
Ahhh I forget to remove this comment after this fix https://github.com/ecomfe/zrender/pull/863
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
[GitHub] [echarts] pissang commented on pull request #16276: add .js extension in the import statement
Posted by GitBox <gi...@apache.org>.
pissang commented on pull request #16276:
URL: https://github.com/apache/echarts/pull/16276#issuecomment-1000679417
@plainheart Just updated zrender to the latest nightly
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org