webpacker 1.0 → 1.1
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/.eslintrc.js +14 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +124 -0
- data/.travis.yml +24 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +6 -6
- data/README.md +126 -19
- data/lib/install/angular.rb +18 -0
- data/lib/install/bin/webpack-dev-server.tt +23 -12
- data/lib/install/bin/webpack-watcher.tt +3 -0
- data/lib/install/bin/webpack.tt +33 -7
- data/lib/install/config/.postcssrc.yml +4 -0
- data/lib/install/config/loaders/core/assets.js +12 -0
- data/lib/install/config/loaders/core/babel.js +10 -0
- data/lib/install/config/loaders/core/coffee.js +4 -0
- data/lib/install/config/loaders/core/erb.js +9 -0
- data/lib/install/config/loaders/core/sass.js +9 -0
- data/lib/install/config/loaders/installers/angular.js +4 -0
- data/lib/install/config/loaders/installers/react.js +11 -0
- data/lib/install/config/loaders/installers/vue.js +10 -0
- data/lib/install/config/webpack/configuration.js +21 -0
- data/lib/install/config/webpack/development.js +16 -0
- data/lib/install/config/webpack/development.server.js +17 -0
- data/lib/install/config/webpack/development.server.yml +4 -0
- data/lib/install/config/webpack/paths.yml +19 -0
- data/lib/install/config/webpack/production.js +20 -0
- data/lib/install/config/webpack/shared.js +51 -0
- data/lib/install/{angular → examples/angular}/hello_angular.js +1 -1
- data/lib/install/{angular → examples/angular}/hello_angular/app/app.component.ts +0 -0
- data/lib/install/{angular → examples/angular}/hello_angular/app/app.module.ts +0 -0
- data/lib/install/{angular → examples/angular}/hello_angular/index.ts +0 -0
- data/lib/install/{angular → examples/angular}/hello_angular/polyfills.ts +0 -0
- data/lib/install/{angular → examples/angular}/tsconfig.json +0 -0
- data/lib/install/examples/react/.babelrc +3 -0
- data/lib/install/examples/react/hello_react.jsx +25 -0
- data/lib/install/examples/vue/app.vue +22 -0
- data/lib/install/examples/vue/hello_vue.js +19 -0
- data/lib/install/javascript/packs/application.js +1 -0
- data/lib/install/react.rb +15 -0
- data/lib/install/template.rb +20 -14
- data/lib/install/vue.rb +15 -0
- data/lib/tasks/installers.rake +21 -0
- data/lib/tasks/webpacker.rake +14 -107
- data/lib/tasks/webpacker/compile.rake +29 -0
- data/lib/tasks/webpacker/install.rake +12 -0
- data/lib/tasks/webpacker/verify_install.rake +16 -0
- data/lib/tasks/webpacker/yarn_install.rake +6 -0
- data/lib/webpacker.rb +1 -1
- data/lib/webpacker/configuration.rb +42 -0
- data/lib/webpacker/file_loader.rb +24 -0
- data/lib/webpacker/helper.rb +32 -3
- data/lib/webpacker/manifest.rb +29 -0
- data/lib/webpacker/railtie.rb +6 -16
- data/lib/webpacker/version.rb +3 -0
- data/package.json +28 -0
- data/webpacker.gemspec +15 -12
- data/yarn.lock +1014 -0
- metadata +50 -20
- data/lib/install/config/development.js +0 -24
- data/lib/install/config/production.js +0 -16
- data/lib/install/config/shared.js +0 -70
- data/lib/install/react/.babelrc +0 -3
- data/lib/install/react/hello_react.js +0 -16
- data/lib/webpacker/digests.rb +0 -42
- data/lib/webpacker/source.rb +0 -38
@@ -1,22 +1,33 @@
|
|
1
1
|
<%= shebang %>
|
2
|
+
$stdout.sync = true
|
2
3
|
|
3
|
-
|
4
|
-
|
4
|
+
require "shellwords"
|
5
|
+
require "yaml"
|
5
6
|
|
6
|
-
|
7
|
+
ENV["RAILS_ENV"] ||= "development"
|
8
|
+
RAILS_ENV = ENV["RAILS_ENV"]
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
-
WEBPACK_CONFIG = "#{APP_PATH}/config/webpack/#{NODE_ENV}.js"
|
10
|
+
ENV["NODE_ENV"] ||= RAILS_ENV
|
11
|
+
NODE_ENV = ENV["NODE_ENV"]
|
11
12
|
|
12
|
-
|
13
|
-
|
13
|
+
APP_PATH = File.expand_path("../", __dir__)
|
14
|
+
CONFIG_PATH = File.join(APP_PATH, "config/webpack/paths.yml")
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
begin
|
17
|
+
paths = YAML.load(File.read(CONFIG_PATH))
|
18
|
+
|
19
|
+
NODE_MODULES_PATH = File.join(APP_PATH.shellescape, paths["node_modules"])
|
20
|
+
WEBPACK_CONFIG_PATH = File.join(APP_PATH.shellescape, paths["config"])
|
21
|
+
|
22
|
+
WEBPACK_BIN = "#{NODE_MODULES_PATH}/.bin/webpack-dev-server"
|
23
|
+
DEV_SERVER_CONFIG = "#{WEBPACK_CONFIG_PATH}/development.server.js"
|
24
|
+
rescue Errno::ENOENT, NoMethodError
|
25
|
+
puts "Configuration not found in config/webpacker/paths.yml."
|
26
|
+
puts "Please run bundle exec rails webpacker:install to install webpacker"
|
27
|
+
exit!
|
18
28
|
end
|
19
29
|
|
20
30
|
Dir.chdir(APP_PATH) do
|
21
|
-
exec "
|
31
|
+
exec "NODE_PATH=#{NODE_MODULES_PATH} #{WEBPACK_BIN} --progress --color " \
|
32
|
+
"--config #{DEV_SERVER_CONFIG}"
|
22
33
|
end
|
data/lib/install/bin/webpack.tt
CHANGED
@@ -1,14 +1,40 @@
|
|
1
1
|
<%= shebang %>
|
2
|
+
$stdout.sync = true
|
2
3
|
|
3
|
-
|
4
|
-
|
4
|
+
require "shellwords"
|
5
|
+
require "yaml"
|
5
6
|
|
6
|
-
|
7
|
+
ENV["RAILS_ENV"] ||= "development"
|
8
|
+
RAILS_ENV = ENV["RAILS_ENV"]
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
-
|
10
|
+
ENV["NODE_ENV"] ||= RAILS_ENV
|
11
|
+
NODE_ENV = ENV["NODE_ENV"]
|
12
|
+
|
13
|
+
APP_PATH = File.expand_path("../", __dir__)
|
14
|
+
CONFIG_PATH = File.join(APP_PATH, "config/webpack/paths.yml")
|
15
|
+
DEV_SERVER_CONFIG_PATH = File.join(APP_PATH, "config/webpack/development.server.yml")
|
16
|
+
|
17
|
+
begin
|
18
|
+
paths = YAML.load(File.read(CONFIG_PATH))
|
19
|
+
dev_server = YAML.load(File.read(DEV_SERVER_CONFIG_PATH))
|
20
|
+
|
21
|
+
NODE_MODULES_PATH = File.join(APP_PATH.shellescape, paths["node_modules"])
|
22
|
+
WEBPACK_CONFIG_PATH = File.join(APP_PATH.shellescape, paths["config"])
|
23
|
+
|
24
|
+
if NODE_ENV == "development" && dev_server["enabled"]
|
25
|
+
puts "Warning: webpack-dev-server is currently enabled in #{DEV_SERVER_CONFIG_PATH}. " \
|
26
|
+
"Disable to serve assets directly from public/packs directory"
|
27
|
+
end
|
28
|
+
rescue Errno::ENOENT, NoMethodError
|
29
|
+
puts "Configuration not found in config/webpack/paths.yml or config/webpack/development.server.yml."
|
30
|
+
puts "Please run bundle exec rails webpacker:install to install webpacker"
|
31
|
+
exit!
|
32
|
+
end
|
33
|
+
|
34
|
+
WEBPACK_BIN = "#{NODE_MODULES_PATH}/.bin/webpack"
|
35
|
+
WEBPACK_CONFIG = "#{WEBPACK_CONFIG_PATH}/#{NODE_ENV}.js"
|
11
36
|
|
12
37
|
Dir.chdir(APP_PATH) do
|
13
|
-
exec "
|
38
|
+
exec "NODE_PATH=#{NODE_MODULES_PATH} #{WEBPACK_BIN} --config #{WEBPACK_CONFIG}" \
|
39
|
+
" #{ARGV.join(" ")}"
|
14
40
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
const { env, publicPath } = require('../configuration.js')
|
2
|
+
|
3
|
+
module.exports = {
|
4
|
+
test: /\.(jpeg|png|gif|svg|eot|ttf|woff|woff2)$/i,
|
5
|
+
use: [{
|
6
|
+
loader: 'file-loader',
|
7
|
+
options: {
|
8
|
+
publicPath,
|
9
|
+
name: env.NODE_ENV === 'production' ? '[name]-[hash].[ext]' : '[name].[ext]'
|
10
|
+
}
|
11
|
+
}]
|
12
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
// Common configuration for webpacker loaded from config/webpack/paths.yml
|
2
|
+
|
3
|
+
const { join, resolve } = require('path')
|
4
|
+
const { env } = require('process')
|
5
|
+
const { safeLoad } = require('js-yaml')
|
6
|
+
const { readFileSync } = require('fs')
|
7
|
+
|
8
|
+
const configPath = resolve('config', 'webpack')
|
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
|
+
const publicPath = env.NODE_ENV !== 'production' && devServer.enabled ?
|
13
|
+
`http://${devServer.host}:${devServer.port}/` : `/${paths.entry}/`
|
14
|
+
|
15
|
+
module.exports = {
|
16
|
+
devServer,
|
17
|
+
env,
|
18
|
+
paths,
|
19
|
+
loadersDir,
|
20
|
+
publicPath
|
21
|
+
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
// Note: You must restart bin/webpack-watcher for changes to take effect
|
2
|
+
|
3
|
+
const merge = require('webpack-merge')
|
4
|
+
const sharedConfig = require('./shared.js')
|
5
|
+
|
6
|
+
module.exports = merge(sharedConfig, {
|
7
|
+
devtool: 'sourcemap',
|
8
|
+
|
9
|
+
stats: {
|
10
|
+
errorDetails: true
|
11
|
+
},
|
12
|
+
|
13
|
+
output: {
|
14
|
+
pathinfo: true
|
15
|
+
}
|
16
|
+
})
|
@@ -0,0 +1,17 @@
|
|
1
|
+
// Note: You must restart bin/webpack-dev-server for changes to take effect
|
2
|
+
|
3
|
+
const { resolve } = require('path')
|
4
|
+
const merge = require('webpack-merge')
|
5
|
+
const devConfig = require('./development.js')
|
6
|
+
const { devServer, publicPath, paths } = require('./configuration.js')
|
7
|
+
|
8
|
+
module.exports = merge(devConfig, {
|
9
|
+
devServer: {
|
10
|
+
host: devServer.host,
|
11
|
+
port: devServer.port,
|
12
|
+
compress: true,
|
13
|
+
historyApiFallback: true,
|
14
|
+
contentBase: resolve(paths.output, paths.entry),
|
15
|
+
publicPath
|
16
|
+
}
|
17
|
+
})
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# Restart webpack-watcher or webpack-dev-server if you make changes here
|
2
|
+
config: config/webpack
|
3
|
+
entry: packs
|
4
|
+
output: public
|
5
|
+
node_modules: node_modules
|
6
|
+
source: app/javascript
|
7
|
+
extensions:
|
8
|
+
- .coffee
|
9
|
+
- .js
|
10
|
+
- .jsx
|
11
|
+
- .ts
|
12
|
+
- .vue
|
13
|
+
- .sass
|
14
|
+
- .scss
|
15
|
+
- .css
|
16
|
+
- .png
|
17
|
+
- .svg
|
18
|
+
- .gif
|
19
|
+
- .jpeg
|
@@ -0,0 +1,20 @@
|
|
1
|
+
/* eslint global-require: 0 */
|
2
|
+
// Note: You must run bin/webpack for changes to take effect
|
3
|
+
|
4
|
+
const webpack = require('webpack')
|
5
|
+
const merge = require('webpack-merge')
|
6
|
+
const CompressionPlugin = require('compression-webpack-plugin')
|
7
|
+
const sharedConfig = require('./shared.js')
|
8
|
+
|
9
|
+
module.exports = merge(sharedConfig, {
|
10
|
+
output: { filename: '[name]-[chunkhash].js' },
|
11
|
+
|
12
|
+
plugins: [
|
13
|
+
new webpack.optimize.UglifyJsPlugin(),
|
14
|
+
new CompressionPlugin({
|
15
|
+
asset: '[path].gz[query]',
|
16
|
+
algorithm: 'gzip',
|
17
|
+
test: /\.(js|css|svg|eot|ttf|woff|woff2)$/
|
18
|
+
})
|
19
|
+
]
|
20
|
+
})
|
@@ -0,0 +1,51 @@
|
|
1
|
+
// Note: You must restart bin/webpack-watcher for changes to take effect
|
2
|
+
/* eslint global-require: 0 */
|
3
|
+
/* eslint import/no-dynamic-require: 0 */
|
4
|
+
|
5
|
+
const webpack = require('webpack')
|
6
|
+
const { basename, join, resolve } = require('path')
|
7
|
+
const { sync } = require('glob')
|
8
|
+
const { readdirSync } = require('fs')
|
9
|
+
const ExtractTextPlugin = require('extract-text-webpack-plugin')
|
10
|
+
const ManifestPlugin = require('webpack-manifest-plugin')
|
11
|
+
const extname = require('path-complete-extname')
|
12
|
+
const { env, paths, publicPath, loadersDir } = require('./configuration.js')
|
13
|
+
|
14
|
+
const extensionGlob = `*{${paths.extensions.join(',')}}*`
|
15
|
+
const packPaths = sync(join(paths.source, paths.entry, extensionGlob))
|
16
|
+
|
17
|
+
module.exports = {
|
18
|
+
entry: packPaths.reduce(
|
19
|
+
(map, entry) => {
|
20
|
+
const localMap = map
|
21
|
+
localMap[basename(entry, extname(entry))] = resolve(entry)
|
22
|
+
return localMap
|
23
|
+
}, {}
|
24
|
+
),
|
25
|
+
|
26
|
+
output: { filename: '[name].js', path: resolve(paths.output, paths.entry) },
|
27
|
+
|
28
|
+
module: {
|
29
|
+
rules: readdirSync(loadersDir).map(file => (
|
30
|
+
require(join(loadersDir, file))
|
31
|
+
))
|
32
|
+
},
|
33
|
+
|
34
|
+
plugins: [
|
35
|
+
new webpack.EnvironmentPlugin(JSON.parse(JSON.stringify(env))),
|
36
|
+
new ExtractTextPlugin(env.NODE_ENV === 'production' ? '[name]-[hash].css' : '[name].css'),
|
37
|
+
new ManifestPlugin({ fileName: 'manifest.json', publicPath, writeToFileEmit: true })
|
38
|
+
],
|
39
|
+
|
40
|
+
resolve: {
|
41
|
+
extensions: paths.extensions,
|
42
|
+
modules: [
|
43
|
+
resolve(paths.source),
|
44
|
+
resolve(paths.node_modules)
|
45
|
+
]
|
46
|
+
},
|
47
|
+
|
48
|
+
resolveLoader: {
|
49
|
+
modules: [paths.node_modules]
|
50
|
+
}
|
51
|
+
}
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,25 @@
|
|
1
|
+
// Run this example by adding <%= javascript_pack_tag 'hello_react' %> to the head of your layout file,
|
2
|
+
// like app/views/layouts/application.html.erb. All it does is render <div>Hello React</div> at the bottom
|
3
|
+
// of the page.
|
4
|
+
|
5
|
+
import React from 'react'
|
6
|
+
import ReactDOM from 'react-dom'
|
7
|
+
|
8
|
+
const Hello = props => (
|
9
|
+
<div>Hello {props.name}!</div>
|
10
|
+
)
|
11
|
+
|
12
|
+
Hello.defaultProps = {
|
13
|
+
name: 'David'
|
14
|
+
}
|
15
|
+
|
16
|
+
Hello.propTypes = {
|
17
|
+
name: React.PropTypes.string
|
18
|
+
}
|
19
|
+
|
20
|
+
document.addEventListener('DOMContentLoaded', () => {
|
21
|
+
ReactDOM.render(
|
22
|
+
<Hello name="React" />,
|
23
|
+
document.body.appendChild(document.createElement('div')),
|
24
|
+
)
|
25
|
+
})
|
@@ -0,0 +1,22 @@
|
|
1
|
+
<template>
|
2
|
+
<div id="app">
|
3
|
+
<p>{{ message }}</p>
|
4
|
+
</div>
|
5
|
+
</template>
|
6
|
+
|
7
|
+
<script>
|
8
|
+
module.exports = {
|
9
|
+
data: function () {
|
10
|
+
return {
|
11
|
+
message: "Hello Vue!"
|
12
|
+
}
|
13
|
+
}
|
14
|
+
}
|
15
|
+
</script>
|
16
|
+
|
17
|
+
<style scoped>
|
18
|
+
p {
|
19
|
+
font-size: 2em;
|
20
|
+
text-align: center;
|
21
|
+
}
|
22
|
+
</style>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
/* eslint no-console: 0 */
|
2
|
+
// Run this example by adding <%= javascript_pack_tag 'hello_vue' %>
|
3
|
+
// to the head of your layout file,
|
4
|
+
// like app/views/layouts/application.html.erb.
|
5
|
+
// All it does is render <div>Hello Vue</div> at the bottom of the page.
|
6
|
+
|
7
|
+
import Vue from 'vue/dist/vue.esm'
|
8
|
+
import App from './app.vue'
|
9
|
+
|
10
|
+
document.addEventListener('DOMContentLoaded', () => {
|
11
|
+
document.body.appendChild(document.createElement('hello'))
|
12
|
+
const app = new Vue({
|
13
|
+
el: 'hello',
|
14
|
+
template: '<App/>',
|
15
|
+
components: { App }
|
16
|
+
})
|
17
|
+
|
18
|
+
console.log(app)
|
19
|
+
})
|