From 32d198f8e706c6fb7266d6f2b0633af53103efda Mon Sep 17 00:00:00 2001 From: David Lechner Date: Mon, 7 Mar 2022 10:42:18 -0600 Subject: [PATCH] craco: drop esnext rules Since 08e59d2, shopify no longer published .esnext files for webpack so we can drop these rules. However, when we do this, there is still another .mjs issue that needs to be worked around. --- craco.config.js | 45 ++++++++------------------------------------- 1 file changed, 8 insertions(+), 37 deletions(-) diff --git a/craco.config.js b/craco.config.js index e4a5eac8..92f930e0 100644 --- a/craco.config.js +++ b/craco.config.js @@ -2,12 +2,7 @@ // // https://github.com/gsoft-inc/craco/blob/master/packages/craco/README.md#configuration -const { - addBeforeLoader, - getLoader, - getLoaders, - loaderByName, -} = require('@craco/craco'); +const { addBeforeLoader, loaderByName } = require('@craco/craco'); const CopyPlugin = require('copy-webpack-plugin'); const LicensePlugin = require('license-webpack-plugin').LicenseWebpackPlugin; const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin'); @@ -240,12 +235,6 @@ module.exports = { filename: '[name].worker.[contenthash].js', }), ], - configure: { - resolve: { - // need 'esnext' first to avoid compile errors - mainFields: ['esnext', 'browser', 'module', 'main'], - }, - }, }, plugins: [ { @@ -256,31 +245,13 @@ module.exports = { pluginOptions, context: { env, paths }, }) => { - // add .esnext file extension for @shopify/* - - webpackConfig.resolve.extensions = [ - '.web.esnext', - '.esnext', - ...webpackConfig.resolve.extensions, - ]; - - const babelLoaders = getLoaders( - webpackConfig, - loaderByName('babel-loader'), - ); - babelLoaders.matches[0].loader.test = - /\.(esnext|js|mjs|jsx|ts|tsx)$/; - babelLoaders.matches[1].loader.test = /\.(esnext|js|mjs)$/; - - const fileLoader = getLoader( - webpackConfig, - loaderByName('file-loader'), - ); - fileLoader.match.loader.exclude = [ - /\.(esnext|js|mjs|jsx|ts|tsx)$/, - /\.html$/, - /\.json$/, - ]; + // work around @shopify/* webpack compatibility + // https://github.com/Shopify/quilt/issues/1722#issuecomment-789883471 + webpackConfig.module.rules.push({ + test: /\.mjs$/, + include: /node_modules/, + type: 'javascript/auto', + }); // work around default handling of .wasm files // https://github.com/webpack/webpack/issues/7352