{"action":"created","issue":{"url":"https://api.github.com/repos/fusionjs/fusion-cli/issues/254","repository_url":"https://api.github.com/repos/fusionjs/fusion-cli","labels_url":"https://api.github.com/repos/fusionjs/fusion-cli/issues/254/labels{/name}","comments_url":"https://api.github.com/repos/fusionjs/fusion-cli/issues/254/comments","events_url":"https://api.github.com/repos/fusionjs/fusion-cli/issues/254/events","html_url":"https://github.com/fusionjs/fusion-cli/issues/254","id":299529039,"number":254,"title":"Improve experience of working with node builtins","user":{"login":"ganemone","id":3399526,"avatar_url":"https://avatars1.githubusercontent.com/u/3399526?v=4","gravatar_id":"","url":"https://api.github.com/users/ganemone","html_url":"https://github.com/ganemone","followers_url":"https://api.github.com/users/ganemone/followers","following_url":"https://api.github.com/users/ganemone/following{/other_user}","gists_url":"https://api.github.com/users/ganemone/gists{/gist_id}","starred_url":"https://api.github.com/users/ganemone/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ganemone/subscriptions","organizations_url":"https://api.github.com/users/ganemone/orgs","repos_url":"https://api.github.com/users/ganemone/repos","events_url":"https://api.github.com/users/ganemone/events{/privacy}","received_events_url":"https://api.github.com/users/ganemone/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"ganemone","id":3399526,"avatar_url":"https://avatars1.githubusercontent.com/u/3399526?v=4","gravatar_id":"","url":"https://api.github.com/users/ganemone","html_url":"https://github.com/ganemone","followers_url":"https://api.github.com/users/ganemone/followers","following_url":"https://api.github.com/users/ganemone/following{/other_user}","gists_url":"https://api.github.com/users/ganemone/gists{/gist_id}","starred_url":"https://api.github.com/users/ganemone/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ganemone/subscriptions","organizations_url":"https://api.github.com/users/ganemone/orgs","repos_url":"https://api.github.com/users/ganemone/repos","events_url":"https://api.github.com/users/ganemone/events{/privacy}","received_events_url":"https://api.github.com/users/ganemone/received_events","type":"User","site_admin":false},"assignees":[{"login":"ganemone","id":3399526,"avatar_url":"https://avatars1.githubusercontent.com/u/3399526?v=4","gravatar_id":"","url":"https://api.github.com/users/ganemone","html_url":"https://github.com/ganemone","followers_url":"https://api.github.com/users/ganemone/followers","following_url":"https://api.github.com/users/ganemone/following{/other_user}","gists_url":"https://api.github.com/users/ganemone/gists{/gist_id}","starred_url":"https://api.github.com/users/ganemone/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ganemone/subscriptions","organizations_url":"https://api.github.com/users/ganemone/orgs","repos_url":"https://api.github.com/users/ganemone/repos","events_url":"https://api.github.com/users/ganemone/events{/privacy}","received_events_url":"https://api.github.com/users/ganemone/received_events","type":"User","site_admin":false}],"milestone":null,"comments":0,"created_at":"2018-02-22T22:17:47Z","updated_at":"2018-02-22T22:52:20Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"### Type of issue\n\nFeature request\n\n### Description\n\nUsing node builtins currently requires employing some hacks due to the way we manage tree shaking in conjunction with our webpack node configuration. We should improve the experience of using node builtins.\n\n### Current behavior\n\n```js\n// some-plugin.js\nimport fs from 'fs';\nimport {createPlugin} from 'fusion-core';\n\nexport default createPlugin({\n  deps: {},\n  provides: () => {\n    // do some things with fs...\n  }\n}}\n\n// src/main.js\nimport somePlugin from './some-plugin';\n__NODE__ && app.register(somePlugin):\n```\n\nRunning `dev` results in: \n\n```\nerror: (client) ./src/some-plugin.js\nModule not found: Error: Can't resolve 'fs' in ...\n```\n\nThis happens for two reasons.\n1. we don't tree shake in development, so `src/some-plugin.js` is included in the client bundle\n2. we set the `node.fs` webpack config to be `false`\n\n### Expected behavior\n\nThe build should work, but the plugin won't be registered.\n\n### Steps to reproduce\n\n1. scaffold a fusion app\n2. create a plugin that imports fs\n3. apply that plugin in __NODE__ only\n4. run `fusion dev`\n\n### Proposed Solution\n\nLong term, we can investigate ways of supporting tree shaking in development. Short term, we should set all `node` builtins to be `empty` (where possible) for the client build. This will allow the user to import them, but with throw errors if the user tries to use them. \n\nNOTE: Unfortunately, problems often arise when certain node builtins are set to 'empty', specifically surrounding testing, so we may need to make exceptions in certain cases."},"comment":{"url":"https://api.github.com/repos/fusionjs/fusion-cli/issues/comments/367850395","html_url":"https://github.com/fusionjs/fusion-cli/issues/254#issuecomment-367850395","issue_url":"https://api.github.com/repos/fusionjs/fusion-cli/issues/254","id":367850395,"user":{"login":"lhorie","id":1637573,"avatar_url":"https://avatars3.githubusercontent.com/u/1637573?v=4","gravatar_id":"","url":"https://api.github.com/users/lhorie","html_url":"https://github.com/lhorie","followers_url":"https://api.github.com/users/lhorie/followers","following_url":"https://api.github.com/users/lhorie/following{/other_user}","gists_url":"https://api.github.com/users/lhorie/gists{/gist_id}","starred_url":"https://api.github.com/users/lhorie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lhorie/subscriptions","organizations_url":"https://api.github.com/users/lhorie/orgs","repos_url":"https://api.github.com/users/lhorie/repos","events_url":"https://api.github.com/users/lhorie/events{/privacy}","received_events_url":"https://api.github.com/users/lhorie/received_events","type":"User","site_admin":false},"created_at":"2018-02-22T22:52:20Z","updated_at":"2018-02-22T22:52:20Z","author_association":"CONTRIBUTOR","body":"I feel like this is a bug, not a feature request.\r\n\r\nRe: proposed solution: how about writing a babel plugin that checks for `import ... from 'builtin'` and removes the import in browsers, using [this](https://github.com/juliangruber/builtins) or similar libs?"}}
{"actor":{"display_login":"lhorie"}}