diff --git a/packages/webpack-config-anansi/package.json b/packages/webpack-config-anansi/package.json index 4431a2f99..1f2bf6a82 100644 --- a/packages/webpack-config-anansi/package.json +++ b/packages/webpack-config-anansi/package.json @@ -56,6 +56,8 @@ "rimraf": "^3.0.2" }, "dependencies": { + "@babel/plugin-transform-typescript": "^7.13.0", + "@babel/preset-env": "^7.13.10", "@linaria/webpack-loader": "^3.0.0-beta.2", "@pmmmwh/react-refresh-webpack-plugin": "^0.4.3", "@svgr/webpack": "^5.5.0", diff --git a/packages/webpack-config-anansi/src/base/index.js b/packages/webpack-config-anansi/src/base/index.js index 924b6f1c3..1e5eb04a5 100644 --- a/packages/webpack-config-anansi/src/base/index.js +++ b/packages/webpack-config-anansi/src/base/index.js @@ -129,6 +129,56 @@ export default function makeBaseConfig({ ], exclude: libraryExclude, }, + // transpile JS outside the app to support standard ES features + { + test: /\.m?js$/, + include: /node_modules/, + exclude: [ + // \\ for Windows, \/ for Mac OS and Linux + /node_modules[\\\/](core-js)/, + /node_modules[\\\/]webpack[\\\/]buildin/, + /@babel(?:\/|\\{1,2})runtime/, + ], + use: { + loader: require.resolve('babel-loader'), + options: { + babelrc: false, + configFile: false, + compact: false, + cacheDirectory: true, + // See https://github.com/facebook/create-react-app/issues/6846 for context + cacheCompression: false, + // Babel assumes ES Modules, which isn't safe until CommonJS + // dies. This changes the behavior to assume CommonJS unless + // an `import` or `export` is present in the file. + // https://github.com/webpack/webpack/issues/4039#issuecomment-419284940 + sourceType: 'unambiguous', + presets: [ + [ + '@babel/preset-env', + { + bugfixes: true, + useBuiltIns: 'entry', + corejs: 3, + exclude: ['transform-typeof-symbol'], + }, + ], + ], + plugins: [ + [ + '@babel/plugin-transform-runtime', + { + corejs: false, + helpers: true, + regenerator: true, + useESModules: true, + version: require('@babel/runtime/package.json').version, + }, + ], + ], + }, + }, + }, { test: /\.html$/, use: [{ loader: require.resolve('html-loader') }], diff --git a/yarn.lock b/yarn.lock index aa4c6ac8d..795e676e6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1087,7 +1087,7 @@ "@babel/helper-create-regexp-features-plugin" "^7.12.13" "@babel/helper-plugin-utils" "^7.12.13" -"@babel/preset-env@>=7", "@babel/preset-env@^7.12.1", "@babel/preset-env@^7.12.11", "@babel/preset-env@^7.13.15": +"@babel/preset-env@>=7", "@babel/preset-env@^7.12.1", "@babel/preset-env@^7.12.11", "@babel/preset-env@^7.13.10", "@babel/preset-env@^7.13.15": version "7.13.15" resolved "https://registry.yarnpkg.com/@babel/preset-env/-/preset-env-7.13.15.tgz#c8a6eb584f96ecba183d3d414a83553a599f478f" integrity sha512-D4JAPMXcxk69PKe81jRJ21/fP/uYdcTZ3hJDF5QX2HSI9bBxxYw/dumdR6dGumhjxlprHPE4XWoPaqzZUVy2MA== @@ -5923,7 +5923,16 @@ camelcase-keys@^4.0.0: map-obj "^2.0.0" quick-lru "^1.0.0" -camelcase-keys@^6.0.0, camelcase-keys@^6.2.2: +camelcase-keys@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/camelcase-keys/-/camelcase-keys-6.0.0.tgz#12a07a6f50189213c3e8626c4069e28b997d01d1" + integrity sha512-NW1C7M9/uDZlfDP0+pWv0yAtgni7AZ9bYKtWgIfJylNXUFfis2BxsX3lCVuZE12wtRePEfJjnG6T9CnMohEybw== + dependencies: + camelcase "^5.3.1" + map-obj "^4.0.0" + quick-lru "^4.0.1" + +camelcase-keys@^6.2.2: version "6.2.2" resolved "https://registry.yarnpkg.com/camelcase-keys/-/camelcase-keys-6.2.2.tgz#5e755d6ba51aa223ec7d3d52f25778210f9dc3c0" integrity sha512-YrwaA0vEKazPBkn0ipTiMpSajYDSe+KjQfrjhcBMxJt/znbvlHd8Pw/Vamaz5EB4Wfhs3SUR3Z9mwRu/P3s3Yg== @@ -12129,7 +12138,12 @@ lodash.uniq@4.5.0, lodash.uniq@^4.5.0: resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773" integrity sha1-0CJTc662Uq3BvILklFM5qEJ1R3M= -lodash@^4.0.0, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.12, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.20, lodash@^4.17.21, lodash@^4.17.4, lodash@^4.2.1, lodash@~4.17.10: +lodash@^4.0.0, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.12, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.20, lodash@^4.17.4, lodash@~4.17.10: + version "4.17.20" + resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.20.tgz#b44a9b6297bcb698f1c51a3545a2b3b368d59c52" + integrity sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA== + +lodash@^4.17.21, lodash@^4.2.1: version "4.17.21" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c" integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==