Merge pull request #3117 from tchak/update-babel
Update webpacker (babel7)
This commit is contained in:
commit
bd519835cd
9 changed files with 2205 additions and 3315 deletions
42
.babelrc
42
.babelrc
|
@ -1,9 +1,10 @@
|
||||||
{
|
{
|
||||||
"presets": [
|
"presets": [
|
||||||
["env", {
|
[
|
||||||
|
"@babel/env",
|
||||||
|
{
|
||||||
"modules": false,
|
"modules": false,
|
||||||
"targets": {
|
"targets": {
|
||||||
// See config/browser.rb
|
|
||||||
"browsers": [
|
"browsers": [
|
||||||
"> 1%",
|
"> 1%",
|
||||||
"Chrome >= 50",
|
"Chrome >= 50",
|
||||||
|
@ -16,13 +17,38 @@
|
||||||
],
|
],
|
||||||
"uglify": true
|
"uglify": true
|
||||||
},
|
},
|
||||||
"useBuiltIns": true
|
"forceAllTransforms": true,
|
||||||
}]
|
"useBuiltIns": "entry"
|
||||||
|
}
|
||||||
|
]
|
||||||
],
|
],
|
||||||
|
|
||||||
"plugins": [
|
"plugins": [
|
||||||
"syntax-dynamic-import",
|
"@babel/plugin-transform-destructuring",
|
||||||
"transform-object-rest-spread",
|
"@babel/plugin-syntax-dynamic-import",
|
||||||
["transform-class-properties", { "spec": true }]
|
[
|
||||||
|
"@babel/plugin-proposal-object-rest-spread",
|
||||||
|
{
|
||||||
|
"useBuiltIns": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"@babel/plugin-transform-runtime",
|
||||||
|
{
|
||||||
|
"helpers": false,
|
||||||
|
"regenerator": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"@babel/plugin-transform-regenerator",
|
||||||
|
{
|
||||||
|
"async": false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"@babel/plugin-proposal-class-properties",
|
||||||
|
{
|
||||||
|
"loose": true
|
||||||
|
}
|
||||||
|
]
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
import '../shared/polyfills';
|
import '../shared/polyfills';
|
||||||
import Turbolinks from 'turbolinks';
|
import Turbolinks from 'turbolinks';
|
||||||
import Rails from 'rails-ujs';
|
import Rails from 'rails-ujs';
|
||||||
import ActiveStorage from '../shared/activestorage/ujs';
|
import * as ActiveStorage from 'activestorage';
|
||||||
import jQuery from 'jquery';
|
import jQuery from 'jquery';
|
||||||
|
|
||||||
|
import '../shared/activestorage/progress';
|
||||||
import '../shared/sentry';
|
import '../shared/sentry';
|
||||||
import '../shared/rails-ujs-fix';
|
import '../shared/rails-ujs-fix';
|
||||||
import '../shared/safari-11-file-xhr-workaround';
|
import '../shared/safari-11-file-xhr-workaround';
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
import '../shared/polyfills';
|
import '../shared/polyfills';
|
||||||
import Turbolinks from 'turbolinks';
|
import Turbolinks from 'turbolinks';
|
||||||
import Rails from 'rails-ujs';
|
import Rails from 'rails-ujs';
|
||||||
import ActiveStorage from '../shared/activestorage/ujs';
|
import * as ActiveStorage from 'activestorage';
|
||||||
import Chartkick from 'chartkick';
|
import Chartkick from 'chartkick';
|
||||||
import Highcharts from 'highcharts';
|
import Highcharts from 'highcharts';
|
||||||
|
|
||||||
|
import '../shared/activestorage/progress';
|
||||||
import '../shared/sentry';
|
import '../shared/sentry';
|
||||||
import '../shared/rails-ujs-fix';
|
import '../shared/rails-ujs-fix';
|
||||||
import '../shared/safari-11-file-xhr-workaround';
|
import '../shared/safari-11-file-xhr-workaround';
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// Include runtime-polyfills for older browsers.
|
// Include runtime-polyfills for older browsers.
|
||||||
// Due to .babelrc's 'useBuiltIns', only polyfills actually
|
// Due to .babelrc's 'useBuiltIns', only polyfills actually
|
||||||
// required by the browsers we support will be included.
|
// required by the browsers we support will be included.
|
||||||
import 'babel-polyfill';
|
import '@babel/polyfill';
|
||||||
|
|
||||||
// This file is copied from mailjet. We serve here a copy of it ourselves
|
// This file is copied from mailjet. We serve here a copy of it ourselves
|
||||||
// to avoid loading javascript files from other domains on the frontpage.
|
// to avoid loading javascript files from other domains on the frontpage.
|
||||||
|
|
|
@ -1,105 +0,0 @@
|
||||||
import { DirectUploadsController } from 'activestorage/src/direct_uploads_controller';
|
|
||||||
import { findElement } from 'activestorage/src/helpers';
|
|
||||||
import './progress';
|
|
||||||
|
|
||||||
// This is a patched copy of https://github.com/rails/rails/blob/master/activestorage/app/javascript/activestorage/ujs.js
|
|
||||||
// It fixes support for multiple input/button elements on direct upload forms
|
|
||||||
|
|
||||||
const processingAttribute = 'data-direct-uploads-processing';
|
|
||||||
let started = false;
|
|
||||||
|
|
||||||
export function start() {
|
|
||||||
if (!started) {
|
|
||||||
started = true;
|
|
||||||
document.addEventListener('submit', didSubmitForm);
|
|
||||||
document.addEventListener('click', didSubmitFormElement);
|
|
||||||
document.addEventListener('ajax:before', didSubmitRemoteElement);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default { start };
|
|
||||||
|
|
||||||
function didSubmitForm(event) {
|
|
||||||
handleFormSubmissionEvent(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
function didSubmitFormElement(event) {
|
|
||||||
const { target } = event;
|
|
||||||
if (isSubmitElement(target)) {
|
|
||||||
handleFormSubmissionEvent(formSubmitEvent(event), target);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function didSubmitRemoteElement(event) {
|
|
||||||
if (event.target.tagName == 'FORM') {
|
|
||||||
handleFormSubmissionEvent(event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function formSubmitEvent(event) {
|
|
||||||
return {
|
|
||||||
target: event.target.form,
|
|
||||||
preventDefault() {
|
|
||||||
event.preventDefault();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function isSubmitElement({ tagName, type, form }) {
|
|
||||||
if (form && (tagName === 'BUTTON' || tagName === 'INPUT')) {
|
|
||||||
return type === 'submit';
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleFormSubmissionEvent(event, button) {
|
|
||||||
const form = event.target;
|
|
||||||
|
|
||||||
if (form.hasAttribute(processingAttribute)) {
|
|
||||||
event.preventDefault();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const controller = new DirectUploadsController(form);
|
|
||||||
const { inputs } = controller;
|
|
||||||
|
|
||||||
if (inputs.length) {
|
|
||||||
event.preventDefault();
|
|
||||||
form.setAttribute(processingAttribute, '');
|
|
||||||
inputs.forEach(disable);
|
|
||||||
controller.start(error => {
|
|
||||||
form.removeAttribute(processingAttribute);
|
|
||||||
if (error) {
|
|
||||||
inputs.forEach(enable);
|
|
||||||
} else {
|
|
||||||
submitForm(form, button);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function submitForm(form, button) {
|
|
||||||
button = button || findElement(form, 'input[type=submit]');
|
|
||||||
if (button) {
|
|
||||||
const { disabled } = button;
|
|
||||||
button.disabled = false;
|
|
||||||
button.focus();
|
|
||||||
button.click();
|
|
||||||
button.disabled = disabled;
|
|
||||||
} else {
|
|
||||||
button = document.createElement('input');
|
|
||||||
button.type = 'submit';
|
|
||||||
button.style.display = 'none';
|
|
||||||
form.appendChild(button);
|
|
||||||
button.click();
|
|
||||||
form.removeChild(button);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function disable(input) {
|
|
||||||
input.disabled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function enable(input) {
|
|
||||||
input.disabled = false;
|
|
||||||
}
|
|
|
@ -1,5 +1,5 @@
|
||||||
// Include runtime-polyfills for older browsers.
|
// Include runtime-polyfills for older browsers.
|
||||||
// Due to .babelrc's 'useBuiltIns', only polyfills actually
|
// Due to .babelrc's 'useBuiltIns', only polyfills actually
|
||||||
// required by the browsers we support will be included.
|
// required by the browsers we support will be included.
|
||||||
import 'babel-polyfill';
|
import '@babel/polyfill';
|
||||||
import 'dom4';
|
import 'dom4';
|
||||||
|
|
|
@ -1,20 +1,6 @@
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const { environment } = require('@rails/webpacker');
|
const { environment } = require('@rails/webpacker');
|
||||||
|
|
||||||
// By default don't transpile JS files in ./node_modules – except for some specific modules.
|
|
||||||
const babelLoader = environment.loaders.get('babel');
|
|
||||||
babelLoader.exclude = function(modulePath) {
|
|
||||||
let forcedModules = [
|
|
||||||
'activestorage' // ActiveStorage uses 'class', which is not supported by IE 11 and older Safari version
|
|
||||||
];
|
|
||||||
return (
|
|
||||||
modulePath.includes('node_modules') &&
|
|
||||||
forcedModules.every(
|
|
||||||
forcedModule => !modulePath.includes('node_modules/' + forcedModule)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const resolve = {
|
const resolve = {
|
||||||
alias: {
|
alias: {
|
||||||
'@utils': path.resolve(__dirname, '..', '..', 'app/javascript/shared/utils')
|
'@utils': path.resolve(__dirname, '..', '..', 'app/javascript/shared/utils')
|
||||||
|
|
12
package.json
12
package.json
|
@ -1,9 +1,9 @@
|
||||||
{
|
{
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@rails/webpacker": "4.0.0-pre.2",
|
"@rails/webpacker": "4.0.0-pre.3",
|
||||||
"@sentry/browser": "^4.0.4",
|
"@sentry/browser": "^4.0.4",
|
||||||
"@turf/area": "^6.0.1",
|
"@turf/area": "^6.0.1",
|
||||||
"activestorage": "^5.2.1",
|
"activestorage": "^5.2.2-rc1",
|
||||||
"autocomplete.js": "^0.31.0",
|
"autocomplete.js": "^0.31.0",
|
||||||
"chartkick": "^3.0.1",
|
"chartkick": "^3.0.1",
|
||||||
"debounce": "^1.2.0",
|
"debounce": "^1.2.0",
|
||||||
|
@ -19,10 +19,10 @@
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"eclint": "^2.8.0",
|
"eclint": "^2.8.0",
|
||||||
"eslint": "^5.6.0",
|
"eslint": "^5.9.0",
|
||||||
"eslint-config-prettier": "^3.1.0",
|
"eslint-config-prettier": "^3.3.0",
|
||||||
"eslint-plugin-prettier": "^2.6.2",
|
"eslint-plugin-prettier": "^3.0.0",
|
||||||
"prettier": "^1.14.3",
|
"prettier": "^1.15.3",
|
||||||
"webpack-dev-server": "^3.1.9"
|
"webpack-dev-server": "^3.1.9"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
Loading…
Add table
Reference in a new issue