webpacker 1.1 → 1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +6 -8
- data/CHANGELOG.md +64 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +68 -1
- data/README.md +42 -25
- data/Rakefile +11 -0
- data/lib/install/angular.rb +1 -1
- data/lib/install/bin/webpack-dev-server.tt +2 -2
- data/lib/install/bin/webpack.tt +2 -9
- data/lib/install/bin/yarn.tt +3 -2
- data/lib/install/config/.babelrc +5 -0
- data/lib/install/config/loaders/core/assets.js +1 -1
- data/lib/install/config/loaders/core/babel.js +1 -6
- data/lib/install/config/loaders/core/erb.js +1 -1
- data/lib/install/config/loaders/core/sass.js +6 -1
- data/lib/install/config/loaders/installers/react.js +1 -7
- data/lib/install/config/loaders/installers/vue.js +4 -2
- data/lib/install/config/webpack/configuration.js +9 -4
- data/lib/install/config/webpack/development.js +1 -1
- data/lib/install/config/webpack/development.server.yml +17 -4
- data/lib/install/config/webpack/paths.yml +33 -19
- data/lib/install/config/webpack/production.js +2 -1
- data/lib/install/config/webpack/shared.js +13 -10
- data/lib/install/config/webpack/test.js +6 -0
- data/lib/install/examples/react/.babelrc +4 -1
- data/lib/install/examples/react/hello_react.jsx +2 -1
- data/lib/install/examples/vue/app.vue +1 -1
- data/lib/install/react.rb +20 -4
- data/lib/install/template.rb +21 -9
- data/lib/install/vue.rb +1 -1
- data/lib/tasks/installers.rake +2 -2
- data/lib/tasks/webpacker.rake +2 -0
- data/lib/tasks/webpacker/check_node.rake +19 -0
- data/lib/tasks/webpacker/check_yarn.rake +12 -0
- data/lib/tasks/webpacker/clobber.rake +17 -0
- data/lib/tasks/webpacker/compile.rake +15 -2
- data/lib/tasks/webpacker/install.rake +3 -3
- data/lib/tasks/webpacker/verify_install.rake +1 -1
- data/lib/webpacker.rb +5 -0
- data/lib/webpacker/configuration.rb +15 -6
- data/lib/webpacker/env.rb +27 -0
- data/lib/webpacker/manifest.rb +6 -1
- data/lib/webpacker/railtie.rb +6 -4
- data/lib/webpacker/version.rb +1 -1
- data/package.json +4 -1
- data/test/env_test.rb +16 -0
- data/test/webpacker_test.rb +14 -0
- data/webpacker.gemspec +2 -2
- metadata +18 -5
- data/lib/install/bin/webpack-watcher.tt +0 -10
@@ -1,9 +1,14 @@
|
|
1
1
|
const ExtractTextPlugin = require('extract-text-webpack-plugin')
|
2
|
+
const { env } = require('../configuration.js')
|
2
3
|
|
3
4
|
module.exports = {
|
4
5
|
test: /\.(scss|sass|css)$/i,
|
5
6
|
use: ExtractTextPlugin.extract({
|
6
7
|
fallback: 'style-loader',
|
7
|
-
use: [
|
8
|
+
use: [
|
9
|
+
{ loader: 'css-loader', options: { minimize: env.NODE_ENV === 'production' } },
|
10
|
+
'postcss-loader',
|
11
|
+
'sass-loader'
|
12
|
+
]
|
8
13
|
})
|
9
14
|
}
|
@@ -3,8 +3,10 @@ module.exports = {
|
|
3
3
|
loader: 'vue-loader',
|
4
4
|
options: {
|
5
5
|
loaders: {
|
6
|
-
|
7
|
-
|
6
|
+
js: 'babel-loader',
|
7
|
+
file: 'file-loader',
|
8
|
+
scss: 'vue-style-loader!css-loader!postcss-loader!sass-loader',
|
9
|
+
sass: 'vue-style-loader!css-loader!postcss-loader!sass-loader?indentedSyntax'
|
8
10
|
}
|
9
11
|
}
|
10
12
|
}
|
@@ -7,15 +7,20 @@ const { readFileSync } = require('fs')
|
|
7
7
|
|
8
8
|
const configPath = resolve('config', 'webpack')
|
9
9
|
const loadersDir = join(__dirname, 'loaders')
|
10
|
-
const paths = safeLoad(readFileSync(join(configPath, 'paths.yml'), 'utf8'))
|
11
|
-
const devServer = safeLoad(readFileSync(join(configPath, 'development.server.yml'), 'utf8'))
|
12
|
-
|
13
|
-
|
10
|
+
const paths = safeLoad(readFileSync(join(configPath, 'paths.yml'), 'utf8'))[env.NODE_ENV]
|
11
|
+
const devServer = safeLoad(readFileSync(join(configPath, 'development.server.yml'), 'utf8'))[env.NODE_ENV]
|
12
|
+
|
13
|
+
// Compute public path based on environment and ASSET_HOST in production
|
14
|
+
const ifHasCDN = env.ASSET_HOST !== undefined && env.NODE_ENV === 'production'
|
15
|
+
const devServerUrl = `http://${devServer.host}:${devServer.port}/${paths.entry}/`
|
16
|
+
const publicUrl = ifHasCDN ? `${env.ASSET_HOST}/${paths.entry}/` : `/${paths.entry}/`
|
17
|
+
const publicPath = env.NODE_ENV !== 'production' ? devServerUrl : publicUrl
|
14
18
|
|
15
19
|
module.exports = {
|
16
20
|
devServer,
|
17
21
|
env,
|
18
22
|
paths,
|
19
23
|
loadersDir,
|
24
|
+
publicUrl,
|
20
25
|
publicPath
|
21
26
|
}
|
@@ -1,4 +1,17 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
# Note: You must restart bin/webpack-dev-server for changes to take effect
|
2
|
+
|
3
|
+
default: &default
|
4
|
+
enabled: true
|
5
|
+
host: localhost
|
6
|
+
port: 8080
|
7
|
+
|
8
|
+
development:
|
9
|
+
<<: *default
|
10
|
+
|
11
|
+
test:
|
12
|
+
<<: *default
|
13
|
+
enabled: false
|
14
|
+
|
15
|
+
production:
|
16
|
+
<<: *default
|
17
|
+
enabled: false
|
@@ -1,19 +1,33 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
1
|
+
# Note: You must restart bin/webpack-dev-server for changes to take effect
|
2
|
+
|
3
|
+
default: &default
|
4
|
+
config: config/webpack
|
5
|
+
entry: packs
|
6
|
+
output: public
|
7
|
+
manifest: manifest.json
|
8
|
+
node_modules: node_modules
|
9
|
+
source: app/javascript
|
10
|
+
extensions:
|
11
|
+
- .coffee
|
12
|
+
- .js
|
13
|
+
- .jsx
|
14
|
+
- .ts
|
15
|
+
- .vue
|
16
|
+
- .sass
|
17
|
+
- .scss
|
18
|
+
- .css
|
19
|
+
- .png
|
20
|
+
- .svg
|
21
|
+
- .gif
|
22
|
+
- .jpeg
|
23
|
+
- .jpg
|
24
|
+
|
25
|
+
development:
|
26
|
+
<<: *default
|
27
|
+
|
28
|
+
test:
|
29
|
+
<<: *default
|
30
|
+
manifest: manifest-test.json
|
31
|
+
|
32
|
+
production:
|
33
|
+
<<: *default
|
@@ -1,40 +1,43 @@
|
|
1
|
-
// Note: You must restart bin/webpack-
|
1
|
+
// Note: You must restart bin/webpack-dev-server for changes to take effect
|
2
|
+
|
2
3
|
/* eslint global-require: 0 */
|
3
4
|
/* eslint import/no-dynamic-require: 0 */
|
4
5
|
|
5
6
|
const webpack = require('webpack')
|
6
|
-
const { basename, join, resolve } = require('path')
|
7
|
+
const { basename, dirname, join, relative, resolve } = require('path')
|
7
8
|
const { sync } = require('glob')
|
8
|
-
const { readdirSync } = require('fs')
|
9
9
|
const ExtractTextPlugin = require('extract-text-webpack-plugin')
|
10
10
|
const ManifestPlugin = require('webpack-manifest-plugin')
|
11
11
|
const extname = require('path-complete-extname')
|
12
12
|
const { env, paths, publicPath, loadersDir } = require('./configuration.js')
|
13
13
|
|
14
|
-
const extensionGlob =
|
14
|
+
const extensionGlob = `**/*{${paths.extensions.join(',')}}*`
|
15
15
|
const packPaths = sync(join(paths.source, paths.entry, extensionGlob))
|
16
16
|
|
17
17
|
module.exports = {
|
18
18
|
entry: packPaths.reduce(
|
19
19
|
(map, entry) => {
|
20
20
|
const localMap = map
|
21
|
-
|
21
|
+
const namespace = relative(join(paths.source, paths.entry), dirname(entry))
|
22
|
+
localMap[join(namespace, basename(entry, extname(entry)))] = resolve(entry)
|
22
23
|
return localMap
|
23
24
|
}, {}
|
24
25
|
),
|
25
26
|
|
26
|
-
output: {
|
27
|
+
output: {
|
28
|
+
filename: '[name].js',
|
29
|
+
path: resolve(paths.output, paths.entry),
|
30
|
+
publicPath
|
31
|
+
},
|
27
32
|
|
28
33
|
module: {
|
29
|
-
rules:
|
30
|
-
require(join(loadersDir, file))
|
31
|
-
))
|
34
|
+
rules: sync(join(loadersDir, '*.js')).map(loader => require(loader))
|
32
35
|
},
|
33
36
|
|
34
37
|
plugins: [
|
35
38
|
new webpack.EnvironmentPlugin(JSON.parse(JSON.stringify(env))),
|
36
39
|
new ExtractTextPlugin(env.NODE_ENV === 'production' ? '[name]-[hash].css' : '[name].css'),
|
37
|
-
new ManifestPlugin({ fileName:
|
40
|
+
new ManifestPlugin({ fileName: paths.manifest, publicPath, writeToFileEmit: true })
|
38
41
|
],
|
39
42
|
|
40
43
|
resolve: {
|
@@ -4,6 +4,7 @@
|
|
4
4
|
|
5
5
|
import React from 'react'
|
6
6
|
import ReactDOM from 'react-dom'
|
7
|
+
import PropTypes from 'prop-types'
|
7
8
|
|
8
9
|
const Hello = props => (
|
9
10
|
<div>Hello {props.name}!</div>
|
@@ -14,7 +15,7 @@ Hello.defaultProps = {
|
|
14
15
|
}
|
15
16
|
|
16
17
|
Hello.propTypes = {
|
17
|
-
name:
|
18
|
+
name: PropTypes.string
|
18
19
|
}
|
19
20
|
|
20
21
|
document.addEventListener('DOMContentLoaded', () => {
|
data/lib/install/react.rb
CHANGED
@@ -1,15 +1,31 @@
|
|
1
1
|
require "webpacker/configuration"
|
2
2
|
|
3
|
+
babelrc = Rails.root.join(".babelrc")
|
4
|
+
|
5
|
+
if File.exist?(babelrc)
|
6
|
+
react_babelrc = JSON.parse(File.read(babelrc))
|
7
|
+
react_babelrc["presets"] ||= []
|
8
|
+
|
9
|
+
unless react_babelrc["presets"].include?("react")
|
10
|
+
react_babelrc["presets"].push("react")
|
11
|
+
puts "Copying react preset to your .babelrc file"
|
12
|
+
|
13
|
+
File.open(babelrc, "w") do |f|
|
14
|
+
f.puts JSON.pretty_generate(react_babelrc)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
else
|
18
|
+
puts "Copying .babelrc to app root directory"
|
19
|
+
copy_file "#{__dir__}/examples/react/.babelrc", ".babelrc"
|
20
|
+
end
|
21
|
+
|
3
22
|
puts "Copying react loader to #{Webpacker::Configuration.config_path}/loaders"
|
4
23
|
copy_file "#{__dir__}/config/loaders/installers/react.js", "config/webpack/loaders/react.js"
|
5
24
|
|
6
|
-
puts "Copying .babelrc to app root directory"
|
7
|
-
copy_file "#{__dir__}/examples/react/.babelrc", ".babelrc"
|
8
|
-
|
9
25
|
puts "Copying react example entry file to #{Webpacker::Configuration.entry_path}"
|
10
26
|
copy_file "#{__dir__}/examples/react/hello_react.jsx", "#{Webpacker::Configuration.entry_path}/hello_react.jsx"
|
11
27
|
|
12
28
|
puts "Installing all react dependencies"
|
13
|
-
run "./bin/yarn add react react-dom babel-preset-react"
|
29
|
+
run "./bin/yarn add react react-dom babel-preset-react prop-types"
|
14
30
|
|
15
31
|
puts "Webpacker now supports react.js 🎉"
|
data/lib/install/template.rb
CHANGED
@@ -1,24 +1,36 @@
|
|
1
1
|
# Install webpacker
|
2
|
-
puts "Creating javascript app source directory"
|
3
|
-
directory "#{__dir__}/javascript", "app/javascript"
|
4
|
-
|
5
|
-
puts "Copying binstubs"
|
6
|
-
directory "#{__dir__}/bin", "bin"
|
7
|
-
chmod "bin", 0755 & ~File.umask, verbose: false
|
8
|
-
|
9
2
|
puts "Copying webpack core config and loaders"
|
10
3
|
directory "#{__dir__}/config/webpack", "config/webpack"
|
11
4
|
directory "#{__dir__}/config/loaders/core", "config/webpack/loaders"
|
12
5
|
copy_file "#{__dir__}/config/.postcssrc.yml", ".postcssrc.yml"
|
13
6
|
|
14
|
-
|
7
|
+
puts "Copying .babelrc to app root directory"
|
8
|
+
copy_file "#{__dir__}/config/.babelrc", ".babelrc"
|
9
|
+
|
10
|
+
puts "Creating javascript app source directory"
|
11
|
+
directory "#{__dir__}/javascript", "#{Webpacker::Configuration.source}"
|
12
|
+
|
13
|
+
puts "Copying binstubs"
|
14
|
+
template "#{__dir__}/bin/webpack-dev-server", "bin/webpack-dev-server"
|
15
|
+
template "#{__dir__}/bin/webpack", "bin/webpack"
|
16
|
+
|
17
|
+
if !File.exist?("bin/yarn")
|
18
|
+
puts "Copying yarn"
|
19
|
+
template "#{__dir__}/bin/yarn", "bin/yarn"
|
20
|
+
end
|
21
|
+
|
22
|
+
chmod "bin", 0755 & ~File.umask, verbose: false
|
23
|
+
|
24
|
+
if File.exists?(".gitignore")
|
25
|
+
append_to_file ".gitignore", <<-EOS
|
15
26
|
/public/packs
|
16
27
|
/node_modules
|
17
28
|
EOS
|
29
|
+
end
|
18
30
|
|
19
31
|
puts "Installing all JavaScript dependencies"
|
20
32
|
run "./bin/yarn add webpack webpack-merge js-yaml path-complete-extname " \
|
21
|
-
"webpack-manifest-plugin babel-loader coffee-loader coffee-script " \
|
33
|
+
"webpack-manifest-plugin babel-loader@7.x coffee-loader coffee-script " \
|
22
34
|
"babel-core babel-preset-env compression-webpack-plugin rails-erb-loader glob " \
|
23
35
|
"extract-text-webpack-plugin node-sass file-loader sass-loader css-loader style-loader " \
|
24
36
|
"postcss-loader autoprefixer postcss-smart-import precss"
|
data/lib/install/vue.rb
CHANGED
@@ -10,6 +10,6 @@ puts "Copying vue app file to #{Webpacker::Configuration.entry_path}"
|
|
10
10
|
copy_file "#{__dir__}/examples/vue/app.vue", "#{Webpacker::Configuration.entry_path}/app.vue"
|
11
11
|
|
12
12
|
puts "Installing all vue dependencies"
|
13
|
-
run "./bin/yarn add vue vue-loader vue-template-compiler
|
13
|
+
run "./bin/yarn add vue vue-loader vue-template-compiler"
|
14
14
|
|
15
15
|
puts "Webpacker now supports vue.js 🎉"
|
data/lib/tasks/installers.rake
CHANGED
@@ -11,9 +11,9 @@ namespace :webpacker do
|
|
11
11
|
task task_name => ["webpacker:verify_install"] do
|
12
12
|
template = File.expand_path("../install/#{task_name}.rb", __dir__)
|
13
13
|
if Rails::VERSION::MAJOR >= 5
|
14
|
-
exec "./bin/rails app:template LOCATION=#{template}"
|
14
|
+
exec "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{template}"
|
15
15
|
else
|
16
|
-
exec "./bin/rake rails:template LOCATION=#{template}"
|
16
|
+
exec "#{RbConfig.ruby} ./bin/rake rails:template LOCATION=#{template}"
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
data/lib/tasks/webpacker.rake
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
tasks = {
|
2
2
|
"webpacker:install" => "Installs and setup webpack with yarn",
|
3
3
|
"webpacker:compile" => "Compiles webpack bundles based on environment",
|
4
|
+
"webpacker:check_node" => "Verifies if Node.js is installed",
|
5
|
+
"webpacker:check_yarn" => "Verifies if yarn is installed",
|
4
6
|
"webpacker:verify_install" => "Verifies if webpacker is installed",
|
5
7
|
"webpacker:yarn_install" => "Support for older Rails versions. Install all JavaScript dependencies as specified via Yarn",
|
6
8
|
"webpacker:install:react" => "Installs and setup example react component",
|
@@ -0,0 +1,19 @@
|
|
1
|
+
namespace :webpacker do
|
2
|
+
desc "Verifies if Node.js is installed"
|
3
|
+
task :check_node do
|
4
|
+
begin
|
5
|
+
node_version = `node -v`
|
6
|
+
required_node_version = "6.4"
|
7
|
+
|
8
|
+
raise Errno::ENOENT if node_version.blank?
|
9
|
+
if Gem::Version.new(node_version.strip.tr("v", "")) < Gem::Version.new(required_node_version)
|
10
|
+
puts "Webpacker requires Node.js >= v#{required_node_version} and you are using #{node_version}"
|
11
|
+
puts "Please upgrade Node.js https://nodejs.org/en/download/"
|
12
|
+
puts "Exiting!" && exit!
|
13
|
+
end
|
14
|
+
rescue Errno::ENOENT
|
15
|
+
puts "Node.js not installed. Please download and install Node.js https://nodejs.org/en/download/"
|
16
|
+
puts "Exiting!" && exit!
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
namespace :webpacker do
|
2
|
+
desc "Verifies if yarn is installed"
|
3
|
+
task :check_yarn do
|
4
|
+
begin
|
5
|
+
version = `yarn --version`
|
6
|
+
raise Errno::ENOENT if version.blank?
|
7
|
+
rescue Errno::ENOENT
|
8
|
+
puts "Webpacker requires yarn. Please download and install Yarn https://yarnpkg.com/lang/en/docs/install/"
|
9
|
+
puts "Exiting!" && exit!
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "webpacker/configuration"
|
2
|
+
|
3
|
+
namespace :webpacker do
|
4
|
+
desc "Remove the webpack compiled output directory"
|
5
|
+
task clobber: ["webpacker:verify_install", :environment] do
|
6
|
+
packs_path = Webpacker::Configuration.packs_path
|
7
|
+
FileUtils.rm_r(packs_path) if File.exist?(packs_path)
|
8
|
+
puts "Removed webpack output path directory #{packs_path}"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
# Run clobber if the assets:clobber is run
|
13
|
+
if Rake::Task.task_defined?("assets:clobber")
|
14
|
+
Rake::Task["assets:clobber"].enhance do
|
15
|
+
Rake::Task["webpacker:clobber"].invoke
|
16
|
+
end
|
17
|
+
end
|