Skip to content

feat: provide esm output file in dist #6966

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

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions antd-tools/getWebpackConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const imageOptions = {
limit: 10000,
};

function getWebpackConfig(modules) {
function getWebpackConfig(modules, esm = false) {
const pkg = require(getProjectPath('package.json'));
const babelConfig = require('./getBabelCommonConfig')(modules || false);

Expand Down Expand Up @@ -185,7 +185,7 @@ All rights reserved.
};

if (process.env.RUN_ENV === 'PRODUCTION') {
const entry = ['./index'];
let entry = ['./index'];
config.externals = [
{
vue: {
Expand All @@ -197,9 +197,25 @@ All rights reserved.
},
},
];
config.output.library = distFileBaseName;
config.output.libraryTarget = 'umd';
config.output.globalObject = 'this';
if (esm) {
entry = ['./index.esm'];
config.experiments = {
...config.experiments,
outputModule: true,
};
config.output.chunkFormat = 'module';
config.output.library = {
type: 'module',
};
config.target = 'es2019';
} else {
config.output.libraryTarget = 'umd';
config.output.library = distFileBaseName;
config.output.globalObject = 'this';
}

const entryName = esm ? `${distFileBaseName}.esm` : distFileBaseName;

config.optimization = {
minimizer: [
new TerserPlugin({
Expand All @@ -213,7 +229,7 @@ All rights reserved.
// Development
const uncompressedConfig = merge({}, config, {
entry: {
[distFileBaseName]: entry,
[entryName]: entry,
},
mode: 'development',
plugins: [
Expand All @@ -226,7 +242,7 @@ All rights reserved.
// Production
const prodConfig = merge({}, config, {
entry: {
[`${distFileBaseName}.min`]: entry,
[`${entryName}.min`]: entry,
},
mode: 'production',
plugins: [
Expand Down
3 changes: 2 additions & 1 deletion webpack.build.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function externalDayjs(config) {
}

const webpackConfig = getWebpackConfig(false);
const webpackESMConfig = getWebpackConfig(false, true);

if (process.env.RUN_ENV === 'PRODUCTION') {
webpackConfig.forEach(config => {
Expand Down Expand Up @@ -72,4 +73,4 @@ if (process.env.RUN_ENV === 'PRODUCTION') {
});
}

module.exports = [...webpackConfig];
module.exports = [...webpackConfig, ...webpackESMConfig];