1.7.0 • Published 4 years ago

@malmo/cli-utils v1.7.0

Weekly downloads
9
License
MIT
Repository
github
Last release
4 years ago
┌─────────────────┐
│ ┌┬┐┌─┐┬  ┌┬┐┌─┐ │
│ │││├─┤│  ││││ │ │
│ ┴ ┴┴ ┴┴─┘┴ ┴└─┘ │
└─────────────────┘

A cli interface to build Javascript applications with zero configuration.

Installation

  • With yarn: yarn global add malmo
  • With npm: npm install -g malmo

Available commands

  • malmo init Initialize configuration wizard. Remote and locale packages that contain malmo and starter-kit in their names will be listed.
  • malmo dev Launch dev server
  • malmo build Build your application
  • malmo config Print current configuration

Available options

  • -h, --help Print the usage guide
  • -v, --version Print package version
  • -w, --watch Restart compilation on configuration files changes
  • --env [key] Use env[key] configuration from malmo.config.js-

malmo.config.js

Use this file for overwrite or extend all the settings used by the malmo cli:

ParameterDescriptionTypeRequiredDefaultAvailable in the global CONSTANTS object
bootstrapExpressAppInvoke Express.listen methodbooleanNODE_ENV === 'production'true
cleanClean dist folder before launch dev serverbooleantruefalse
distName of the dist folderstringdistfalse
publicPathWebpack output.publicPath settingstring | true
portExpress application portnumberfirst available porttrue
rootThe project browser address, opened after malmo devnumber{PROTOCOL}://{IP}:{PORT}true
staticFolderThe public folder where all the bundled files will be placedstring | false
https.keyKey certificate pathstring | false
https.certCert certificate pathstring | false

Environment

Each setting is overwritable with the env key:

module.exports = {
    bootstrapExpressApp: true,
    foo: 100, // custom constant, see above
    env: {
        staging: {
            bootstrapExpressApp: false,
            foo: 200,
        }
    }
}

Global CONSTANTS object

Thanks to webpack.DefinePlugin, those settings are propagated from malmo to each webpack entries in the global CONSTANTS object:

malmo dev

/* global CONSTANTS */
console.log(CONSTANTS.foo) // 100

malmo dev --env=staging

/* global CONSTANTS */
console.log(CONSTANTS.foo) // 200

malmo.loaders-config.js

Use this configuration for overwrite or extend all the settings used by the default malmo webpack loaders:

KeyOptions
cssHotsee https://github.com/shepherdwind/css-hot-loader for all the available options
csssee https://webpack.js.org/loaders/css-loader for all the available options
cssNodeModulescss-loader settings applied to the node_modules folder
scsssee https://webpack.js.org/loaders/sass-loader for all the available options
filesee https://webpack.js.org/loaders/file-loader for all the available options
jssee https://github.com/babel/babel-loader for all the available options

If you need to add same external folders to the babel transpile, use the js.include option:

const path = require('path');

module.exports = {
    js: {
        include: path.resolve(__dirname, 'node_modules', 'my-module')
    }
}

malmo.plugins-config.js

Use this configuration for overwrite or extend all the settings used by the default malmo webpack plugins:

KeyOptions
miniCssExtractPluginsee https://webpack.js.org/plugins/mini-css-extract-plugin for all the available options
uglifyJsPluginsee https://www.npmjs.com/package/uglifyjs-webpack-plugin for all the available options
htmlWebpackPluginsee https://github.com/jantimon/html-webpack-plugin#options for all the available options
module.exports = {
    htmlWebpackPlugin: {
        title: "Project Title"
    }
}

malmo.webpack-config.js

Use this configuration for extend the webpack configuration:

module.exports = {
    module: {
      rules: [
        {
          test: /\.(glsl|frag|vert)$/,
          use: [
              'raw-loader',
              'glslify-loader',
            ],
        },
      ],
    },
}

malmo.express-config.js

Use this configuration for extend the express application used in ssr mode:

const cors = require('cors');

module.exports = (app, options) => {
  app.use(cors());
  return app;
};

Configuration format

Each configuration can be written as a simple js object, or as a function that returns an object. The object will be merged with the defaults thanks to the webpack-merge package. If you use a function, all the settings are passed as arguments:

  • malmo.loaders-config.js
  • malmo.plugins-config.js
  • malmo.webpack-config.js
module.exports = ({
    foo,
    port,
    others...
}) => ({
    
})
  • malmo.express-config.js
module.exports = (app, {
    foo,
    port,
    others...
}) => ({
    
})

Merge strategy

For customize the webpack-merge strategy, export a named variable called strategy:

module.exports = { ... };

module.exports.strategy = { css: 'replace' };

Environment variables

This are the environment variables available in all the configuration files:

KeyDescription
process.env.SERVERtrue if the configuration is used by the server.js entry
process.env.NODE_ENVdevelopment or production, based on the launched command
process.env.PORTthe node process port

Shared node packages

In all the configuration files, these modules are linked from the malmo folder, so it's not necessary to install them:

  • express
  • modernizr
  • html-webpack-plugin
  • mini-css-extract-plugin
  • uglifyjs-webpack-plugin
  • webpack
  • webpack-merge