Skip to content

Commit c5ea668

Browse files
authored
chore: provide esm output file in dist (#6966)
1 parent 3c5fb84 commit c5ea668

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

antd-tools/getWebpackConfig.js

+23-7
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const imageOptions = {
2222
limit: 10000,
2323
};
2424

25-
function getWebpackConfig(modules) {
25+
function getWebpackConfig(modules, esm = false) {
2626
const pkg = require(getProjectPath('package.json'));
2727
const babelConfig = require('./getBabelCommonConfig')(modules || false);
2828

@@ -185,7 +185,7 @@ All rights reserved.
185185
};
186186

187187
if (process.env.RUN_ENV === 'PRODUCTION') {
188-
const entry = ['./index'];
188+
let entry = ['./index'];
189189
config.externals = [
190190
{
191191
vue: {
@@ -197,9 +197,25 @@ All rights reserved.
197197
},
198198
},
199199
];
200-
config.output.library = distFileBaseName;
201-
config.output.libraryTarget = 'umd';
202-
config.output.globalObject = 'this';
200+
if (esm) {
201+
entry = ['./index.esm'];
202+
config.experiments = {
203+
...config.experiments,
204+
outputModule: true,
205+
};
206+
config.output.chunkFormat = 'module';
207+
config.output.library = {
208+
type: 'module',
209+
};
210+
config.target = 'es2019';
211+
} else {
212+
config.output.libraryTarget = 'umd';
213+
config.output.library = distFileBaseName;
214+
config.output.globalObject = 'this';
215+
}
216+
217+
const entryName = esm ? `${distFileBaseName}.esm` : distFileBaseName;
218+
203219
config.optimization = {
204220
minimizer: [
205221
new TerserPlugin({
@@ -213,7 +229,7 @@ All rights reserved.
213229
// Development
214230
const uncompressedConfig = merge({}, config, {
215231
entry: {
216-
[distFileBaseName]: entry,
232+
[entryName]: entry,
217233
},
218234
mode: 'development',
219235
plugins: [
@@ -226,7 +242,7 @@ All rights reserved.
226242
// Production
227243
const prodConfig = merge({}, config, {
228244
entry: {
229-
[`${distFileBaseName}.min`]: entry,
245+
[`${entryName}.min`]: entry,
230246
},
231247
mode: 'production',
232248
plugins: [

webpack.build.conf.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ function externalDayjs(config) {
3939
}
4040

4141
const webpackConfig = getWebpackConfig(false);
42+
const webpackESMConfig = getWebpackConfig(false, true);
4243

4344
if (process.env.RUN_ENV === 'PRODUCTION') {
4445
webpackConfig.forEach(config => {
@@ -72,4 +73,4 @@ if (process.env.RUN_ENV === 'PRODUCTION') {
7273
});
7374
}
7475

75-
module.exports = [...webpackConfig];
76+
module.exports = [...webpackConfig, ...webpackESMConfig];

0 commit comments

Comments
 (0)