Skip to content

Commit

Permalink
Complete webpacker upgrade process
Browse files Browse the repository at this point in the history
- Depfu triggered a Rails webpacker upgrade without incident but
the official doc recommended certain steps:

https://github.com/rails/webpacker/blob/master/docs/v4-upgrade.md
https://webpack.js.org/migrate/4/

It appears that previous independent updates of babel etc. have
actually handled many of these steps.
  • Loading branch information
James Glover committed Mar 8, 2019
1 parent c3dce7f commit b5d7b62
Show file tree
Hide file tree
Showing 8 changed files with 2,373 additions and 75 deletions.
22 changes: 0 additions & 22 deletions .babelrc

This file was deleted.

4 changes: 0 additions & 4 deletions .postcssrc.yml

This file was deleted.

73 changes: 73 additions & 0 deletions bable.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
module.exports = function(api) {
var validEnv = ['development', 'test', 'production']
var currentEnv = api.env()
var isDevelopmentEnv = api.env('development')
var isProductionEnv = api.env('production')
var isTestEnv = api.env('test')

if (!validEnv.includes(currentEnv)) {
throw new Error(
'Please specify a valid `NODE_ENV` or ' +
'`BABEL_ENV` environment variables. Valid values are "development", ' +
'"test", and "production". Instead, received: ' +
JSON.stringify(currentEnv) +
'.'
)
}

return {
presets: [
isTestEnv && [
require('@babel/preset-env').default,
{
targets: {
node: 'current',
chrome: 49,
firefox: 52,
browsers: '> 1%'
}
}
],
(isProductionEnv || isDevelopmentEnv) && [
require('@babel/preset-env').default,
{
forceAllTransforms: true,
useBuiltIns: 'entry',
modules: false,
exclude: ['transform-typeof-symbol']
}
]
].filter(Boolean),
plugins: [
require('babel-plugin-macros'),
require('@babel/plugin-syntax-dynamic-import').default,
isTestEnv && require('babel-plugin-dynamic-import-node'),
require('@babel/plugin-transform-destructuring').default,
[
require('@babel/plugin-proposal-class-properties').default,
{
loose: true
}
],
[
require('@babel/plugin-proposal-object-rest-spread').default,
{
useBuiltIns: true
}
],
[
require('@babel/plugin-transform-runtime').default,
{
helpers: false,
regenerator: true
}
],
[
require('@babel/plugin-transform-regenerator').default,
{
async: false
}
]
].filter(Boolean)
}
}
13 changes: 0 additions & 13 deletions config/webpack/production.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,6 @@ module.exports = merge(sharedConfig, {
stats: 'normal',

plugins: [
// new webpack.optimize.UglifyJsPlugin({
// minimize: true,
// sourceMap: true,

// compress: {
// warnings: false
// },

// output: {
// comments: false
// }
// }),

new CompressionPlugin({
asset: '[path].gz[query]',
algorithm: 'gzip',
Expand Down
58 changes: 56 additions & 2 deletions config/webpacker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,78 @@
default: &default
source_path: app/javascript
source_entry_path: packs
public_root_path: public
public_output_path: packs
cache_path: tmp/cache/webpacker
check_yarn_integrity: false
webpack_compile_output: false

resolved_paths: []

# Reload manifest.json on all requests so we reload latest compiled packs
cache_manifest: false

# Extract and emit a css file
extract_css: true

static_assets_extensions:
- .jpg
- .jpeg
- .png
- .gif
- .tiff
- .ico
- .svg
- .eot
- .otf
- .ttf
- .woff
- .woff2

extensions:
- .erb
- .mjs
- .js
- .jsx
- .ts
- .vue
- .sass
- .scss
- .css
- .module.sass
- .module.scss
- .module.css
- .png
- .svg
- .gif
- .jpeg
- .jpg


development:
<<: *default

compile: true
check_yarn_integrity: true

# Reference: https://webpack.js.org/configuration/dev-server/
dev_server:
host: 0.0.0.0
port: 8080
https: false
host: localhost
port: 3035
public: localhost:3035
hmr: false
# Inline should be set to true if using HMR
inline: true
overlay: true
compress: true
disable_host_check: true
use_local_ip: false
quiet: false
headers:
'Access-Control-Allow-Origin': '*'
watch_options:
ignored: '**/node_modules/**'

test:
<<: *default
Expand All @@ -37,3 +83,11 @@ test:

production:
<<: *default
# Production depends on precompilation of packs prior to booting for performance.
compile: false

# Extract and emit a css file
extract_css: true

# Cache manifest.json for performance
cache_manifest: true
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"@babel/plugin-proposal-class-properties": "^7.1.0",
"@babel/plugin-syntax-dynamic-import": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@rails/webpacker": "^4.0.2",
"autoprefixer": "^7.1.1",
"axios": "^0.18.0",
"babel-loader": "8",
Expand Down
12 changes: 12 additions & 0 deletions postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
plugins: [
require('postcss-import'),
require('postcss-flexbugs-fixes'),
require('postcss-preset-env')({
autoprefixer: {
flexbox: 'no-2009'
},
stage: 3
})
]
}
Loading

0 comments on commit b5d7b62

Please sign in to comment.