-
Notifications
You must be signed in to change notification settings - Fork 121
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
Fix resolution on Atom editor #8
Conversation
This feature detection may fail on Atom env. use browserify's standalone instead of `window` detection
use NodeDictionaryLoader as a default. if use BrowserDictionaryLoader, build files by browserify.
browser/kuromoji.js use BrowserDictionaryLoader instead of NodeDictionaryLoader.
@@ -0,0 +1,46 @@ | |||
var zlib = require("zlibjs/bin/gunzip.min.js"); |
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.
Browser use BrowserDictionaryLoader.js
(dist/browser/kuromoji.js)
@@ -4,6 +4,9 @@ | |||
"author": "Takuya Asano <takuya.a@gmail.com>", | |||
"description": "JavaScript implementation of Japanese morphological analyzer", | |||
"main": "./dist/node/kuromoji.js", | |||
"browser": { |
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.
@@ -4,6 +4,9 @@ | |||
"author": "Takuya Asano <takuya.a@gmail.com>", | |||
"description": "JavaScript implementation of Japanese morphological analyzer", | |||
"main": "./dist/node/kuromoji.js", | |||
"browser": { | |||
"./dist/node/loader/NodeDictionaryLoader.js": "./dist/node/loader/BrowserDictionaryLoader.js" |
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.
I don't know about browser
field in details, but if this line is replaced by
"./src/loader/NodeDictionaryLoader.js": "./src/loader/BrowserDictionaryLoader.js"
, perhaps we don't need this line of code in gulpfile.js:
b.require(__dirname + "/src/loader/BrowserDictionaryLoader.js", {expose: "./loader/NodeDictionaryLoader.js"});
(I think browserify will make this rearrangement)
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.
Edit: Ah, I agree with that.
But, this change cause external transform not work.
browser
field for external.(This affect external browserify
command)
external is a user that use kuromoji
as a module.
b.require
for internal.(This affect only gulp build
)
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.
Hmm... gulp build
does not seem to need b.require
in my environment.
my package.json:
"browser": {
"./src/loader/NodeDictionaryLoader.js": "./src/loader/BrowserDictionaryLoader.js"
},
my gulpfile.js:
var b = browserify({
entries: ["./src/kuromoji.js"],
standalone: "kuromoji" // window.kuromoji
});
// Commented out b.require
// b.require(__dirname + "/src/loader/BrowserDictionaryLoader.js", {expose: "./loader/NodeDictionaryLoader.js"});
b.bundle()
.pipe(source("kuromoji.js"))
.pipe(gulp.dest("./dist/browser/"));
I executed
$ gulp build
then I got preferred dist/browser/kuromoji.js
with BrowserDictionaryLoader.
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.
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.
I got it!
b.require
is needed for such that modules:
- require kuromoji.js (in node.js manner)
- are browserified (for working on browser)
(but not tested... If you encountered problems, please open an issue)
Thanks a lot @azu I have a question or comment on this point. |
Thanks! |
@takuyaa Hi, I fixed
require("kuromoji"); // undefeined
issue on some env like Atom.Purpose
Currently,
kuromoji.js
doesn't work on Atom editor(plugin).This pull request fix this issue.
require("kuromoji"); // undefeined
in Atom.Changes
window
detection fromsrc/kuromoji.js
andDictionaryLoader
DictionaryLoader
intoBrowserDictionaryLoader
andNodeDictionaryLoader
Atom has
window
object... it means thatmodule.exports = undefined
@src/kuromoji.js
I refactor this feature detection and move feature detection to browserify's build phase.
(So, feature detection code was removed)
src/
code use directlyNodeDictionaryLoader
.dist/browser/kuromoji.js
use directlyBrowserDictionaryLoader
(dist/browser/kuromoji.js
doesn't containNodeDictionaryLoader
)I'v added a macro that replace
NodeDictionaryLoader
toBrowserDictionaryLoader
intogulpfile.js
andpackage.json