forked from alibaba/formily
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
“import on demand” support in antd and next (alibaba#193)
- Loading branch information
1 parent
71367f7
commit 369724c
Showing
7 changed files
with
92 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,5 @@ coverage | |
expected | ||
website | ||
gh-pages | ||
weex | ||
weex | ||
build.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require('../../scripts/build')({ | ||
libraryDirectory: 'lib', | ||
libraryName: 'antd', | ||
style: 'css' | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require('../../scripts/build')({ | ||
libraryDirectory: 'lib', | ||
libraryName: '@alifd/next', | ||
style: importPath => `${importPath}/style` | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
const tsImportPluginFactory = require('ts-import-plugin') | ||
const ts = require('typescript') | ||
const glob = require('glob') | ||
const json5 = require('json5') | ||
const fs = require('fs') | ||
|
||
const getCompilerOptions = () => { | ||
const tsconfig = json5.parse( | ||
fs.readFileSync('./tsconfig.json', { | ||
encoding: 'utf8' | ||
}) | ||
) | ||
|
||
const base = json5.parse( | ||
fs.readFileSync('../../tsconfig.json', { | ||
encoding: 'utf8' | ||
}) | ||
) | ||
const json = { ...base.compilerOptions, ...tsconfig.compilerOptions } | ||
|
||
return ts.convertCompilerOptionsFromJson(json) | ||
} | ||
|
||
function compiler(fileNames, options, transformer) { | ||
const program = ts.createProgram(fileNames, options) | ||
const emitResult = transformer | ||
? program.emit(undefined, undefined, undefined, false, { | ||
before: [transformer] | ||
}) | ||
: program.emit() | ||
|
||
const allDiagnostics = ts | ||
.getPreEmitDiagnostics(program) | ||
.concat(emitResult.diagnostics) | ||
|
||
allDiagnostics.forEach(diagnostic => { | ||
if (diagnostic.file) { | ||
let { line, character } = diagnostic.file.getLineAndCharacterOfPosition( | ||
diagnostic.start | ||
) | ||
let message = ts.flattenDiagnosticMessageText( | ||
diagnostic.messageText, | ||
'\n' | ||
) | ||
console.log( | ||
`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}` | ||
) | ||
} else { | ||
console.log( | ||
`${ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n')}` | ||
) | ||
} | ||
}) | ||
|
||
let exitCode = emitResult.emitSkipped ? 1 : 0 | ||
console.log(`Process exiting with code '${exitCode}'.`) | ||
process.exit(exitCode) | ||
} | ||
|
||
module.exports = function build(transformerConfig) { | ||
glob('./src/**/*.{js,ts,tsx}', (errs, fileNames) => { | ||
if (errs) { | ||
console.log(errs) | ||
process.exit(1) | ||
} | ||
const parseRet = getCompilerOptions() | ||
if (parseRet.errors.length > 0) { | ||
console.log(parseRet.errors) | ||
process.exit(1) | ||
} | ||
const transformer = transformerConfig | ||
? tsImportPluginFactory(transformerConfig) | ||
: undefined | ||
|
||
compiler(fileNames, parseRet.options, transformer) | ||
}) | ||
} |