From f2018044863a931076ae2e5e7e17c9f1e952e395 Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Tue, 1 Dec 2020 17:58:33 +0100 Subject: [PATCH] Update webpack config to match newest webpacker gem --- .browserslistrc | 1 + .gitignore | 2 +- babel.config.js | 134 +++++++++--------- .../initializers/content_security_policy.rb | 5 + config/webpack/development.js | 6 +- config/webpack/environment.js | 14 +- config/webpack/production.js | 6 +- config/webpack/test.js | 6 +- config/webpacker.yml | 15 +- package.json | 1 - postcss.config.js | 22 +-- yarn.lock | 72 +++++----- 12 files changed, 142 insertions(+), 142 deletions(-) create mode 100644 .browserslistrc diff --git a/.browserslistrc b/.browserslistrc new file mode 100644 index 00000000..e94f8140 --- /dev/null +++ b/.browserslistrc @@ -0,0 +1 @@ +defaults diff --git a/.gitignore b/.gitignore index cb8562bf..55ac4898 100644 --- a/.gitignore +++ b/.gitignore @@ -22,9 +22,9 @@ /.vagrant *.iml *.DS_Store -/node_modules /public/packs /public/packs-test /node_modules +/yarn-error.log yarn-debug.log* .yarn-integrity diff --git a/babel.config.js b/babel.config.js index 3082558d..4df19493 100644 --- a/babel.config.js +++ b/babel.config.js @@ -1,70 +1,70 @@ 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') + 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) + - '.' - ) - } + 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' - } - } - ], - (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) - } -}; + return { + presets: [ + isTestEnv && [ + '@babel/preset-env', + { + targets: { + node: 'current' + } + } + ], + (isProductionEnv || isDevelopmentEnv) && [ + '@babel/preset-env', + { + forceAllTransforms: true, + useBuiltIns: 'entry', + corejs: 3, + modules: false, + exclude: ['transform-typeof-symbol'] + } + ] + ].filter(Boolean), + plugins: [ + 'babel-plugin-macros', + '@babel/plugin-syntax-dynamic-import', + isTestEnv && 'babel-plugin-dynamic-import-node', + '@babel/plugin-transform-destructuring', + [ + '@babel/plugin-proposal-class-properties', + { + loose: true + } + ], + [ + '@babel/plugin-proposal-object-rest-spread', + { + useBuiltIns: true + } + ], + [ + '@babel/plugin-transform-runtime', + { + helpers: false + } + ], + [ + '@babel/plugin-transform-regenerator', + { + async: false + } + ] + ].filter(Boolean) + } +} diff --git a/config/initializers/content_security_policy.rb b/config/initializers/content_security_policy.rb index d3bcaa5e..c161e929 100644 --- a/config/initializers/content_security_policy.rb +++ b/config/initializers/content_security_policy.rb @@ -11,6 +11,11 @@ # policy.object_src :none # policy.script_src :self, :https # policy.style_src :self, :https +# +# # You need to allow webpack-dev-server host as allowed origin for connect-src. +# # This can be done in Rails 5.2+ for development environment in the CSP initializer +# # config/initializers/content_security_policy.rb with a snippet like this: +# policy.connect_src :self, :https, "http://localhost:3035", "ws://localhost:3035" if Rails.env.development? # # Specify URI for violation reports # # policy.report_uri "/csp-violation-report-endpoint" diff --git a/config/webpack/development.js b/config/webpack/development.js index 9bee5c01..50209390 100644 --- a/config/webpack/development.js +++ b/config/webpack/development.js @@ -1,5 +1,5 @@ -process.env.NODE_ENV = process.env.NODE_ENV || 'development'; +process.env.NODE_ENV = process.env.NODE_ENV || 'development' -const environment = require('./environment'); +const environment = require('./environment') -module.exports = environment; +module.exports = environment diff --git a/config/webpack/environment.js b/config/webpack/environment.js index eeac00be..54e50536 100644 --- a/config/webpack/environment.js +++ b/config/webpack/environment.js @@ -4,9 +4,9 @@ Info for this file can be found github.com/rails/webpacker/blob/master/docs/webpack.md */ -const { environment } = require('@rails/webpacker'); -const { merge } = require('webpack-merge'); -const webpack = require('webpack'); +const { environment } = require('@rails/webpacker') +const { merge } = require('webpack-merge') +const webpack = require('webpack') // Add an additional plugin of your choosing : ProvidePlugin environment.plugins.prepend('Provide', new webpack.ProvidePlugin({ @@ -22,15 +22,15 @@ environment.plugins.prepend('Provide', new webpack.ProvidePlugin({ Sentry: '@sentry/browser', Sortable: 'sortablejs', }) -); +) -const envConfig = module.exports = environment; +const envConfig = module.exports = environment const aliasConfig = module.exports = { resolve: { alias: { jquery: 'jquery/src/jquery', } } -}; +} -module.exports = merge(envConfig.toWebpackConfig(), aliasConfig); +module.exports = merge(envConfig.toWebpackConfig(), aliasConfig) diff --git a/config/webpack/production.js b/config/webpack/production.js index ffd1a49c..1fddcfb4 100644 --- a/config/webpack/production.js +++ b/config/webpack/production.js @@ -1,5 +1,5 @@ -process.env.NODE_ENV = process.env.NODE_ENV || 'production'; +process.env.NODE_ENV = process.env.NODE_ENV || 'production' -const environment = require('./environment'); +const environment = require('./environment') -module.exports = environment; +module.exports = environment diff --git a/config/webpack/test.js b/config/webpack/test.js index 9bee5c01..50209390 100644 --- a/config/webpack/test.js +++ b/config/webpack/test.js @@ -1,5 +1,5 @@ -process.env.NODE_ENV = process.env.NODE_ENV || 'development'; +process.env.NODE_ENV = process.env.NODE_ENV || 'development' -const environment = require('./environment'); +const environment = require('./environment') -module.exports = environment; +module.exports = environment diff --git a/config/webpacker.yml b/config/webpacker.yml index a66d7d3e..549cd1d8 100644 --- a/config/webpacker.yml +++ b/config/webpacker.yml @@ -6,12 +6,11 @@ default: &default public_root_path: public public_output_path: packs cache_path: tmp/cache/webpacker - check_yarn_integrity: false webpack_compile_output: false # Additional paths webpack should lookup modules # ['app/assets', 'engine/foo/app/assets'] - resolved_paths: [] + additional_paths: [] # Reload manifest.json on all requests so we reload latest compiled packs cache_manifest: false @@ -52,15 +51,12 @@ development: <<: *default compile: true - # Verifies that versions and hashed value of the package contents in the project's package.json - check_yarn_integrity: true - # Reference: https://webpack.js.org/configuration/dev-server/ dev_server: https: false - host: 0.0.0.0 + host: localhost port: 3035 - public: 0.0.0.0:3035 + public: localhost:3035 hmr: false # Inline should be set to true if using HMR inline: true @@ -69,12 +65,11 @@ development: disable_host_check: true use_local_ip: false quiet: false + pretty: false headers: 'Access-Control-Allow-Origin': '*' watch_options: - ignored: /node_modules/ - # File Watcher might not work inside Vagrant - poll: true + ignored: '**/node_modules/**' test: diff --git a/package.json b/package.json index ef16ebc2..5afb7ac6 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,6 @@ "sortablejs": "^1.12.0", "underscore": "^1.12.0", "vis": "^4.21.0", - "webpack": "^4.44.2", "webpack-merge": "^5.4.0" }, "devDependencies": { diff --git a/postcss.config.js b/postcss.config.js index 6c6bb512..aa5998a8 100644 --- a/postcss.config.js +++ b/postcss.config.js @@ -1,12 +1,12 @@ module.exports = { - plugins: [ - require('postcss-import'), - require('postcss-flexbugs-fixes'), - require('postcss-preset-env')({ - autoprefixer: { - flexbox: 'no-2009' - }, - stage: 3 - }) - ] -}; + plugins: [ + require('postcss-import'), + require('postcss-flexbugs-fixes'), + require('postcss-preset-env')({ + autoprefixer: { + flexbox: 'no-2009' + }, + stage: 3 + }) + ] +} diff --git a/yarn.lock b/yarn.lock index b99090b6..9b46bf5c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -887,55 +887,55 @@ webpack-sources "^1.4.3" "@sentry/browser@^5.27.6": - version "5.27.6" - resolved "https://registry.yarnpkg.com/@sentry/browser/-/browser-5.27.6.tgz#54fe177e9986246586b0761eb38cbad1ad07ecb5" - integrity sha512-pqrojE2ZmLUVz7l/ogtogK0+M2pK3bigYm0fja7vG7F7kXnCAwqAHDYfkFXEvFI8WvNwH+niy28lSoV95lnm0Q== + version "5.28.0" + resolved "https://registry.yarnpkg.com/@sentry/browser/-/browser-5.28.0.tgz#f4c094bb97070442d95d51966a5e4dc8b92f586f" + integrity sha512-u1W47fgYFGWTV+RRQtNBzPZMXfR4MqCYSpuUVSpWQ+riITH7pvjG1cnBYDGT7+Q1s1wGrAL/9ElJfF795VVT9g== dependencies: - "@sentry/core" "5.27.6" - "@sentry/types" "5.27.6" - "@sentry/utils" "5.27.6" + "@sentry/core" "5.28.0" + "@sentry/types" "5.28.0" + "@sentry/utils" "5.28.0" tslib "^1.9.3" -"@sentry/core@5.27.6": - version "5.27.6" - resolved "https://registry.yarnpkg.com/@sentry/core/-/core-5.27.6.tgz#3ceeb58acd857f1e17d52d3087bfecb506adc1f7" - integrity sha512-izCS5iyc6HAfpW1AsGXLAKetx82C1Sq1siAh97tOlSK58PVJAEH/WMiej9WuZJxCDTOtj94QtoLflssrZyAtFg== +"@sentry/core@5.28.0": + version "5.28.0" + resolved "https://registry.yarnpkg.com/@sentry/core/-/core-5.28.0.tgz#2b5ee2b76f0ccd73545eac61c3c2d72d7c76f531" + integrity sha512-hLAUFauqX+v/ap8ATJFdp392ZvfFoR0Gb4pyRkzOeWWs5ZYuqyb9Dsjtwsb61HH/XHQGW/BKZJR2dgIjQq4JGA== dependencies: - "@sentry/hub" "5.27.6" - "@sentry/minimal" "5.27.6" - "@sentry/types" "5.27.6" - "@sentry/utils" "5.27.6" + "@sentry/hub" "5.28.0" + "@sentry/minimal" "5.28.0" + "@sentry/types" "5.28.0" + "@sentry/utils" "5.28.0" tslib "^1.9.3" -"@sentry/hub@5.27.6": - version "5.27.6" - resolved "https://registry.yarnpkg.com/@sentry/hub/-/hub-5.27.6.tgz#a94adbe32c45dda7ad5adf742b82e0a022eb9c2f" - integrity sha512-bOMky3iu7zEghSaWmTayfme5tCpUok841qDCGxGKuyAtOhBDsgGNS/ApNEEDF2fyX0oo4G1cHYPWhX90ZFf/xA== +"@sentry/hub@5.28.0": + version "5.28.0" + resolved "https://registry.yarnpkg.com/@sentry/hub/-/hub-5.28.0.tgz#6a00b1011c0492b6acbaf0e24961fbd1c7edd1c1" + integrity sha512-1k19yJJcKoHbw12FET35t0m86lx/X6eJ6r4qM13eb2WN/OpoFtsgs1IjQOhGFL3OfVMcfh800Lc57ga04RLjLA== dependencies: - "@sentry/types" "5.27.6" - "@sentry/utils" "5.27.6" + "@sentry/types" "5.28.0" + "@sentry/utils" "5.28.0" tslib "^1.9.3" -"@sentry/minimal@5.27.6": - version "5.27.6" - resolved "https://registry.yarnpkg.com/@sentry/minimal/-/minimal-5.27.6.tgz#783012ed94668be168f2b521e0ea6295c76ce2b0" - integrity sha512-pKhzVQX9nL4m1dcnb2i2Y47IWVNs+K3wiYLgCB9hl9+ApxppfOc+fquiFoCloST3IuaD4yly2TtbOJgAMWcMxQ== +"@sentry/minimal@5.28.0": + version "5.28.0" + resolved "https://registry.yarnpkg.com/@sentry/minimal/-/minimal-5.28.0.tgz#bfa63f5961988e6652207c77b3ea46d89f2d52bf" + integrity sha512-HzFrJx0xe5KETEZc7RxlH+1TfmH3q8w35ILOP5HGvk3+lG1DR25wHbMFmuUqNqVXrl26t0z32UBI30G1MxmTfA== dependencies: - "@sentry/hub" "5.27.6" - "@sentry/types" "5.27.6" + "@sentry/hub" "5.28.0" + "@sentry/types" "5.28.0" tslib "^1.9.3" -"@sentry/types@5.27.6": - version "5.27.6" - resolved "https://registry.yarnpkg.com/@sentry/types/-/types-5.27.6.tgz#b5054eafcb8ac11d4bc4787c7bc7fc113cad8b80" - integrity sha512-XOW9W8DrMk++4Hk7gWi9o5VR0o/GrqGfTKyFsHSIjqt2hL6kiMPvKeb2Hhmp7Iq37N2bDmRdWpM5m+68S2Jk6w== +"@sentry/types@5.28.0": + version "5.28.0" + resolved "https://registry.yarnpkg.com/@sentry/types/-/types-5.28.0.tgz#242131fef910bded53350a36ffd7df240cfb8dcf" + integrity sha512-nNhoZEXdqM2xivxJBrLhxtJ2+s6FfKXUw5yBf0Jf/RBrBnH5fggPNImmyfpOoysl72igWcMWk4nnfyP5iDrriQ== -"@sentry/utils@5.27.6": - version "5.27.6" - resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-5.27.6.tgz#cd8486469ae9716a21a4bc7e828e5aeee0ed9727" - integrity sha512-/QMVLv+zrTfiIj2PU+SodSbSzD5MmamMOaljkDsRIVsj6gpkm1/VG1g2+40TZ0FbQ4hCW2F+iR7cnqzZBNmchA== +"@sentry/utils@5.28.0": + version "5.28.0" + resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-5.28.0.tgz#a30e36afd7094ced8d585c9fde2df2636cca6cf5" + integrity sha512-LW+ReVw9JG6g8Bvp2I1ThMDPATlisvkde+1WykxGqRhu2YIO+PvWhnoFhr9RD0ia3rYVlJkgkuTshMbPJ8HVwA== dependencies: - "@sentry/types" "5.27.6" + "@sentry/types" "5.28.0" tslib "^1.9.3" "@types/glob@^7.1.1": @@ -7862,7 +7862,7 @@ webpack-sources@^1.0.0, webpack-sources@^1.1.0, webpack-sources@^1.4.0, webpack- source-list-map "^2.0.0" source-map "~0.6.1" -webpack@^4.44.1, webpack@^4.44.2: +webpack@^4.44.1: version "4.44.2" resolved "https://registry.yarnpkg.com/webpack/-/webpack-4.44.2.tgz#6bfe2b0af055c8b2d1e90ed2cd9363f841266b72" integrity sha512-6KJVGlCxYdISyurpQ0IPTklv+DULv05rs2hseIXer6D7KrUicRDLFb4IUM1S6LUAKypPM/nSiVSuv8jHu1m3/Q==