A tool for common tasks in Javascript projects.
- Transpile to ES6/Typescript
- Support React/Angular 1.x (2.0 will be supported soon)
- Browser tests using protractor / Selenium Webdriver
- Unit tests using Jest/Mocha/karma
- ESlint/TSlint
- CSS Modules
- Sass
- Local dev environment running node server / cdn server
- Wallaby
- async/await (
babel-polyfill
needed) - Minify/Uglify
- Bundle JS/CSS using Webpack
- External/Inline css
- Webpack 2 (tree shaking)
- HMR
npm install --save-dev yoshi
In your package.json
:
{
"scripts": {
"start": "yoshi start",
"pretest": "yoshi lint && yoshi build",
"test": "yoshi test",
"build": ":",
"release": "yoshi release" //only needed if you publish to npm
...
}
}
Or within the command line:
yoshi [command] [options]
For a quick start, take a look at our generators:
npm install -g yo
npm install -g generator-yoshi
Then generate your new project:
yo yoshi
The following sections describe the available tasks in yoshi
. You can always use the --help
flag for every task to see its usage.
Flag | Short Flag | Description | Default Value |
---|---|---|---|
--entry-point | -e | Entry point for the app. | ./dist/index.js |
--manual-restart | get SIGHUP on change and manage application reboot manually | false |
This will run the specified (server) entryPoint
file and mount a CDN server.
The following are the default values for the CDN server's port, mount directory and whether to serve statics over https or regular http. You can change them in your package.json
:
"yoshi": {
"servers": {
"cdn": {
"port": 3200,
"dir": "dist/statics",
"ssl": false
}
}
}
Flag | Short Flag | Description | Default Value |
---|---|---|---|
--output | The output directory for static assets. | statics |
|
--analyze | run webpack-bundle-analyzer plugin. |
This task will perform the following:
- Compile using
TypeScript
(*.ts
) orbabel
(*.js
) files intodist/
. In case you do not want to transpile server (node), you can remove.babelrc
/tsconfig
/package json'sbabel
key. If you still need those (for transpiling client code), please useyoshi.runIndividualTranspiler
. - Copy assets to
dist
folder (ejs/html/images...).
You can specify multiple entry points in your package.json
file. This gives the ability build multiple bundles at once. More info about Webpack entries can be found here.
"yoshi": {
"entry": {
"a": "./a",
"b": "./b",
"c": ["./c", "./d"]
}
}
Note: if you have multiple entries you should consider using the Commons Chunk Plugin
Note2: the decision whether to use TypeScript
or babel
is done by searching tsconfig.json
inside the root directory.
Flag | Description |
---|---|
--mocha | Run unit tests with Mocha - this is the default |
--jasmine | Run unit tests with Jasmine |
--karma | Run tests with Karma (browser) |
--jest | Run tests with Jest |
--protractor | Run e2e tests with Protractor (e2e) |
By default, this task executes both unit test (using mocha
as default) and e2e test using protractor
.
Default unit test glob is {test,app,src}/**/*.spec.+(js|ts)
. You can change this by adding the following to your package.json:
yoshi: {
specs: {
node: 'my-crazy-tests-glob-here'
}
}
-
Note that when specifying multiple flags, only the first one will be considered, so you can't compose test runners (for now).
-
Mocha tests setup:
You can add a
test/mocha-setup.js
file, with mocha tests specific setup. Mocha willrequire
this file, if exists. Example for suchtest/mocha-setup.js
:import 'babel-polyfill'; import 'isomorphic-fetch'; import sinonChai from 'sinon-chai'; import chaiAsPromised from 'chai-as-promised'; import chai from 'chai'; chai.use(sinonChai); chai.use(chaiAsPromised);
-
Karma tests setup:
When running tests using Karma, make sure you have the right configurations in your
package.json
as described inyoshi.specs
section. In addition, if you have akarma.conf.js
file, the configurations will be merged with our built-in configurations. -
Jasmine tests setup:
Specifying a custom glob for test files is possible by configuring
package.json
as described inyoshi.specs
. The default glob matches.spec.
files in all folders.
If you wish to load helpers, import them all in a file placed at'test/setup.js'
.
Flag | Short Flag | Description |
---|---|---|
--fix | Automatically fix lint problems (works only for eslint) |
Executes TSLint
or ESLint
(depending on the type of the project) over all matched files. An '.eslintrc' / tslint.json
file with proper configurations is required.
Bump package.json
version and publish to npm using wnpm-release
.
Configurations are meant to be inside package.json
under yoshi
section or by passing flags to common tasks.
See above sections.
By default, your require
d css will bundled to a separate app.css
bundle. You can leave your css in main js bundle by adding the following to your package.json
:
"yoshi": {
"separateCss": false
}
We use css modules as default. You can disable this option any time by adding the following to wix section inside your package.json
:
"yoshi": {
"cssModules": false
}
Disabling cssModules on a specific css file is possible by adding .global
before file extention.
For example:
./Counter.global.scss
//no css modules for this file
Using css modules inside your component is easy:
import s from './Counter.scss';//import css/scss
<p className={s.mainColor}>{counterValue}</p>
Using css when css modules are turned off:
import './Counter.scss';//import css/scss
<p className="mainColor">{counterValue}</p>
Explanation is in cli/build section.
Explanation is in cli/start section.
Prevent bundling of certain imported packages and instead retrieve these external dependencies at runtime (as a script tags)
{
"yoshi": {
"externals": {
"react": "React"
}
}
}
Specs globs are configurable. browser
is for karma, node
is for mocha and jasmine.
{
"yoshi": {
"specs": {
"browser": "dist/custom/globs/**/*.spec.js",
"node": "dist/custom/globs/**/*.spec.js"
}
}
}
For example:
{
"yoshi": {
"specs": {
"browser": "dist/src/client/**/*.spec.js",
"node": "dist/src/server/**/*.spec.js"
}
}
}
In case you don't want to transpile your server (node) code, and you still need .babelrc
/tsconfig
, you can add runIndividualTranspiler
flag to skip server transpiling.
You can explicitly ask build process to transpile some node modules in case those modules do not contain transpiled code. Note that this is not a recommended workflow. It can be very error prone:
- It might be for example that your app babel config and the node module babel config will be conflicting.
- Any babel plugin that is used by your dependencies will need to be installed by your app as well.
- You'll need to also add nested dependencies that need transpiling into array, which can be confusing.
Anyway, if you don't have a better alternative you can pass array with module names in this property.
If set, export the bundle as library. yoshi.exports
is the name.
Use this if you are writing a library and want to publish it as single file. Library will be exported with UMD
format.
- How do I debug my application/tests?
- How to add external assets to my client part of the project?
- How do I setup Enzyme test environment?
- How to disable css modules in specific places
- How to I analyze my webpack bundle contents
- How do I separately bundle common logic for multiple entries?
- How to use SVG
- Moment.js locales are missing