Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to specify Babel CLI extensions argument. #561

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.26.0 / 2020-10-20
## Fixes
- Allow to specify Babel CLI extensions argument. This makes it possible to compile Typescript components.

## Dependencies

- @babel/cli: v7.8.4 → [v7.10.3](https://github.com/babel/babel/blob/master/CHANGELOG.md#v7102-2020-05-30)
Expand Down Expand Up @@ -38,6 +42,7 @@

- Don't include `docs/` in the npm package.


# 0.25.0 / 2020-05-20

## Breaking Changes
Expand Down
19 changes: 19 additions & 0 deletions docs/guides/ReactComponents.md
Original file line number Diff line number Diff line change
Expand Up @@ -437,3 +437,22 @@ Use this if you want to develop against the demo app using nwb's development ser
Disables `propTypes` wrapping/stripping.

Use this if your module needs to use `propTypes` at runtime (e.g. for masking `props`), or you think its users might need them.

#### `--extensions` (a.k.a `-x`)

Allows to pass custom extensions that will be taken into account when building the component.

##### Typescript
1. CLI
```
--extensions ['.ts', '.tsx']
```

2. package.json
```
"scripts": {
"build": "nwb build-react-component --extensions '.ts,.tsx'",
}
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "nwb",
"description": "A toolkit for React, Preact & Inferno apps, React libraries and other npm modules for the web, with no configuration (until you need it)",
"version": "0.25.2",
"version": "0.26.0",
"license": "MIT",
"author": "Jonny Buchanan <[email protected]>",
"bin": {
Expand Down
7 changes: 6 additions & 1 deletion src/moduleBuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const DEFAULT_BABEL_IGNORE_CONFIG = [
/**
* Run Babel with generated config written to a temporary .babelrc.
*/
function runBabel(name, {copyFiles, outDir, src}, buildBabelConfig, userConfig, cb) {
function runBabel(name, {copyFiles, outDir, src, extensions}, buildBabelConfig, userConfig, cb) {
let babelConfig = createBabelConfig(buildBabelConfig, userConfig.babel, userConfig.path)
babelConfig.ignore = DEFAULT_BABEL_IGNORE_CONFIG

Expand All @@ -37,6 +37,10 @@ function runBabel(name, {copyFiles, outDir, src}, buildBabelConfig, userConfig,
args.push('--copy-files', '--no-copy-ignored')
}

if (extensions) {
args.push('--extensions', extensions)
}

fs.writeFile('.babelrc', JSON.stringify(babelConfig, null, 2), (err) => {
if (err) return cb(err)
let spinner = ora(`Creating ${name} build`).start()
Expand Down Expand Up @@ -131,6 +135,7 @@ export default function moduleBuild(args, buildConfig = {}, cb) {
let babelCliOptions = {
copyFiles: !!args['copy-files'],
src: path.resolve('src'),
extensions: args['extensions'] || args['x'],
}

let tasks = [(cb) => cleanModule(args, cb)]
Expand Down