diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a0ab810e..1136136f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) @@ -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 diff --git a/lib/install/config/.babelrc b/lib/install/config/.babelrc new file mode 100644 index 000000000..a8211d329 --- /dev/null +++ b/lib/install/config/.babelrc @@ -0,0 +1,5 @@ +{ + "presets": [ + ["env", { "modules": false } ] + ] +} diff --git a/lib/install/config/loaders/core/babel.js b/lib/install/config/loaders/core/babel.js index 82481e15e..c608e708f 100644 --- a/lib/install/config/loaders/core/babel.js +++ b/lib/install/config/loaders/core/babel.js @@ -1,10 +1,5 @@ module.exports = { test: /\.js(\.erb)?$/, exclude: /node_modules/, - loader: 'babel-loader', - options: { - presets: [ - ['env', { modules: false }] - ] - } + loader: 'babel-loader' } diff --git a/lib/install/config/loaders/installers/react.js b/lib/install/config/loaders/installers/react.js index 065dc4e07..cfd641774 100644 --- a/lib/install/config/loaders/installers/react.js +++ b/lib/install/config/loaders/installers/react.js @@ -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' } diff --git a/lib/install/config/loaders/installers/vue.js b/lib/install/config/loaders/installers/vue.js index 7dbab0409..9a56758bb 100644 --- a/lib/install/config/loaders/installers/vue.js +++ b/lib/install/config/loaders/installers/vue.js @@ -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' } diff --git a/lib/install/react.rb b/lib/install/react.rb index b5f3b737f..5655882bd 100644 --- a/lib/install/react.rb +++ b/lib/install/react.rb @@ -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" diff --git a/lib/install/template.rb b/lib/install/template.rb index f51347b79..3f2533fba 100644 --- a/lib/install/template.rb +++ b/lib/install/template.rb @@ -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 diff --git a/lib/webpacker/configuration.rb b/lib/webpacker/configuration.rb index 9c01e794d..67282c3cc 100644 --- a/lib/webpacker/configuration.rb +++ b/lib/webpacker/configuration.rb @@ -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