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

Commit

Permalink
fix: use default export mode for commonjs build
Browse files Browse the repository at this point in the history
  • Loading branch information
znck committed Apr 3, 2020
1 parent 4acc158 commit d1e77ff
Show file tree
Hide file tree
Showing 6 changed files with 362 additions and 29 deletions.
22 changes: 15 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"version": "6.0.0-alpha.0",
"license": "MIT",
"main": "dist/index.js",
"module": "dist/rollup-plugin-vue.esm.js",
"typings": "dist/index.d.ts",
"author": "Rahul Kadyan <[email protected]> (https://znck.me)",
"files": [
Expand All @@ -12,24 +11,33 @@
"dependencies": {
"debug": "^4.1.1",
"hash-sum": "^2.0.0",
"lint-staged": "^10.1.1",
"rollup-pluginutils": "^2.8.2",
"sourcemap-codec": "^1.4.8"
},
"peerDependencies": {
"@vue/compiler-sfc": "*"
},
"devDependencies": {
"@vue/compiler-sfc": "^3.0.0-alpha.10",
"@rollup/plugin-typescript": "^4.0.0",
"@types/debug": "^4.1.5",
"@types/jest": "^24.9.0",
"@vue/compiler-sfc": "^3.0.0-alpha.10",
"husky": "^4.2.0",
"rollup": "^1.29.1",
"tsdx": "^0.12.3",
"tslib": "^1.10.0",
"typescript": "^3.7.5"
},
"husky": {
"hooks": {}
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.{ts,js,json}": [
"prettier --write"
]
},
"prettier": {
"printWidth": 80,
Expand All @@ -38,10 +46,10 @@
"singleQuote": true
},
"scripts": {
"build": "tsdx build",
"lint": "tsdx lint",
"prepare": "tsdx build",
"start": "tsdx watch",
"build": "rollup -c",
"lint": "tsdx lint src",
"prepublishOnly": "npm run build",
"start": "tsdx watch --target node",
"test": "tsdx test"
}
}
22 changes: 22 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import typescript from '@rollup/plugin-typescript'
import { dependencies, peerDependencies } from './package.json'

/** @type {import('rollup').RollupOptions} */
const config = {
input: 'src/index.ts',
output: {
format: 'cjs',
dir: 'dist',
sourcemap: true,
exports: 'default'
},
external: [
'path',
'querystring',
...Object.keys(dependencies),
...Object.keys(peerDependencies),
],
plugins: [typescript()]
}

export default config
16 changes: 0 additions & 16 deletions src/cssModules.ts

This file was deleted.

18 changes: 17 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { basename, relative } from 'path'
import qs from 'querystring'
import { Plugin, RollupError } from 'rollup'
import { createFilter } from 'rollup-pluginutils'
import { genCSSModulesCode } from './cssModules'
import { encode } from 'sourcemap-codec'

const debug = createDebugger('rollup-plugin-vue')
Expand Down Expand Up @@ -460,3 +459,20 @@ function normalizeSourceMap(map: SFCTemplateCompileResults['map']): any {
mappings: typeof map.mappings === 'string' ? map.mappings : '',
}
}

function genCSSModulesCode(
// @ts-ignore
id: string,
index: number,
request: string,
moduleName: string | boolean
): string {
const styleVar = `style${index}`
let code = `\nimport ${styleVar} from ${request}`

// inject variable
const name = typeof moduleName === 'string' ? moduleName : '$style'
code += `\ncssModules["${name}"] = ${styleVar}`

return code
}
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"importHelpers": true,
"declaration": true,
"sourceMap": true,
"rootDir": "./",
"rootDir": "src",
"outDir": "dist",
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
Expand All @@ -20,7 +21,6 @@
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"moduleResolution": "node",
"baseUrl": "./",
"jsx": "react",
"esModuleInterop": true
}
Expand Down
Loading

0 comments on commit d1e77ff

Please sign in to comment.