missive / emoji-mart

🏪 One component to pick them all
https://missiveapp.com/open/emoji-mart
MIT License
8.7k stars 835 forks source link

All.json is always there :'( #376

Closed peacepostman closed 4 years ago

peacepostman commented 5 years ago

Hello,

I know that this issue seems to be fixed now but i am still struggling to remove all.json from our webpack final build.

I am calling the picker via this snippet

import NimblePicker from 'emoji-mart/dist-es/components/picker/nimble-picker'
import data from 'emoji-mart/data/emojione.json'

And I am calling the emoji renderer via this snippet

import NimbleEmoji from 'emoji-mart/dist-es/components/emoji/nimble-emoji'
import data from 'emoji-mart/data/emojione.json'

Did any of you have any idea why my final build looks like this

Capture d’écran 2019-10-29 à 13 33 49

Best regards,

annie-zyp commented 5 years ago

@peacepostman Do you solve this problem? I met the same problem.

peacepostman commented 5 years ago

Humm, actually yes but its more a trick than a permanent solution :D

In package.json "postinstall": "node ./build-tools/clear-emoji-file.js" Then the target script :

const fs = require('fs')

try {
  var rootDir = process.cwd()
  var file = `${rootDir}/node_modules/emoji-mart/data/all.json`
  fs.writeFileSync(file, '{}', 'utf8')
  console.log('Emoji-mart all.json file is now empty')
} catch (error) {
  console.error(error)
}

work

nolanlawson commented 4 years ago

It's possible to use the nimble picker without including the JSON in the JavaScript file itself. In fact this is probably a good idea, since it's better for performance to use JSON.parse() instead of directly inlining.

Here is an example of how to do it. Basically instead of doing

import data from 'emoji-mart/data/emojione.json'

You would do:

const data = await (await fetch('/some/static/path/emojione.json')).json()

Then you would host the JSON file wherever you host your static data files. Or put it in IndexedDB or wherever you like. :)