{"action":"created","issue":{"url":"https://api.github.com/repos/nklayman/vue-cli-plugin-electron-builder/issues/31","repository_url":"https://api.github.com/repos/nklayman/vue-cli-plugin-electron-builder","labels_url":"https://api.github.com/repos/nklayman/vue-cli-plugin-electron-builder/issues/31/labels{/name}","comments_url":"https://api.github.com/repos/nklayman/vue-cli-plugin-electron-builder/issues/31/comments","events_url":"https://api.github.com/repos/nklayman/vue-cli-plugin-electron-builder/issues/31/events","html_url":"https://github.com/nklayman/vue-cli-plugin-electron-builder/issues/31","id":338936639,"node_id":"MDU6SXNzdWUzMzg5MzY2Mzk=","number":31,"title":"Unable to get webpack.NormalModuleReplacementPlugin working when building for electron","user":{"login":"bdiz","id":944954,"node_id":"MDQ6VXNlcjk0NDk1NA==","avatar_url":"https://avatars3.githubusercontent.com/u/944954?v=4","gravatar_id":"","url":"https://api.github.com/users/bdiz","html_url":"https://github.com/bdiz","followers_url":"https://api.github.com/users/bdiz/followers","following_url":"https://api.github.com/users/bdiz/following{/other_user}","gists_url":"https://api.github.com/users/bdiz/gists{/gist_id}","starred_url":"https://api.github.com/users/bdiz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bdiz/subscriptions","organizations_url":"https://api.github.com/users/bdiz/orgs","repos_url":"https://api.github.com/users/bdiz/repos","events_url":"https://api.github.com/users/bdiz/events{/privacy}","received_events_url":"https://api.github.com/users/bdiz/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2018-07-06T13:19:41Z","updated_at":"2018-07-07T01:01:04Z","closed_at":null,"author_association":"NONE","body":"**Describe the bug**\r\nI am using a single code base to target web and electron. I have a need to import different modules depending on the build target. I am attempting to use webpack.[NormalModuleReplacementPlugin](https://webpack.js.org/plugins/normal-module-replacement-plugin/) to meet this need as it will not include code in the bundle which is not needed for build targets which it is not currently building.\r\n\r\n**To Reproduce**\r\nCreate a vue.config like this:\r\n```javascript\r\nvar webpack = require('webpack');\r\n\r\nmodule.exports = { \r\n  configureWebpack: () => {\r\n\r\n    let plugins = [ \r\n\r\n      new webpack.NormalModuleReplacementPlugin(/(.*)-VUE_APP_PLATFORM(\\.*)/, function(resource) {\r\n        resource.request = resource.request.replace(/-VUE_APP_PLATFORM/, `-${process.env.VUE_APP_PLATFORM}`);\r\n      })  \r\n    ];  \r\n\r\n    return {\r\n      plugins,\r\n    };  \r\n\r\n  }\r\n};\r\n```\r\nCreate a new env file called .env.electron-production:\r\n```\r\nNODE_ENV=production\r\nVUE_APP_PLATFORM=electron\r\n```\r\nOptionally, create .env.web-production if you want to reproduce the pass case.\r\n```\r\nNODE_ENV=production\r\nVUE_APP_PLATFORM=web\r\n```\r\nCreate two files such as, db-web.js and db-electron.js. \r\n\r\nImport these modules in your project code using the line:\r\n```javascript\r\nimport db from \"../db-VUE_APP_PLATFORM\";\r\n```\r\nRun vue-cli-plugin-electron-builder: `vue-cli-service build:electron --mode electron-production`. (I've also tried first exporting `VUE_APP_PLATFORM=electron`, but it does not effect the result).\r\n\r\nThis error is encountered:\r\n```\r\n  ERROR in ./src/odm.js\r\n  Module not found: Error: Can't resolve '../db-VUE_APP_PLATFORM' in 'src'\r\n```\r\n\r\n**Expected behavior**\r\nExpectation was the module would be found without error. \r\n\r\nWhen building for web with `vue-cli-service build --mode web-production`, this plugin succeeds and the modules are found by webpack.\r\n\r\n**Environment:**\r\n - OS and version: Ubuntu 16.10\r\n - Node version: v10.5.0\r\n - npm version: 6.1.0\r\n - yarn version (if used): \r\n - vue-cli-plugin-electron-builder version : 0.3.2\r\n - vue/cli-service: 3.0.0-rc.3\r\n - other vue plugins used: none\r\n - custom config for vcp-electron-builder: none\r\n - (if possible) link to your repo: not possible\r\n\r\nThanks for this plugin!"},"comment":{"url":"https://api.github.com/repos/nklayman/vue-cli-plugin-electron-builder/issues/comments/403178045","html_url":"https://github.com/nklayman/vue-cli-plugin-electron-builder/issues/31#issuecomment-403178045","issue_url":"https://api.github.com/repos/nklayman/vue-cli-plugin-electron-builder/issues/31","id":403178045,"node_id":"MDEyOklzc3VlQ29tbWVudDQwMzE3ODA0NQ==","user":{"login":"nklayman","id":12448243,"node_id":"MDQ6VXNlcjEyNDQ4MjQz","avatar_url":"https://avatars2.githubusercontent.com/u/12448243?v=4","gravatar_id":"","url":"https://api.github.com/users/nklayman","html_url":"https://github.com/nklayman","followers_url":"https://api.github.com/users/nklayman/followers","following_url":"https://api.github.com/users/nklayman/following{/other_user}","gists_url":"https://api.github.com/users/nklayman/gists{/gist_id}","starred_url":"https://api.github.com/users/nklayman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nklayman/subscriptions","organizations_url":"https://api.github.com/users/nklayman/orgs","repos_url":"https://api.github.com/users/nklayman/repos","events_url":"https://api.github.com/users/nklayman/events{/privacy}","received_events_url":"https://api.github.com/users/nklayman/received_events","type":"User","site_admin":false},"created_at":"2018-07-07T01:01:04Z","updated_at":"2018-07-07T01:01:04Z","author_association":"OWNER","body":"The reason it is set to `.../dist_electron/bundled` is because all files that go through webpack (including files in the `public` directory) end up in `dist_electron/bundled` as not to corrupt the `dist` directory with non SPA compatible code. Electron builder has this nested in the `app.asar` because it needs to access your `node_modules` and `package.json` which are not nested, so the root directory is set to `./`. I will look into copying these into `dist_electron/bundled` so that the files end up in the root directory of the `app.asar`."}}
{"actor":{"display_login":"nklayman"}}