Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 8, 2019. It is now read-only.
/docsPublic archive

usage with bower

Michael Klein edited this pageMar 21, 2016 ·9 revisions

To use components from bower you need to add two things to webpack:

  • Let webpack look in thebower_components folder.
  • Let webpack use themain field from thebower.json file.

Configuration

Seeconfigurationresolve.modulesDirectories andlist of pluginsResolverPlugin.

varpath=require("path");varwebpack=require("webpack");module.exports={resolve:{modulesDirectories:["web_modules","node_modules","bower_components"]},plugins:[newwebpack.ResolverPlugin(newwebpack.ResolverPlugin.DirectoryDescriptionFilePlugin(".bower.json",["main"]))]}

Prefer modules from npm over bower

In many cases modules from npm are better than the same module from bower. Bower mostly contain only concatenated/bundled files which are:

  • More difficult to handle for webpack
  • More difficult to optimize for webpack
  • Sometimes only useable without a module system

So prefer to use the CommonJs-style module and let webpack build it.

Example react

bower package vs. npm package

Note: the bower package is built with browserify and envify (NODE_ENV = "production")

So we compare four configurations:

a) webpack + bower package (DefinePlugin makes no difference here as envify already removed debug code)

b) webpack + bower package +module.noParse for react

c) webpack + npm package

d) webpack + npm package +DefinePlugin withNODE_ENV = "production"

configurationmodulesbundle sizecompilation time
a)1136k100%
b)1136k73,6%
c)136130k89,9%
d)135127k85,3%

(webpack 1.3.0-beta8, react 0.10.0, bundle size minimized)

webpack 👍

Clone this wiki locally


[8]ページ先頭

©2009-2025 Movatter.jp