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

Fix for IE 11-compatible Babel transpilation #242

Merged
merged 9 commits into from
Nov 4, 2019
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
35 changes: 27 additions & 8 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,15 +1,34 @@
{
"presets": ["next/babel"], // https://goo.gl/aqbWJY
"presets": [[
"next/babel",
{
"preset-env": {
"useBuiltIns": "entry",
"corejs": 3,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Newer than the default. Default would be 2, also this line is necessary to get rid of a warning.

"debug": true
},
"transform-runtime": {
"corejs": 3,
"useESModules": false
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this, the server code would crash on start.

},
"class-properties": {}
}
]], // https://goo.gl/aqbWJY
"plugins": [
"transform-flow-strip-types",
[
"ttag",
{
"babel-plugin-styled-components"
],
"env": {
"ttag": {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the configuration used when running Babel with BABEL_ENV=ttag.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you test the pot file extraction with these changes?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't look in detail at the .pot file, but it was generated correctly.

// ttag plugin has its own environment to not conflict
// with `babel-env` transpilation:
//
// https://github.com/ttag-org/babel-plugin-ttag/issues/138
"plugins": [["ttag", {
"extract": {
"output": "public/i18n/translations.pot"
}
}
],
"babel-plugin-styled-components"
]
}]]
}
}
}
66 changes: 39 additions & 27 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,52 @@
const ElasticAPMSourceMapPlugin = require('@hypo808/elastic-apm-sourcemap-webpack-plugin').default;
const TTagPlugin = require('babel-plugin-ttag').default;
const withSass = require('@zeit/next-sass');
const withCss = require('@zeit/next-css');
const withTranspileModules = require('next-transpile-modules');
const webpack = require('webpack');
const env = require('./src/lib/env');
const withSourceMaps = require('@zeit/next-source-maps');

module.exports = withSourceMaps(
withCss(
withSass({
webpack: config => {
// Fixes npm packages that depend on `fs` module
config.node = {
fs: 'empty',
dgram: 'empty',
net: 'empty',
tls: 'empty',
child_process: 'empty',
async_hooks: 'mock',
'elastic-apm-node': 'empty',
};
withSass(
withTranspileModules({
// Next.js doesn't transpile node_modules content by default.
// We have to do this manually to make IE 11 users happy.
transpileModules: [
'@sozialhelden/twelve-factor-dotenv',
'@elastic/apm-rum-core',
'@elastic/apm-rum',
'dotenv',
],
webpack: config => {
// Fixes npm packages that depend on `fs` module
config.node = {
fs: 'empty',
dgram: 'empty',
net: 'empty',
tls: 'empty',
child_process: 'empty',
async_hooks: 'mock',
'elastic-apm-node': 'empty',
};

// if (process.env.NODE_ENV === 'production') {
// config.plugins.unshift(new ElasticAPMSourceMapPlugin({
// serviceName: 'wheelmap-react-frontend',
// serviceVersion: env.npm_package_version,
// serverURL: env.REACT_APP_ELASTIC_APM_SERVER_URL,
// publicPath: `${env.PUBLIC_URL}/_next/static/chunks`,
// secret: env.ELASTIC_APM_SECRET_TOKEN,
// logLevel: 'debug'
// }));
// }
// if (process.env.NODE_ENV === 'production') {
// config.plugins.unshift(new ElasticAPMSourceMapPlugin({
// serviceName: 'wheelmap-react-frontend',
// serviceVersion: env.npm_package_version,
// serverURL: env.REACT_APP_ELASTIC_APM_SERVER_URL,
// publicPath: `${env.PUBLIC_URL}/_next/static/chunks`,
// secret: env.ELASTIC_APM_SECRET_TOKEN,
// logLevel: 'debug'
// }));
// }

return config;
},
// Disabling file-system routing to always use custom server.
useFileSystemPublicRoutes: false,
})
return config;
},
// Disabling file-system routing to always use custom server.
useFileSystemPublicRoutes: false,
})
)
)
);
Loading