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

[Feature]: Support moment-locales-webpack-plugin #6373

Closed
SyMind opened this issue Apr 26, 2024 · 6 comments · Fixed by #6420
Closed

[Feature]: Support moment-locales-webpack-plugin #6373

SyMind opened this issue Apr 26, 2024 · 6 comments · Fixed by #6420
Assignees
Labels
feat New feature or request

Comments

@SyMind
Copy link
Member

SyMind commented Apr 26, 2024

What problem does this feature solve?

Easily remove unused Moment.js locales when building with webpack.

https://www.npmjs.com/package/moment-locales-webpack-plugin

What does the proposed API of configuration look like?

const MomentLocalesPlugin = require('moment-locales-webpack-plugin');

module.exports = {
    plugins: [
        // To strip all locales except “en”
        new MomentLocalesPlugin(),
 
        // Or: To strip all locales except “en”, “es-us” and “ru”
        // (“en” is built into Moment and can’t be removed)
        new MomentLocalesPlugin({
            localesToKeep: ['es-us', 'ru'],
        }),
    ],
};
@SyMind SyMind added feat New feature or request pending triage The issue/PR is currently untouched. labels Apr 26, 2024
@SyMind SyMind self-assigned this Apr 26, 2024
@h-a-n-a h-a-n-a removed the pending triage The issue/PR is currently untouched. label Apr 26, 2024
@escaton
Copy link
Contributor

escaton commented Jun 27, 2024

This actually enables ContextReplacementPlugin which is indicated as Unsupported yet here 🎉 Great work!

@obennett-m
Copy link

This actually enables ContextReplacementPlugin which is indicated as Unsupported yet here 🎉 Great work!

It doesn't based on my testing. The below still fails :-(

const rspack = require('@rspack/core')
...

  plugins: [
    new rspack.ContextReplacementPlugin(/moment[\/\\]locale$/, /(da|de|fr|es|en|it|nl|pt|sv)$/),
  ],
...

@escaton
Copy link
Contributor

escaton commented Jul 13, 2024

Works for me: new webpack.ContextReplacementPlugin

@obennett-m
Copy link

obennett-m commented Jul 15, 2024

Works for me: new webpack.ContextReplacementPlugin

It seems you still have webpack installed in your project. If you use the same require line: const rspack = require('@rspack/core') what happens then?
Here are the version I'm using btw:

    "@rspack/cli": "^0.7.5",
    "@rspack/core": "^0.7.5",

with the error:

rspack --config rspack/build-dev.config.babel.mjs --watch
(node:1357) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
TypeError: rspack.ContextReplacementPlugin is not a constructor

Which makes sense to me as I didn't see any code for a ContextReplacementPlugin in this PR.

@escaton
Copy link
Contributor

escaton commented Jul 16, 2024

If you look under the hood of moment-locales-webpack-plugin it uses webpack.ContextReplacementPlugin. it doesn't mean that the whole webpack is used there. Just one of its built-in plugins works thanks for the changes in this PR.

@obennett-m
Copy link

If you look under the hood of moment-locales-webpack-plugin it uses webpack.ContextReplacementPlugin. it doesn't mean that the whole webpack is used there. Just one of its built-in plugins works thanks for the changes in this PR.

I did look under the hood when I didn't get this working with only @rspack/core installed. This is how I know webpack needs to still be installed in order for this to work. rspack isn't providing ContextReplacementPlugin, so what is documented at https://www.rspack.dev/plugins/webpack/index is still correct.

If you were to completely uninstall webpack from your project you would see the same issues I do.
TypeError: rspack.ContextReplacementPlugin is not a constructor means it is not implemented in @rspack/core.

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

Successfully merging a pull request may close this issue.

4 participants