Skip to content

Move inline babel settings to .babelrc #291

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ bundle exec rails webpacker:install
```
- Check node version and yarn before installing webpacker - [#217](https://github.com/rails/webpacker/issues/217)

- Include webpacker helper to views - [#172](https://github.com/rails/webpacker/issues/172)

- Webpacker installer on windows - [#245](https://github.com/rails/webpacker/issues/245)

- Yarn duplication - [#278](https://github.com/rails/webpacker/issues/278)

- Add back Spring for `rails-erb-loader` - [#216](https://github.com/rails/webpacker/issues/216)

- Move babel presets and plugins to .babelrc - [#202](https://github.com/rails/webpacker/issues/202)

### Added
- A changelog - [#211](https://github.com/rails/webpacker/issues/211)
- Minimize CSS assets - [#218](https://github.com/rails/webpacker/issues/218)
Expand All @@ -26,6 +36,8 @@ app/javascript/packs/hello_vue.js
app/javascript/packs/hello.vue
```
- Add tree-shaking support - [#250](https://github.com/rails/webpacker/pull/250)
- Add initial test case by @kimquy [#259](https://github.com/rails/webpacker/pull/259)


## [1.1] - 2017-03-24

Expand Down
5 changes: 5 additions & 0 deletions lib/install/config/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"presets": [
["env", { "modules": false } ]
]
}
7 changes: 1 addition & 6 deletions lib/install/config/loaders/core/babel.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
module.exports = {
test: /\.js(\.erb)?$/,
exclude: /node_modules/,
loader: 'babel-loader',
options: {
presets: [
['env', { modules: false }]
]
}
loader: 'babel-loader'
}
8 changes: 1 addition & 7 deletions lib/install/config/loaders/installers/react.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
module.exports = {
test: /\.(js|jsx)?(\.erb)?$/,
exclude: /node_modules/,
loader: 'babel-loader',
options: {
presets: [
'react',
['env', { modules: false }]
]
}
loader: 'babel-loader'
}
8 changes: 1 addition & 7 deletions lib/install/config/loaders/installers/vue.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
module.exports = {
test: /.vue$/,
loader: 'vue-loader',
options: {
loaders: {
scss: 'vue-style-loader!css-loader!sass-loader',
sass: 'vue-style-loader!css-loader!sass-loader?indentedSyntax'
}
}
loader: 'vue-loader'
}
22 changes: 19 additions & 3 deletions lib/install/react.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
require "webpacker/configuration"

babelrc = Rails.root.join(".babelrc")

if File.exist?(babelrc)
react_babelrc = JSON.parse(File.read(babelrc))
react_babelrc["presets"] ||= []

unless react_babelrc["presets"].include?("react")
react_babelrc["presets"].push("react")
puts "Copying react preset to your .babelrc file"

File.open(babelrc, "w") do |f|
f.puts JSON.pretty_generate(react_babelrc)
end
end
else
puts "Copying .babelrc to app root directory"
copy_file "#{__dir__}/examples/react/.babelrc", ".babelrc"
end

puts "Copying react loader to #{Webpacker::Configuration.config_path}/loaders"
copy_file "#{__dir__}/config/loaders/installers/react.js", "config/webpack/loaders/react.js"

puts "Copying .babelrc to app root directory"
copy_file "#{__dir__}/examples/react/.babelrc", ".babelrc"

puts "Copying react example entry file to #{Webpacker::Configuration.entry_path}"
copy_file "#{__dir__}/examples/react/hello_react.jsx", "#{Webpacker::Configuration.entry_path}/hello_react.jsx"

Expand Down
17 changes: 11 additions & 6 deletions lib/install/template.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
# Install webpacker
puts "Copying webpack core config and loaders"
directory "#{__dir__}/config/webpack", "config/webpack"
directory "#{__dir__}/config/loaders/core", "config/webpack/loaders"
copy_file "#{__dir__}/config/.postcssrc.yml", ".postcssrc.yml"

puts "Copying .babelrc to app root directory"
copy_file "#{__dir__}/config/.babelrc", ".babelrc"

puts "Creating javascript app source directory"
directory "#{__dir__}/javascript", "app/javascript"
directory "#{__dir__}/javascript", "#{Webpacker::Configuration.source}"

puts "Copying binstubs"
template "#{__dir__}/bin/webpack-dev-server", "bin/webpack-dev-server"
template "#{__dir__}/bin/webpack-watcher", "bin/webpack-watcher"
template "#{__dir__}/bin/webpack", "bin/webpack"

if !File.exist?("bin/yarn")
puts "Copying yarn"
template "#{__dir__}/bin/yarn", "bin/yarn"
end
chmod "bin", 0755 & ~File.umask, verbose: false

puts "Copying webpack core config and loaders"
directory "#{__dir__}/config/webpack", "config/webpack"
directory "#{__dir__}/config/loaders/core", "config/webpack/loaders"
copy_file "#{__dir__}/config/.postcssrc.yml", ".postcssrc.yml"
chmod "bin", 0755 & ~File.umask, verbose: false

if File.exists?(".gitignore")
append_to_file ".gitignore", <<-EOS
Expand Down
6 changes: 5 additions & 1 deletion lib/webpacker/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ def output_path
Rails.root.join(paths.fetch(:output, "public"))
end

def source
paths.fetch(:source, "app/javascript")
end

def source_path
Rails.root.join(paths.fetch(:source, "app/javascript"))
Rails.root.join(source)
end
end

Expand Down