Skip to content
This repository was archived by the owner on Jan 18, 2022. It is now read-only.

Commit d1e77ff

Browse files
committed
fix: use default export mode for commonjs build
1 parent 4acc158 commit d1e77ff

File tree

6 files changed

+362
-29
lines changed

6 files changed

+362
-29
lines changed

Diff for: package.json

+15-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"version": "6.0.0-alpha.0",
44
"license": "MIT",
55
"main": "dist/index.js",
6-
"module": "dist/rollup-plugin-vue.esm.js",
76
"typings": "dist/index.d.ts",
87
"author": "Rahul Kadyan <[email protected]> (https://znck.me)",
98
"files": [
@@ -12,24 +11,33 @@
1211
"dependencies": {
1312
"debug": "^4.1.1",
1413
"hash-sum": "^2.0.0",
14+
"lint-staged": "^10.1.1",
1515
"rollup-pluginutils": "^2.8.2",
1616
"sourcemap-codec": "^1.4.8"
1717
},
1818
"peerDependencies": {
1919
"@vue/compiler-sfc": "*"
2020
},
2121
"devDependencies": {
22-
"@vue/compiler-sfc": "^3.0.0-alpha.10",
22+
"@rollup/plugin-typescript": "^4.0.0",
2323
"@types/debug": "^4.1.5",
2424
"@types/jest": "^24.9.0",
25+
"@vue/compiler-sfc": "^3.0.0-alpha.10",
2526
"husky": "^4.2.0",
2627
"rollup": "^1.29.1",
2728
"tsdx": "^0.12.3",
2829
"tslib": "^1.10.0",
2930
"typescript": "^3.7.5"
3031
},
3132
"husky": {
32-
"hooks": {}
33+
"hooks": {
34+
"pre-commit": "lint-staged"
35+
}
36+
},
37+
"lint-staged": {
38+
"*.{ts,js,json}": [
39+
"prettier --write"
40+
]
3341
},
3442
"prettier": {
3543
"printWidth": 80,
@@ -38,10 +46,10 @@
3846
"singleQuote": true
3947
},
4048
"scripts": {
41-
"build": "tsdx build",
42-
"lint": "tsdx lint",
43-
"prepare": "tsdx build",
44-
"start": "tsdx watch",
49+
"build": "rollup -c",
50+
"lint": "tsdx lint src",
51+
"prepublishOnly": "npm run build",
52+
"start": "tsdx watch --target node",
4553
"test": "tsdx test"
4654
}
4755
}

Diff for: rollup.config.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import typescript from '@rollup/plugin-typescript'
2+
import { dependencies, peerDependencies } from './package.json'
3+
4+
/** @type {import('rollup').RollupOptions} */
5+
const config = {
6+
input: 'src/index.ts',
7+
output: {
8+
format: 'cjs',
9+
dir: 'dist',
10+
sourcemap: true,
11+
exports: 'default'
12+
},
13+
external: [
14+
'path',
15+
'querystring',
16+
...Object.keys(dependencies),
17+
...Object.keys(peerDependencies),
18+
],
19+
plugins: [typescript()]
20+
}
21+
22+
export default config

Diff for: src/cssModules.ts

-16
This file was deleted.

Diff for: src/index.ts

+17-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import { basename, relative } from 'path'
2323
import qs from 'querystring'
2424
import { Plugin, RollupError } from 'rollup'
2525
import { createFilter } from 'rollup-pluginutils'
26-
import { genCSSModulesCode } from './cssModules'
2726
import { encode } from 'sourcemap-codec'
2827

2928
const debug = createDebugger('rollup-plugin-vue')
@@ -460,3 +459,20 @@ function normalizeSourceMap(map: SFCTemplateCompileResults['map']): any {
460459
mappings: typeof map.mappings === 'string' ? map.mappings : '',
461460
}
462461
}
462+
463+
function genCSSModulesCode(
464+
// @ts-ignore
465+
id: string,
466+
index: number,
467+
request: string,
468+
moduleName: string | boolean
469+
): string {
470+
const styleVar = `style${index}`
471+
let code = `\nimport ${styleVar} from ${request}`
472+
473+
// inject variable
474+
const name = typeof moduleName === 'string' ? moduleName : '$style'
475+
code += `\ncssModules["${name}"] = ${styleVar}`
476+
477+
return code
478+
}

Diff for: tsconfig.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"importHelpers": true,
88
"declaration": true,
99
"sourceMap": true,
10-
"rootDir": "./",
10+
"rootDir": "src",
11+
"outDir": "dist",
1112
"strict": true,
1213
"noImplicitAny": true,
1314
"strictNullChecks": true,
@@ -20,7 +21,6 @@
2021
"noImplicitReturns": true,
2122
"noFallthroughCasesInSwitch": true,
2223
"moduleResolution": "node",
23-
"baseUrl": "./",
2424
"jsx": "react",
2525
"esModuleInterop": true
2626
}

0 commit comments

Comments
 (0)