-
Notifications
You must be signed in to change notification settings - Fork 462
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
how to use ol3-ext in webpack #33
Comments
Hello, |
Would be great ability to import individual components from npm. For example, thanks. |
I think I found a solution,may be usefulin webpack.base.conf.js resolve: {
extensions: ['.js', '.vue', '.json'],
alias: {
'vue$': 'vue/dist/vue.esm.js',
'@': resolve('src'),
'ol': resolve('node_modules/openlayers/dist/ol.js'),
'ol3-ext-dir': resolve('src/libs/ol3-ext'),
'ol3-ext': resolve('src/libs/ol3-ext/ol3-ext.modified.js'), // I modified ol3-ext's js file, deleted lines about WSynchro
'jspanel': 'jspanel3/source/jquery.jspanel.min.js'
}
}, and in module rules, add config {
test: require.resolve(path.join(libs, "ol3-ext/ol3-ext.modified.js")),
loader: "imports-loader?$=jquery,ol=openlayers"
} then , you just have to import 'ol3-ext'
// your code |
It would be really awesome, if this extension could be implemented with the ES2016 module syntax |
ol3-ext change is name and is now available on npm: https://www.npmjs.com/package/ol-ext |
@Viglino I would appreciate to see the best way to use ol-ext npm with ol modules, maybe an example would help alot, am confused about how to import the modules, currently I am ol3-xt cdn |
Hello, There is no best way to use ol-ext:
You should consider how you want to control your code:
Look at the Getting Started section. |
Hi, |
Thanks much @Viglino, I created a very simple repo here to demonstrate what am doing, please check it and modify what you see wrong. |
I'm not very aware with webpacks. |
If you have a running example using @houzw solution, you're welcome! This will be a first step. |
Hey @DarkScript! I can see you've done a great work! |
Thanks @DarkScript for your work! As openlayers promotes to use its "packaged" version it is great to have same with ol-ext. We will still have to find a way to keep the 2 version (packaged and old-fashion single file) of the same library in the same place. |
OK! I'll stop updates for my part until we get something working. |
@DarkScript I've started to write a gulp script to recreate the current (old-fashion) dist with your modifications. I use the |
@Viglino Ok, I will see what you will have, I will create a branch also from the last commit you will do on this week. |
Am also concerned if we should rename the 'classes', for instance, instead of ol_control_Button, should we use Button. And when the class is being imported and exported, we can just do: buttoncontrol.js (in ol-ext/control/) var Button = function(){
...
Button.prototype....
}
...
export default Button in a class using Button module import Button from 'ol-ext/control/buttoncontrol'
...
var myButton = new Button();
... What do you think about such es6 based way, openlayers are also switching to this way here to create class and here to export it |
Well, I've got a script that takes the es6 ol_control_Button to create the js ol.control.Button (quite simple as it just replace "_" with "." 😀 ). If we only use export default ol_control_Button and then import Button from 'ol-ext/control/buttoncontrol' The problem is that with the ol_control_Button there is 2 classes (Button and TextButton) exported and the exported class is ol_control_Button 😬 ... |
I think it will be pretty to rename the files to match the export. import Button from 'ol-ext/control/button' |
Good, I will create a branch for the node module and work on that this weekend |
You can create a branch "v2", we'll close the current (v1) branch and switch to the v2 when all runs. Anyway the old files won't be used directly except in a webpack, the only issue is to ensure the I'll try to push a script to build the (old-fashion) dist tomorrow! |
I created a branch 'npm-restructured' which contains the new structure, I updated to be in line with your last modifification. I have not yet included the fix @thhomas did but I will. I kept the naming we had in the initial repo I created and I moved all source to src as its best practice to separate the project from example and build, config and rest of stuff in the root directory. Its great if you created the script for rebuilding the dist, I will separate TextButton and Button in next push I do |
for info I accidently did a merge with main branch but after realizing I did a revert, its now back to its earlier state. |
@DarkScript I've pushed a I've also updated the doc using the dist (+2 bugs correction in the code to make it run). Run I'll work on examples to make them run 😄 |
@Viglino good work with the script, I will use the npm-restructured branch as node module in a branch am working on tomorrow, as I check for possible bugs especially in import/export. |
@DarkScript don't hesitate to rename the files to match the module names and even rename the directories (./src/layer contains sources...) |
@Viglino I did rename and reorganized some files, I edited the gulp script, help me test the gulp task and if order of files is good, also remember to modify ol.animation.pan which is used in the code but the class doesn't exist in the version of ol we are using(4.6.*), check also getpreview, settextpathstyle, cspline, convexhull, geomutils, hexbinsource, vectorrenderer3d, wsynchro which I never tested their functionality as node modules. |
With what we have I think now the node modules are ready, bugs expected but we can remove them as soon as they are identified. We should avoid to commit the dist folder in npm to avoid confusion of current between import based syntax with the old ol.. syntax (my opinion). |
@DarkScript now all examples runs! Maybe we should rename files to match the module name |
@Viglino yeah we can rename the files for instance instead of buttoncontrol.js we can have button.js since the file package (folder) is already control, should I go ahead with this? I can do it by tomorrow. |
OK. I think we also have to move the sources from |
@Viglino I renamed the files to match export names, I also updated the gulp script, please test the script, also check on the merge request by @hkollmann, I placed a TODO on this branch. The next step would be maybe to change the functions name, for instance, instead of ol_control_Button we can have Button, this can be done in next version (you can add it to Roadmap of ol-ext ) |
As the script use the function names to recreate the ol classes, renaming the functions would force us to change the method and look in the file path 😒 . |
Hi!
If all is OK I can push a last version for the gh-pages (v1.1.3) and switch to the restructured branch (v2.0). |
Hi, I've pushed the Next step: create a v2.0.0 based on master and publish to npm. Todo:
|
ol3-ext is great!
But how to use it in webpack with npm?
thanks
The text was updated successfully, but these errors were encountered: