-
Notifications
You must be signed in to change notification settings - Fork 759
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
Support singleton webpacker (3 and above) #777
Changes from 12 commits
392ec00
4531b1c
14865d8
80c03d8
8c7dcd8
cd74273
2b7cf68
d1e665e
ea8810e
5a78e5d
b960b9a
cc8528f
54f95b7
ed8a891
488a840
2c8ec5e
29c1d02
ca48da9
41b633f
a5f3da5
9b7af66
2492053
f33976a
1b210b0
72285ce
8c88a3b
4fad8b3
c587945
b6dc2aa
7b1b5ad
6324185
77536cd
253ccde
2805d9d
9390b09
4aa297f
f15b255
c61f74d
0c0b9bc
e3efcb8
0f75fe7
07afcb7
384a406
579367f
940f5dd
9437671
caf0827
f2330d9
e5bbe14
83fbdaf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
# This file was generated by Appraisal | ||
# This file shouldn't have turbolinks or sprockets in it | ||
|
||
source "http://rubygems.org" | ||
|
||
gem "rails", "~> 5.0.0" | ||
gem "webpacker", :github => "rails/webpacker" | ||
gem "webpacker", "~> 1.0" | ||
gem "therubyracer" | ||
|
||
gemspec :path => "../" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# This file was generated by Appraisal | ||
|
||
source "http://rubygems.org" | ||
|
||
gem "rails", "~> 5.0.0" | ||
gem "webpacker", ">= 3.0 " | ||
gem "therubyracer" | ||
|
||
gemspec :path => "../" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ class WebpackerManifestContainer | |
|
||
def find_asset(logical_path) | ||
# raises if not found | ||
asset_path = Webpacker::Manifest.lookup(logical_path).to_s | ||
asset_path = manifest.lookup(logical_path).to_s | ||
if asset_path.start_with?("http") | ||
# Get a file from the webpack-dev-server | ||
dev_server_asset = open(asset_path).read | ||
|
@@ -21,11 +21,23 @@ def find_asset(logical_path) | |
dev_server_asset | ||
else | ||
# Read the already-compiled pack: | ||
full_path = Webpacker::Manifest.lookup_path(logical_path).to_s | ||
full_path = file_path(logical_path).to_s | ||
File.read(full_path) | ||
end | ||
end | ||
|
||
def manifest | ||
Webpacker.respond_to?(:manifest) ? Webpacker.manifest : Webpacker::Manifest | ||
end | ||
|
||
def file_path path | ||
manifest.respond_to?(:lookup_path) ? manifest.lookup_path(path) : File.join(config.output_path, manifest.lookup(path).split('/')[2..-1]) | ||
end | ||
|
||
def config | ||
!!defined?(Webpacker::Configuration) ? Webpacker::Configuration : Webpacker.config | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this needs to be def config
Webpacker.respond_to?(:config) ? Webpacker.config : Webpacker::Configuration
end Because even in Webpacker 3, the |
||
end | ||
|
||
def self.compatible? | ||
!!defined?(Webpacker) | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,20 @@ | ||
// Note: You must restart bin/webpack-dev-server for changes to take effect | ||
try { | ||
const environment = require('./environment') | ||
|
||
const merge = require('webpack-merge') | ||
const sharedConfig = require('./shared.js') | ||
module.exports = environment.toWebpackConfig() | ||
} catch (e) { | ||
const merge = require('webpack-merge') | ||
const sharedConfig = require('./shared.js') | ||
|
||
module.exports = merge(sharedConfig, { | ||
devtool: 'sourcemap', | ||
module.exports = merge(sharedConfig, { | ||
devtool: 'sourcemap', | ||
|
||
stats: { | ||
errorDetails: true | ||
}, | ||
stats: { | ||
errorDetails: true | ||
}, | ||
|
||
output: { | ||
pathinfo: true | ||
} | ||
}) | ||
output: { | ||
pathinfo: true | ||
} | ||
}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const { environment } = require('@rails/webpacker') | ||
|
||
module.exports = environment |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,6 @@ development: | |
|
||
test: | ||
<<: *default | ||
manifest: manifest-test.json | ||
|
||
production: | ||
<<: *default |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,20 @@ | ||
// Note: You must restart bin/webpack-dev-server for changes to take effect | ||
try { | ||
const environment = require('./environment') | ||
|
||
/* eslint global-require: 0 */ | ||
module.exports = environment.toWebpackConfig() | ||
} catch (e) { | ||
const merge = require('webpack-merge') | ||
const sharedConfig = require('./shared.js') | ||
|
||
const webpack = require('webpack') | ||
const merge = require('webpack-merge') | ||
const CompressionPlugin = require('compression-webpack-plugin') | ||
const sharedConfig = require('./shared.js') | ||
module.exports = merge(sharedConfig, { | ||
devtool: 'sourcemap', | ||
|
||
module.exports = merge(sharedConfig, { | ||
output: { filename: '[name]-[chunkhash].js' }, | ||
stats: { | ||
errorDetails: true | ||
}, | ||
|
||
plugins: [ | ||
new webpack.optimize.UglifyJsPlugin(), | ||
new CompressionPlugin({ | ||
asset: '[path].gz[query]', | ||
algorithm: 'gzip', | ||
test: /\.(js|css|html|json|ico|svg|eot|otf|ttf)$/ | ||
}) | ||
] | ||
}) | ||
output: { | ||
pathinfo: true | ||
} | ||
}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,20 @@ | ||
// Note: You must restart bin/webpack-dev-server for changes to take effect | ||
try { | ||
const environment = require('./environment') | ||
|
||
const merge = require('webpack-merge') | ||
const sharedConfig = require('./shared.js') | ||
module.exports = environment.toWebpackConfig() | ||
} catch (e) { | ||
const merge = require('webpack-merge') | ||
const sharedConfig = require('./shared.js') | ||
|
||
module.exports = merge(sharedConfig, {}) | ||
module.exports = merge(sharedConfig, { | ||
devtool: 'sourcemap', | ||
|
||
stats: { | ||
errorDetails: true | ||
}, | ||
|
||
output: { | ||
pathinfo: true | ||
} | ||
}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Note: You must restart bin/webpack-dev-server for changes to take effect | ||
|
||
default: &default # ~ = Rails.root | ||
source_path: app/javascript # ~/:source | ||
source_entry_path: packs # ~/:source/:entry | ||
public_output_path: packs # ~/public/:output | ||
cache_path: tmp/cache/webpacker | ||
|
||
# Additional paths webpack should lookup modules | ||
# ['app/assets', 'engine/foo/app/assets'] | ||
resolved_paths: [] | ||
|
||
# Reload manifest.json on all requests so we reload latest compiled packs | ||
cache_manifest: false | ||
|
||
extensions: | ||
- .coffee | ||
- .erb | ||
- .js | ||
- .jsx | ||
- .ts | ||
- .vue | ||
- .sass | ||
- .scss | ||
- .css | ||
- .png | ||
- .svg | ||
- .gif | ||
- .jpeg | ||
- .jpg | ||
|
||
development: | ||
<<: *default | ||
compile: true | ||
|
||
dev_server: | ||
host: localhost | ||
port: 3035 | ||
hmr: false | ||
https: false | ||
|
||
test: | ||
<<: *default | ||
compile: true | ||
|
||
# Compile test packs to a separate directory | ||
public_output_path: packs-test | ||
|
||
production: | ||
<<: *default | ||
|
||
# Production demands on precompilation of packs prior to booting for performance. | ||
compile: false | ||
|
||
# Cache manifest.json for performance | ||
cache_manifest: true |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,15 +61,15 @@ def wait_to_ensure_asset_pipeline_detects_changes | |
|
||
if WebpackerHelpers.available? | ||
new_file_path = '../dummy/app/javascript/components/NewList.js' | ||
new_file_contents = <<-JS | ||
var React = require("react") | ||
module.exports = function() { return <span>"New List"</span> } | ||
JS | ||
new_file_contents = <<-HEREDOC | ||
var React = require("react") | ||
module.exports = function() { return <span>"New List"</span> } | ||
HEREDOC | ||
else | ||
new_file_path = '../dummy/app/assets/javascripts/components/ZZ_NewComponent.js.jsx' | ||
new_file_contents = <<-JS | ||
var NewList = function() { return <span>"New List"</span> } | ||
JS | ||
new_file_contents = <<-HEREDOC | ||
var NewList = function() { return <span>"New List"</span> } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like you might've messed up the indentation here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
HEREDOC | ||
end | ||
|
||
new_file_path = File.expand_path(new_file_path, __FILE__) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it works for me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works..... but is it correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is correct as-is:
Webpacker.config.source_entry_path
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Webpacker.config.source_entry_path
is the correct way to call this, as this is defined in webpacker.