Skip to content

Commit

Permalink
enhance: Transform ES standards in node_modules
Browse files Browse the repository at this point in the history
  • Loading branch information
ntucker committed Mar 22, 2021
1 parent f28d1ed commit 7f26568
Show file tree
Hide file tree
Showing 3 changed files with 602 additions and 185 deletions.
2 changes: 2 additions & 0 deletions packages/webpack-config-anansi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,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.1",
"@pmmmwh/react-refresh-webpack-plugin": "^0.4.3",
"@svgr/webpack": "^5.5.0",
Expand Down
50 changes: 50 additions & 0 deletions packages/webpack-config-anansi/src/base/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,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: /\.(md|txt)$/,
type: 'asset/source',
Expand Down
Loading

0 comments on commit 7f26568

Please sign in to comment.