gaearon / ama

Ask me anything!
222 stars 5 forks source link

The webpack adds an unnecessary file to the chunk #164

Closed rckm closed 3 years ago

rckm commented 3 years ago

Hi Dan, i have project React + Typescript + react-app-rewired.

This project has external folder SDK which include sdk.js, sdk.wasm etc. (sdk.js is already optimized and minimized)

In component i can use

import {Foo} from '../public/SDK/sdk.js';

But react or react-app-rewired including sdk.js file into 3.[hash].chunk.js. I think webpack tried to optimize the already optimized code in consequence of which project not building (error was n.setVolume is not a function)

tsconfig.json

{
  "compilerOptions": {
    "target": "ES2018",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "baseUrl": "./src",
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "strictNullChecks": true,
    "noImplicitAny": true,
    "strictPropertyInitialization": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "module": "ESNext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "importHelpers": true,
    "noEmit": true,
    "jsx": "react-jsx",
    "outDir": "build",
  },
  "include": [
    "src",
  ],
  "exclude": ["node_modules", "public/sdk", "build", "public/**/*.js", "src/**/*.js"],
}

config-overrides.js

const { removeModuleScopePlugin } = require('customize-cra');

module.exports = removeModuleScopePlugin();
Whoaa512 commented 3 years ago

This isn't for personal debug help from Dan. You might have better luck on StackOverflow