1.18.8 • Published 2 years ago

@viewar/webpack v1.18.8

Weekly downloads
36
License
MIT
Repository
github
Last release
2 years ago

@viewar/webpack

Build Status PRs Welcome NPM Release Conventional Commits Semantic Versioning

latest CHANGELOG

ATTENTION: All conventional-commits merged into master will trigger a new release!

Installation

npm i @viewar/webpack

includes all packages related to webpack:
*-loader's, babel-presets/plugins, typescript-presets/plugins, karma-plugins + puppeteer, sass/postcss, etc.

Usage

Info: no need to add babel config for webpack usage,
as it is already included in webpacks babel-loader options

node - default

// webpack.config.js
module.exports = require('@viewar/webpack');

node - extended

// webpack.config.js
const configViewAr = require('@viewar/webpack');

module.exports = env => {
  const config = configViewAr(env);
  // modify config as you need
  config.plugins.push(new MySpecialPlugin());
  return config;
};

node - project types

@viewar/webpack is able to handle different types of projects:

  • "react-js": React with Javascript (default)
  • "react-ts": React with Typescript (deprecated)
  • "angular": Angular - not available yet
  • "angularjs: AngularJS - not available yet
// webpack.config.js
const configViewAr = require('@viewar/webpack');

module.exports = env => {
  // Use react with typescript as project type.
  return configViewAr(env, {
    type: 'react-js',
  });
};

cli

webpack-dev --config ./node_modules/@viewar/webpack or
webpack-dev-server --config ./node_modules/@viewar/webpack

Constants

namedefaultenv overwrite
PATHS.src'src'WEBPACK_PATH
PATHS.assets'assets'WEBPACK_ASSETS
PATHS.build'build'WEBPACK_BUILD
PORT8080PORT

Features

Module Resolver

  • enables absolute import paths
    like import Header from 'components/Header'

  • uses 'tsconfig-paths-webpack-plugin' to resolve import paths
    requires: workspaceRoot/tsconfig.json

  • if tsconfig.json is not present it won't use that plugin
    and uses the default resolve config:

      resolve: {
        extensions: ['.jsx', '.js', '.ts', '.tsx', '.json'],
        // paths are relative to workspace root
        alias:      { assets: PATHS.assets },
        modules: [PATHS.src, 'node_modules'],
      }
    • if you use '/src' you probably don't have to change anything
    • overwrite PATHS.src with WEBPACK_PATH (see constants)
  • you can overwrite this config to fit your projects module resolvement,
    if you add 'webpack.config.resolve.js' to your workspaceRoot
    (use format of 'src/webpack.config.resolve.js')

remote console

// on client
import { remoteConsoleInjector } from '@viewar/webpack/remoteConsole';

remoteConsoleInjector();

all native console outputs are sent to our endpoint of remote-console,
and get catched server-side to log them in the terminal.

The endpoint '/remote-console' is injected per webpack-dev-server's 'before' function:
webpackConfig.devServer.before = viewArMiddleware;

TODO: see issues #17 and #39

errorOnUsedPort()

before exporting the config,
we check if the port is free to use and throw an Error, if not.

Integration Tests per 'karma-webpack'

may be moved to own package together with cypress setup in undefined future

Usage
npm i karma --save-dev npx karma start ./node_modules/@viewar/webpack/karma

Explanation
Karma is a test runner for JavaScript applications with several features integrated:

  • real browser instances - no fake DOM!
    supports Chrome, Firefox, IE11+, Safari
    uses headless chrome in CI environment
  • native webpack module bundling
    'karma-webpack' lets you use your projects webpack config
  • built-in mocha runner
    • 'chai' for unit-test assertions (expect, should, ...)
    • 'enzyme' for integration-tests (shallow, mount, render)
    • 'chai-enzyme' for extended integration-tests assetions

Configuration

karma - src/test/karma.config.js
contains karma-config: file pattern, karma plugins, browser settings, usw, ...

mocha - src/test/mocha.setup.js
contains mocha setup: configures chai-enzyme and sets up global assertion functions

Writing Tests

  • example integration tests
    /test/App.spec.js and /test/components/Test.spec.js
  • component related assertions ➡️ 'chai-enzyme'
1.18.8

2 years ago

1.18.7

2 years ago

1.18.1

2 years ago

1.18.0

2 years ago

1.17.0

2 years ago

1.18.5

2 years ago

1.18.4

2 years ago

1.18.3

2 years ago

1.18.2

2 years ago

1.18.6

2 years ago

1.16.2

3 years ago

1.16.1

3 years ago

1.16.0

3 years ago

1.15.0

3 years ago

1.14.1

4 years ago

1.14.0

4 years ago

1.13.2

4 years ago

1.13.1

4 years ago

1.13.0

4 years ago

1.12.3

4 years ago

1.12.2

4 years ago

1.12.1

4 years ago

1.12.0

4 years ago

1.11.1

4 years ago

1.11.0

4 years ago

1.10.6

4 years ago

1.10.5

4 years ago

1.10.4

4 years ago

1.10.3

4 years ago

1.10.2

4 years ago

1.10.1

4 years ago

1.10.0

4 years ago

1.9.4

4 years ago

1.9.3

4 years ago

1.9.2

4 years ago

1.9.1

4 years ago

1.9.0

4 years ago

1.8.2

4 years ago

1.8.1

4 years ago

1.8.0

4 years ago

1.7.0

4 years ago

1.6.0

4 years ago

1.5.4

4 years ago

1.5.3

4 years ago

1.5.2

4 years ago

1.5.1

4 years ago

1.5.0

4 years ago

1.4.0

5 years ago