Skip to content

Commit 36e1ce6

Browse files
committed
rails webpacker:install
1 parent 35429ae commit 36e1ce6

14 files changed

+7418
-1
lines changed

.browserslistrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
defaults

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,10 @@
3232
/vendor/bundle
3333
/db/auth
3434
/.env
35+
36+
/public/packs
37+
/public/packs-test
38+
/node_modules
39+
/yarn-error.log
40+
yarn-debug.log*
41+
.yarn-integrity

app/javascript/packs/application.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* eslint no-console:0 */
2+
// This file is automatically compiled by Webpack, along with any other files
3+
// present in this directory. You're encouraged to place your actual application logic in
4+
// a relevant structure within app/javascript and only use these pack files to reference
5+
// that code so it'll be compiled.
6+
//
7+
// To reference this file, add <%= javascript_pack_tag 'application' %> to the appropriate
8+
// layout file, like app/views/layouts/application.html.erb
9+
10+
11+
// Uncomment to copy all static images under ../images to the output folder and reference
12+
// them with the image_pack_tag helper in views (e.g <%= image_pack_tag 'rails.png' %>)
13+
// or the `imagePath` JavaScript helper below.
14+
//
15+
// const images = require.context('../images', true)
16+
// const imagePath = (name) => images(name, true)
17+
18+
console.log('Hello World from Webpacker')

babel.config.js

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
module.exports = function(api) {
2+
var validEnv = ['development', 'test', 'production']
3+
var currentEnv = api.env()
4+
var isDevelopmentEnv = api.env('development')
5+
var isProductionEnv = api.env('production')
6+
var isTestEnv = api.env('test')
7+
8+
if (!validEnv.includes(currentEnv)) {
9+
throw new Error(
10+
'Please specify a valid `NODE_ENV` or ' +
11+
'`BABEL_ENV` environment variables. Valid values are "development", ' +
12+
'"test", and "production". Instead, received: ' +
13+
JSON.stringify(currentEnv) +
14+
'.'
15+
)
16+
}
17+
18+
return {
19+
presets: [
20+
isTestEnv && [
21+
require('@babel/preset-env').default,
22+
{
23+
targets: {
24+
node: 'current'
25+
}
26+
}
27+
],
28+
(isProductionEnv || isDevelopmentEnv) && [
29+
require('@babel/preset-env').default,
30+
{
31+
forceAllTransforms: true,
32+
useBuiltIns: 'entry',
33+
corejs: 3,
34+
modules: false,
35+
exclude: ['transform-typeof-symbol']
36+
}
37+
]
38+
].filter(Boolean),
39+
plugins: [
40+
require('babel-plugin-macros'),
41+
require('@babel/plugin-syntax-dynamic-import').default,
42+
isTestEnv && require('babel-plugin-dynamic-import-node'),
43+
require('@babel/plugin-transform-destructuring').default,
44+
[
45+
require('@babel/plugin-proposal-class-properties').default,
46+
{
47+
loose: true
48+
}
49+
],
50+
[
51+
require('@babel/plugin-proposal-object-rest-spread').default,
52+
{
53+
useBuiltIns: true
54+
}
55+
],
56+
[
57+
require('@babel/plugin-transform-runtime').default,
58+
{
59+
helpers: false,
60+
regenerator: true,
61+
corejs: false
62+
}
63+
],
64+
[
65+
require('@babel/plugin-transform-regenerator').default,
66+
{
67+
async: false
68+
}
69+
]
70+
].filter(Boolean)
71+
}
72+
}

bin/webpack

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env ruby
2+
3+
ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
4+
ENV["NODE_ENV"] ||= "development"
5+
6+
require "pathname"
7+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
8+
Pathname.new(__FILE__).realpath)
9+
10+
require "rubygems"
11+
require "bundler/setup"
12+
13+
require "webpacker"
14+
require "webpacker/webpack_runner"
15+
16+
APP_ROOT = File.expand_path("..", __dir__)
17+
Dir.chdir(APP_ROOT) do
18+
Webpacker::WebpackRunner.run(ARGV)
19+
end

