{"id":21285521,"url":"https://github.com/takeyuweb/rails-webpack-sample","last_synced_at":"2025-03-15T15:13:03.246Z","repository":{"id":66907469,"uuid":"188055200","full_name":"takeyuweb/rails-webpack-sample","owner":"takeyuweb","description":null,"archived":false,"fork":false,"pushed_at":"2019-05-22T20:14:52.000Z","size":254,"stargazers_count":0,"open_issues_count":4,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-22T05:16:06.710Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/takeyuweb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-05-22T14:27:41.000Z","updated_at":"2019-05-22T19:21:38.000Z","dependencies_parsed_at":"2023-02-24T04:00:44.416Z","dependency_job_id":null,"html_url":"https://github.com/takeyuweb/rails-webpack-sample","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/takeyuweb%2Frails-webpack-sample","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/takeyuweb%2Frails-webpack-sample/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/takeyuweb%2Frails-webpack-sample/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/takeyuweb%2Frails-webpack-sample/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/takeyuweb","download_url":"https://codeload.github.com/takeyuweb/rails-webpack-sample/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243746201,"owners_count":20341203,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-21T11:20:54.584Z","updated_at":"2025-03-15T15:13:03.226Z","avatar_url":"https://github.com/takeyuweb.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Rails + Webpack Sample\n\n![webpack](https://user-images.githubusercontent.com/60980/58201743-d059b700-7d10-11e9-82a8-27d1b652cc8e.gif)\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n  \u003chead\u003e\n    \u003ctitle\u003eRailsWebpackSample\u003c/title\u003e\n    \u003cmeta name=\"csrf-param\" content=\"authenticity_token\" /\u003e\n\u003cmeta name=\"csrf-token\" content=\"dX15C0OggA0QK9Scweo/Bm0l7FnWMNGs1rQrlTodQm4JVZI48HBQGaYFa5ffE/yslP6I0vcKphKCmUFlqkl6Mg==\" /\u003e\n    \n\n    \u003cscript src=\"/bundle/hello_world.17631fbd2bb2407e5b58.js\" defer=\"defer\"\u003e\u003c/script\u003e\n    \u003clink rel=\"stylesheet\" media=\"screen\" href=\"/bundle/style.a18b434aa32a868e5153.css\" /\u003e\n  \u003c/head\u003e\n\n  \u003cbody\u003e\n    \u003ch1\u003eHome#index\u003c/h1\u003e\n\u003cp\u003eFind me in app/views/home/index.html.erb\u003c/p\u003e\n\n\u003c!-- app/frontend/images/skyview.jpg --\u003e\n\u003cimg src=\"/bundle/images/skyview.bf6a8ac49db7896747fa3b5c65cd71ba.jpg\" /\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\n## Setup\n\n```bash\n$ bundle install\n$ npm install\n```\n\n## Start\n\n```bash\n$ npx webpack -p\n$ bundle exec rails s\n```\n\nOpen http://localhost:3000\n\n## webpack\n\n`app/frontend` 以下\n\n### app/frontend/javascripts\n\nJavaScriptを入れるところ\n\n`webpack.config.js` で `app/frontend/javascripts/hello_world.ts` を `hello_world` という名前のエントリーポイントにしている。\n\nRailsテンプレート中で `javascript_bundle_tag \"hello_world\"`\n\n### app/frontend/styles\n\nSCSSを入れるところ\n\n`webpack.config.js` で `app/frontend/styles/style.scss` を `style` という名前のエントリーポイントにしている。\n\nRailsテンプレート中で `stylesheet_bundle_tag \"style\"`\n\n### app/frontend/images\n\n画像を入れるところ\n\n`app/frontend/images/path/to/file.png` を使いたいとき\n\nSCSS中なら `url(\"../images/path/to/file.png\")` （`../` の部分は `.scss` からの相対ディレクトリ指定）\n\nJavaScript中なら `import img from '../images/path/to/file.png'` または `const img = require('../images/path/to/file.png')`\n\nRailsテンプレート中なら `image_bundle_tag \"style\"`\n※これだけでは参照できなくて、別途 `require('../images/path/to/file.png')` のようにwebpackに教えてあげる必要がある。\n\n既知の課題 [sprocketsのようにapp/frontend/images においた画像をJavaScript中でのimportなしにimage_bundle_tagでRailsテンプレート中から参照したい ](https://github.com/takeyuweb/rails-webpack-sample/issues/6)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftakeyuweb%2Frails-webpack-sample","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftakeyuweb%2Frails-webpack-sample","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftakeyuweb%2Frails-webpack-sample/lists"}