12.0.0 • Published 3 years ago

pobpack-browser v12.0.0

Weekly downloads
3
License
ISC
Repository
github
Last release
3 years ago

#features)

Features

  • Start without config
  • Hot Module Reload
  • Human readable errors
  • You can override everything in the webpack config

Install

yarn add pobpack-browser
npm install --save pobpack-browser

Usage

package.json

{
  "scripts": {
    "build": "pobpack-browser build",
    "start": "pobpack-browser"
  }
}
npm run start

Targets

There is two targets : modern and all.

You can use modern to build a specific file for browsers that supports es modules, and import like this:

<script defer src="/all.js" nomodule></script>
<script defer src="/modern.js" type="module"></script>

You should also use polyfill.io to import polyfills and reduce build size. Some modules are removed for their native implementation:

Configuration Options

You can create a file named createWebpackConfig.js next to package.json:

module.exports = function (config, options) {
  return config({
    ...options,
    babel: {}, // babel config (see below)
    jsLoaders: {}, // add more webpack loaders to js/jsx (see below)
    moduleRules: [], // add more webpack rules
    prependPlugins: [], // prepend plugins
    plugins: [], // append plugins
    paths: { src: 'src', build: 'public' },
  });
};

Hot Reload

You should read webpack documentation about HMR

react-hot-loader 4 is included

App.js

import React from 'react';
import hot from 'pobpack-browser/hot';

const App = () => <div>Hello world!</div>;

export default hot(App);

You can activate accept hot-reload by default with webpack-module-hot-accept (not recommended)

createWebpackConfig.js

module.exports = function (config, options) {
  return config(
    Object.assign({}, options, {
      jsLoaders: ['webpack-module-hot-accept'],
    }),
  );
};

Configuration examples

module.exports = function (config, options) {
  return config(Object.assign({}, options, {}));
};

Add a webpack plugin

module.exports = function (config, options) {
  return config(
    Object.assign({}, options, {
      plugins: [new WebPackPlugin()],
    }),
  );
};

You can also do:

module.exports = function (config, options) {
  config = config(options);
  config.plugins.push(new WebPackPlugin());
  return config;
};

Add a babel plugin

const babelPlugin = require('babel-plugin-example');

module.exports = function (config, options) {
  return config(
    Object.assign({}, options, {
      babel: {
        plugins: [babelPlugin],
      },
    }),
  );
};

Override babel preset

const babelPlugin = require('babel-plugin-example');

module.exports = function (config, options) {
  return config(
    Object.assign({}, options, {
      babel: {
        presets: ['pobpack/babel', 'stage-1'],
      },
    }),
  );
};

Add webpack loaders

pobpack handle json and js/jsx files

const babelPlugin = require('babel-plugin-example');

module.exports = function (config, options) {
  return config(
    Object.assign({}, options, {
      loaders: [
        // add your loaders
      ],
    }),
  );
};

Add js/jsx loaders

const babelPlugin = require('babel-plugin-example');

module.exports = function (config, options) {
  return config(
    Object.assign({}, options, {
      jsLoaders: [
        // add your loaders
      ],
    }),
  );
};

Alternatives

12.0.0

3 years ago

10.0.0

3 years ago

11.0.0

3 years ago

11.0.1

3 years ago

9.0.0

4 years ago

8.1.1

4 years ago

8.1.0

4 years ago

8.0.4

4 years ago

8.0.3

4 years ago

8.0.1

4 years ago

8.0.2

4 years ago

8.0.0

4 years ago

7.7.7

5 years ago

7.7.6

5 years ago

7.7.5

5 years ago

7.7.4

5 years ago

7.7.3

5 years ago

7.7.2

5 years ago

7.7.1

5 years ago

7.7.0

5 years ago

7.6.1

5 years ago

7.6.0

5 years ago

7.5.1

5 years ago

7.5.0

5 years ago

7.4.1

5 years ago

7.4.0

5 years ago

7.3.0

5 years ago

7.2.0

5 years ago

7.1.0

5 years ago

7.0.1

5 years ago

7.0.0

5 years ago

6.2.0

5 years ago

6.1.0

6 years ago

6.0.2

6 years ago

6.0.1

6 years ago

6.0.0

6 years ago

5.0.6

6 years ago

5.0.5

6 years ago

5.0.4

6 years ago

5.0.3

6 years ago

5.0.2

6 years ago

5.0.1

6 years ago

5.0.0

6 years ago

4.1.4

6 years ago

4.1.3

6 years ago

4.1.2

6 years ago

4.1.1

6 years ago

4.1.0

6 years ago

4.0.0

6 years ago

3.2.1

6 years ago

3.2.0

6 years ago

3.1.2

6 years ago

3.1.1

7 years ago

3.1.0

7 years ago

3.0.3

7 years ago

3.0.2

7 years ago

3.0.1

7 years ago

3.0.0

7 years ago

2.2.0

7 years ago

2.1.0

7 years ago

2.0.2

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.1.0

7 years ago

1.0.0

7 years ago

0.6.1

7 years ago

0.5.0

7 years ago

0.4.1

7 years ago

0.4.0

7 years ago

0.3.0

7 years ago

0.2.0

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago