Skip to content
This repository was archived by the owner on Feb 15, 2025. It is now read-only.

Commit 195210f

Browse files
committed
Update to webpacker 3
1 parent 37d9172 commit 195210f

22 files changed

+674
-735
lines changed

.postcssrc.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
plugins:
2-
postcss-smart-import: {}
3-
precss: {}
42
autoprefixer: {}

Gemfile.lock

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ GEM
7979
mime-types-data (3.2016.0521)
8080
mini_portile2 (2.3.0)
8181
minitest (5.10.3)
82-
multi_json (1.12.1)
82+
multi_json (1.12.2)
8383
nio4r (2.1.0)
8484
nokogiri (1.8.1)
8585
mini_portile2 (~> 2.3.0)
@@ -89,6 +89,8 @@ GEM
8989
public_suffix (2.0.5)
9090
puma (3.9.1)
9191
rack (2.0.3)
92+
rack-proxy (0.6.2)
93+
rack
9294
rack-test (0.7.0)
9395
rack (>= 1.0, < 3)
9496
rails (5.1.4)
@@ -154,9 +156,9 @@ GEM
154156
activemodel (>= 5.0)
155157
bindex (>= 0.4.0)
156158
railties (>= 5.0)
157-
webpacker (2.0)
159+
webpacker (3.0.2)
158160
activesupport (>= 4.2)
159-
multi_json (~> 1.2)
161+
rack-proxy (>= 0.6.1)
160162
railties (>= 4.2)
161163
websocket-driver (0.6.5)
162164
websocket-extensions (>= 0.1.0)

bin/rails

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
#!/usr/bin/env ruby
2-
begin
3-
load File.expand_path('../spring', __FILE__)
4-
rescue LoadError => e
5-
raise unless e.message.include?('spring')
6-
end
72
APP_PATH = File.expand_path('../config/application', __dir__)
83
require_relative '../config/boot'
94
require 'rails/commands'

bin/rake

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
#!/usr/bin/env ruby
2-
begin
3-
load File.expand_path('../spring', __FILE__)
4-
rescue LoadError => e
5-
raise unless e.message.include?('spring')
6-
end
72
require_relative '../config/boot'
83
require 'rake'
94
Rake.application.run

config/webpack/configuration.js

Lines changed: 0 additions & 35 deletions
This file was deleted.

config/webpack/development.js

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,3 @@
1-
// Note: You must restart bin/webpack-dev-server for changes to take effect
1+
const environment = require('./environment')
22

3-
const merge = require('webpack-merge')
4-
const sharedConfig = require('./shared.js')
5-
const { settings, output } = require('./configuration.js')
6-
7-
module.exports = merge(sharedConfig, {
8-
devtool: 'inline-source-map',
9-
10-
stats: {
11-
errorDetails: true
12-
},
13-
14-
output: {
15-
pathinfo: true
16-
},
17-
18-
devServer: {
19-
clientLogLevel: 'none',
20-
https: settings.dev_server.https,
21-
host: settings.dev_server.host,
22-
port: settings.dev_server.port,
23-
contentBase: output.path,
24-
publicPath: output.publicPath,
25-
compress: true,
26-
headers: { 'Access-Control-Allow-Origin': '*' },
27-
historyApiFallback: true,
28-
watchOptions: {
29-
ignored: /node_modules/
30-
}
31-
}
32-
})
3+
module.exports = environment.toWebpackConfig()

config/webpack/environment.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const { environment } = require('@rails/webpacker')
2+
const merge = require('webpack-merge')
3+
const { resolve } = require('path')
4+
5+
const globalStylePaths = [
6+
resolve('app/assets/stylesheets'),
7+
resolve('node_modules')
8+
]
9+
10+
function enableCssModules(cssLoader) {
11+
const cssModuleOptions = {
12+
modules: true,
13+
sourceMap: true,
14+
localIdentName: '[name]__[local]___[hash:base64:5]'
15+
}
16+
cssLoader.options = merge(cssLoader.options, cssModuleOptions)
17+
}
18+
19+
// Replace ts-loader with awesome-typescript-loader
20+
environment.loaders.set('typescript', {
21+
test: /\.tsx?$/,
22+
exclude: /node_modules/,
23+
loader: 'awesome-typescript-loader'
24+
})
25+
26+
// Limit this loader to specific paths
27+
const styleLoader = environment.loaders.get('style')
28+
styleLoader.include = globalStylePaths
29+
30+
// Add modularized css loader for client components
31+
delete require.cache[require.resolve('@rails/webpacker/package/loaders/style')]
32+
const moduleStyleLoader = require('@rails/webpacker/package/loaders/style')
33+
moduleStyleLoader.exclude = globalStylePaths
34+
enableCssModules(moduleStyleLoader.use.find(el => el.loader === 'css-loader'))
35+
environment.loaders.set('moduleStyle', moduleStyleLoader)
36+
37+
module.exports = environment

config/webpack/extracttext.js

Lines changed: 0 additions & 23 deletions
This file was deleted.

config/webpack/loaders/assets.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

config/webpack/loaders/babel.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

config/webpack/loaders/coffee.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

config/webpack/loaders/erb.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

config/webpack/loaders/module-sass.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

config/webpack/loaders/react.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

config/webpack/loaders/sass.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

config/webpack/loaders/typescript.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

config/webpack/production.js

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,3 @@
1-
// Note: You must restart bin/webpack-dev-server for changes to take effect
1+
const environment = require('./environment')
22

3-
/* eslint global-require: 0 */
4-
5-
const webpack = require('webpack')
6-
const merge = require('webpack-merge')
7-
const CompressionPlugin = require('compression-webpack-plugin')
8-
const sharedConfig = require('./shared.js')
9-
10-
module.exports = merge(sharedConfig, {
11-
output: { filename: '[name]-[chunkhash].js' },
12-
devtool: 'source-map',
13-
stats: 'normal',
14-
15-
plugins: [
16-
new webpack.optimize.UglifyJsPlugin({
17-
minimize: true,
18-
sourceMap: true,
19-
20-
compress: {
21-
warnings: false
22-
},
23-
24-
output: {
25-
comments: false
26-
}
27-
}),
28-
29-
new CompressionPlugin({
30-
asset: '[path].gz[query]',
31-
algorithm: 'gzip',
32-
test: /\.(js|css|html|json|ico|svg|eot|otf|ttf)$/
33-
})
34-
]
35-
})
3+
module.exports = environment.toWebpackConfig()

config/webpack/shared.js

Lines changed: 0 additions & 63 deletions
This file was deleted.

config/webpack/test.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Note: You must restart bin/webpack-dev-server for changes to take effect
1+
const environment = require('./environment')
22

3-
const merge = require('webpack-merge')
4-
const sharedConfig = require('./shared.js')
5-
6-
module.exports = merge(sharedConfig, {})
3+
module.exports = environment.toWebpackConfig()

0 commit comments

Comments
 (0)