bin/webpack-dev-server

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env ruby
2+
3+
ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
4+
ENV["NODE_ENV"] ||= "development"
5+
6+
require "pathname"
7+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
8+
Pathname.new(__FILE__).realpath)
9+
10+
require "rubygems"
11+
require "bundler/setup"
12+
13+
require "webpacker"
14+
require "webpacker/dev_server_runner"
15+
16+
APP_ROOT = File.expand_path("..", __dir__)
17+
Dir.chdir(APP_ROOT) do
18+
Webpacker::DevServerRunner.run(ARGV)
19+
end

config/webpack/development.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
process.env.NODE_ENV = process.env.NODE_ENV || 'development'
2+
3+
const environment = require('./environment')
4+
5+
module.exports = environment.toWebpackConfig()

config/webpack/environment.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const { environment } = require('@rails/webpacker')
2+
3+
module.exports = environment

config/webpack/production.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
process.env.NODE_ENV = process.env.NODE_ENV || 'production'
2+
3+
const environment = require('./environment')
4+
5+
module.exports = environment.toWebpackConfig()

config/webpack/test.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
process.env.NODE_ENV = process.env.NODE_ENV || 'development'
2+
3+
const environment = require('./environment')
4+
5+
module.exports = environment.toWebpackConfig()

config/webpacker.yml

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# Note: You must restart bin/webpack-dev-server for changes to take effect
2+
3+
default: &default
4+
source_path: app/javascript
5+
source_entry_path: packs
6+
public_root_path: public
7+
public_output_path: packs
8+
cache_path: tmp/cache/webpacker
9+
check_yarn_integrity: false
10+
webpack_compile_output: false
11+
12+
# Additional paths webpack should lookup modules
13+
# ['app/assets', 'engine/foo/app/assets']
14+
resolved_paths: []
15+
16+
# Reload manifest.json on all requests so we reload latest compiled packs
17+
cache_manifest: false
18+
19+
# Extract and emit a css file
20+
extract_css: false
21+
22+
static_assets_extensions:
23+
- .jpg
24+
- .jpeg
25+
- .png
26+
- .gif
27+
- .tiff
28+
- .ico
29+
- .svg
30+
- .eot
31+
- .otf
32+
- .ttf
33+
- .woff
34+
- .woff2
35+
36+
extensions:
37+
- .mjs
38+
- .js
39+
- .sass
40+
- .scss
41+
- .css
42+
- .module.sass
43+
- .module.scss
44+
- .module.css
45+
- .png
46+
- .svg
47+
- .gif
48+
- .jpeg
49+
- .jpg
50+
51+
development:
52+
<<: *default
53+
compile: true
54+
55+
# Verifies that correct packages and versions are installed by inspecting package.json, yarn.lock, and node_modules
56+
check_yarn_integrity: true
57+
58+
# Reference: https://webpack.js.org/configuration/dev-server/
59+
dev_server:
60+
https: false
61+
host: localhost
62+
port: 3035
63+
public: localhost:3035
64+
hmr: false
65+
# Inline should be set to true if using HMR
66+
inline: true
67+
overlay: true
68+
compress: true
69+
disable_host_check: true
70+
use_local_ip: false
71+
quiet: false
72+
headers:
73+
'Access-Control-Allow-Origin': '*'
74+
watch_options:
75+
ignored: '**/node_modules/**'
76+
77+
78+
test:
79+
<<: *default
80+
compile: true
81+
82+
# Compile test packs to a separate directory
83+
public_output_path: packs-test
84+
85+
production:
86+
<<: *default
87+
88+
# Production depends on precompilation of packs prior to booting for performance.
89+
compile: false
90+
91+
# Extract and emit a css file
92+
extract_css: true
93+
94+
# Cache manifest.json for performance
95+
cache_manifest: true

package.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
{
22
"name": "bulls-eye",
33
"private": true,
4-
"dependencies": {}
4+
"dependencies": {
5+
"@rails/webpacker": "^4.0.7"
6+
},
7+
"devDependencies": {
8+
"webpack-dev-server": "^3.7.2"
9+
}
510
}

postcss.config.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
plugins: [
3+
require('postcss-import'),
4+
require('postcss-flexbugs-fixes'),
5+
require('postcss-preset-env')({
6+
autoprefixer: {
7+
flexbox: 'no-2009'
8+
},
9+
stage: 3
10+
})
11+
]
12+
}

0 commit comments

Comments
 (0)