12.2.1 • Published 4 years ago

bcd-react-webpack v12.2.1

Weekly downloads
1
License
MIT
Repository
-
Last release
4 years ago

bcd-react-webpack

Use webpack painless.

examples

Usage

1. install

npm install --save-dev webpack webpack-cli webpack-dev-server bcd-react-webpack

2. update package.json

{
  "scripts": {
    "start": "webpack-dev-server --hot",
    "build": "NODE_ENV=production webpack"
  }
}

3. create webpack config file

create webpack config file webpack.config.js

const createConfig = require('bcd-react-webpack');

const env = process.env.NODE_ENV || 'development';

module.exports = createConfig({
  publicPath: env === 'development' ? '/' :
    // TODO: online assets url prefix, you should modify this
    'https://lesspage.oss-cn-shanghai.aliyuncs.com/'
});

4. add sass support

npm install --dev node-sass sass-loader

5. add typescript support

  • add tsconfig.js
{
  "compilerOptions": {
    "module": "commonjs",
    "sourceMap": true,
    "esModuleInterop": true,
    "target": "ES2020",
    "jsx": "react"
  }
}
  • install type declaration
npm install -D @types/react @types/react-dom @types/prop-types

Detail

1. project structure

- config/
  - webpack.config.js

- src/
  - template.html    # tempalte file for HtmlWebpackPlugin

  - pages/           # deduce webpack entries from pages dir
    - index/
      - index.js

    - design/           # muti entry support
      - index.js
      - index.html         # custom template

  - components/     # arbitrarily dir/packages。
  - utils/

- package.json

We also alias '@' for src dir.

import Avatar from '@/components/Avatar';
// import Avatar from '../../../../components/Avatar';

2. stage

Muti entry pages may slowdown the building in current webpack-dev-server, use arg --stage for only build specify entry page.

You can also config stage in config for forcing specify this arg in dev and build phase.

module.exports = createConfig({
  ...,
  stage: true
});

in package.json

{
  "scripts": {
    "start": "webpack-dev-server --hot --config config/webpack.config.js"
  }
}
npm run start --stage mypage

3. custom config

module.exports = createConfig({
  publicPath: env === 'development' ? '/' : './',

  devServer: { ... },        // @see https://webpack.js.org/configuration/dev-server/
  shouldUseSourceMap: true,  // use 'source-map', current default use 'cheap-module-source-map'
  extractCss: true,

  srcPath: 'src',            // source dir
  distPath: 'dist',          // output dir
  assetsDir: { js: 'js/', css: 'css/', media: 'media/' },   // output assets dir
  pagesPath: 'pages',

  digest: false,             // in production env, default to true
  swPrecache: false,         // disable SWPrecacheWebpackPlugin
  manifest: false,           // disable manifest file
  manifest: { fileName },    // custom manifest filename
  bundleAnalyzer: false,     // disable analyzer plugin
});
12.2.1

4 years ago

12.0.0

4 years ago

12.1.0

4 years ago

12.2.0

4 years ago

11.0.0

4 years ago

11.0.1

4 years ago

11.0.0-beta.1

4 years ago

11.0.0-beta.2

4 years ago

11.0.0-beta.3

4 years ago

11.0.0-alpha.1

4 years ago

10.3.0

4 years ago

10.2.2

4 years ago

10.2.1

4 years ago

10.1.0

4 years ago

10.2.0

4 years ago

10.0.0

4 years ago

10.0.0-beta.1

4 years ago

9.0.0

4 years ago

9.0.0-beta.2

4 years ago

9.0.0-beta.1

4 years ago

8.0.0

5 years ago

7.0.0

5 years ago

7.0.0-beta

5 years ago

6.0.1

5 years ago

6.0.0

5 years ago

5.0.0

5 years ago

4.2.1

5 years ago

4.2.0

5 years ago

4.1.0

5 years ago

4.0.0

5 years ago

3.3.0

6 years ago

3.2.0

6 years ago

3.1.0

6 years ago

3.0.1

6 years ago

3.0.0

6 years ago

2.2.0

6 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.0

6 years ago

1.4.1

6 years ago

1.4.0

6 years ago

1.3.1

6 years ago

1.3.0

6 years ago

1.2.0

6 years ago

1.1.0

6 years ago