Skip to content
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

Supply ASSET_HOST to webpack for internal asset compilation #224

Merged
merged 1 commit into from
Apr 12, 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
9 changes: 7 additions & 2 deletions lib/install/config/webpack/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@ const configPath = resolve('config', 'webpack')
const loadersDir = join(__dirname, 'loaders')
const paths = safeLoad(readFileSync(join(configPath, 'paths.yml'), 'utf8'))[env.NODE_ENV]
const devServer = safeLoad(readFileSync(join(configPath, 'development.server.yml'), 'utf8'))[env.NODE_ENV]
const publicPath = env.NODE_ENV !== 'production' && devServer.enabled ?
`http://${devServer.host}:${devServer.port}/` : `/${paths.entry}/`

// Compute public path based on environment and ASSET_HOST in production
const ifHasCDN = env.ASSET_HOST !== undefined && env.NODE_ENV === 'production'
const devServerUrl = `http://${devServer.host}:${devServer.port}/${paths.entry}/`
const publicUrl = ifHasCDN ? `${env.ASSET_HOST}/${paths.entry}/` : `/${paths.entry}/`
const publicPath = env.NODE_ENV !== 'production' && devServer.enabled ? devServerUrl : publicUrl

module.exports = {
devServer,
env,
paths,
loadersDir,
publicUrl,
publicPath
}
6 changes: 5 additions & 1 deletion lib/install/config/webpack/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ module.exports = {
}, {}
),

output: { filename: '[name].js', path: resolve(paths.output, paths.entry) },
output: {
filename: '[name].js',
path: resolve(paths.output, paths.entry),
publicPath
},

module: {
rules: readdirSync(loadersDir).map(file => (
Expand Down
3 changes: 2 additions & 1 deletion lib/tasks/webpacker/compile.rake
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ namespace :webpacker do
desc "Compile javascript packs using webpack for production with digests"
task compile: ["webpacker:verify_install", :environment] do
puts "Compiling webpacker assets 🎉"
result = `NODE_ENV=#{Webpacker::Env.current} ./bin/webpack --json`
asset_host = Rails.application.config.action_controller.asset_host
result = `ASSET_HOST=#{asset_host} NODE_ENV=#{Webpacker::Env.current} ./bin/webpack --json`

unless $?.success?
puts JSON.parse(result)["errors"]
Expand Down