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

Mark 'lodash' module as external dependency in rollup.config #131

Open
stachu3478 opened this issue Apr 21, 2020 · 3 comments
Open

Mark 'lodash' module as external dependency in rollup.config #131

stachu3478 opened this issue Apr 21, 2020 · 3 comments

Comments

@stachu3478
Copy link

I have gone in the problem where i have found a lot of unused bundled code (lodash) and found easy way to solve that.

As in Screeps the lodash module is included by default, i think it should not be bundled one more time. So changing:

// rollup.config.js
export default {
  input: "src/main.ts",
  output: {
    file: "dist/main.js",
    format: "cjs",
    sourcemap: true
  },

  plugins: [
    clear({ targets: ["dist"] }),
    resolve(),
    commonjs(),
    typescript({tsconfig: "./tsconfig.json"}),
    screeps({config: cfg, dryRun: cfg == null})
  ]
}
// UPDATE TO
// rollup.config.js
export default {
  input: "src/main.ts",
  output: {
    file: "dist/main.js",
    format: "cjs",
    sourcemap: true
  },
  external: ['lodash'],

  plugins: [
    clear({ targets: ["dist"] }),
    resolve(),
    commonjs(),
    typescript({tsconfig: "./tsconfig.json"}),
    screeps({config: cfg, dryRun: cfg == null})
  ]
}

... would save a lot of code bundled and improve smart bundling effect.
However, there might be an issue with incompatible lodash version so it is still only an option.

@pyrodogg
Copy link
Member

Lodash only gets bundled if you explicitly import it into files in your project. This shouldn't be necessary if using the games version of lodash. You should be able to write code assuming a global instance of lodash exists bound to _ without import.

A recent update to @types/lodash (v3.10.3) broke the ability to transparently assume a global lodash, so I added a shim to types.d.ts as a workaround.

If you happened to pull this repo within the past week, and you got compile errors regarding lodash which suggested importing it, try pulling the latest changes.

If you prefer explicitly importing (the games's version of) lodash, then yes you will need this external module definition.

If you're explicitly importing a different version of lodash, then it must be bundled.

@pyrodogg
Copy link
Member

It's been pointed out that my hotfix doesn't work / introduces other issues. Back to investigating how to handle lodash.

@folke
Copy link

folke commented Dec 16, 2020

You can add the below to types.d.ts:

declare const _ = typeof lodash

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants