Skip to content

Commit 0c11715

Browse files
authored
Merge pull request #4 from vite-plugin/v1.4.1
V1.4.1
2 parents ff7854c + 1194d1e commit 0c11715

5 files changed

Lines changed: 40 additions & 4 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,5 @@ dist
109109
package-lock.json
110110
pnpm-lock.yaml
111111
yarn.lock
112+
113+
/index.mjs

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## [2022-10-15] v1.4.1
2+
3+
- bafe527 v1.4.1
4+
- 1fd4a6d (github/v1.4.1) feat(🌱): support `type: "module"`
5+
- 6600d5c fix(🐞): type check #3
16

27
## [2022-07-15] v1.4.0
38

build.mjs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import fs from 'node:fs';
2+
import path from 'node:path';
3+
import { createRequire } from 'node:module';
4+
import { fileURLToPath } from 'node:url';
5+
import libEsm from 'lib-esm'
6+
7+
// const iswatch = process.argv.slice(2).includes('--watch');
8+
const CJS = {
9+
__filename: fileURLToPath(import.meta.url),
10+
__dirname: path.dirname(fileURLToPath(import.meta.url)),
11+
require: createRequire(import.meta.url),
12+
};
13+
14+
const filename = path.join(CJS.__dirname, 'index.js');
15+
const destname = filename.replace('.js', '.mjs');
16+
const result = libEsm({ lib: './index.js', members: Object.keys(CJS.require('.')) });
17+
fs.writeFileSync(destname, result.snippet);
18+
19+
console.log('build success');

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module.exports = function optimizer(entries, options = {}) {
2525

2626
if (!config.resolve) config.resolve = {};
2727
if (!config.resolve.alias) config.resolve.alias = [];
28-
if (typeof config.resolve.alias === 'object') {
28+
if (Object.prototype.toString.call(config.resolve.alias) === '[object Object]') {
2929
config.resolve.alias = Object
3030
.entries(config.resolve.alias)
3131
.reduce((memo, [find, replacement]) => memo.concat({ find, replacement }), []);

package.json

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
11
{
22
"name": "vite-plugin-optimizer",
3-
"version": "1.4.0",
3+
"version": "1.4.1",
44
"description": "Manually Pre-Bundling of Vite",
55
"main": "index.js",
6+
"exports": {
7+
".": {
8+
"import": "./index.mjs",
9+
"require": "./index.js"
10+
}
11+
},
612
"repository": {
713
"type": "git",
814
"url": "git+https://github.com/vite-plugin/vite-plugin-optimizer.git"
915
},
1016
"author": "草鞋没号 <308487730@qq.com>",
1117
"license": "MIT",
1218
"scripts": {
13-
"test": "vite -c test/vite.config.ts"
19+
"build": "node build.mjs",
20+
"test": "vite -c test/vite.config.ts",
21+
"prepublishOnly": "npm run build"
1422
},
1523
"devDependencies": {
16-
"vite": "^2.9.9"
24+
"lib-esm": "^0.1.0",
25+
"vite": "^3.2.x"
1726
},
1827
"keywords": [
1928
"vite",
@@ -25,6 +34,7 @@
2534
],
2635
"files": [
2736
"index.js",
37+
"index.mjs",
2838
"index.d.ts"
2939
]
3040
}

0 commit comments

Comments
 (0)