Giter Site home page Giter Site logo

lawebpackba's Introduction

lawebpackba

#####Setting up babel-loader review syntax

module.exports = {
  entry: './src/main.js,
  output:{
    path:'build',
    filename:'bundle.js'
  },
  module:{
    loaders:[
      {
        test:/\.js$/,
        exclude:/(node_modules)/,
        loader:'babel'
      }
    ]
  }
}

#####Using presets

module.exports = {
  entry: './src/main.js,
  output:{
    path:'build',
    filename:'bundle.js'
  },
  module:{
    loaders:[
      {
        test:/\.js$/,
        exclude:/(node_modules)/,
        loader:'babel',
        query:{
          presets:['es2015']
        }
      }
    ]
  }
}

.babelrc

{
  'presets':[
    'es2015'
  ]
}

install

babel-core babel-loader babel-preset-es2015

#####coffee

npm install coffee-loader

####3 webpack and CSS #####Basic

module.exports = {
  entry: './src/main.js,
  output:{
    path:'build',
    filename:'bundle.js'
  },
  module:{
    loaders:[
      {
        test:/\.js$/,
        exclude:/(node_modules)/,
        loader:'babel',
        query:{
          presets:['es2015']
        }
      },
      {
        test:/\.css$/,
        loader:'style-loader!css-loader'
      }
    ]
  }
}

#####Transpiling Sass with webpack

npm install sass-loader node-sass --save-dev

small change

{
  test:/\.scss$/,
  loader:'style-loader!css-loader!sass-loader'
}

#####Loading images with webpack

npm install url-loader file-loader --save-dev

add loader

{
  test:/\.(png|jpg)$/,
  loader:'url-loader?limit=20000'  //if bigger than 20k ,create url asset
}

####4 Code splitting #####Adding multiple entry points create bundle respectively

var webpack = require('webpack');
var path = require('path');
module.exports = {
  entry:{ 
    a:'./dist/a',
    b:'./dist/b'
  },
  output:{
    path:path.join(__dirname,'build'),
    filename:'[name].bundle.js'
  },

#####Using the commons chunk bundle

var CommonsChunkPlugin = require('./node_modules/webpack/lib/optimize/CommonsChunkPlugin')

Update:

module.exports = {
  entry: './src/main.js,
  output:{
    path:'build',
    filename:'bundle.js'
  },
  module:{
    loaders:[
      {
        test:/\.js$/,
        exclude:/(node_modules)/,
        loader:'babel',
        query:{
          presets:['es2015']
        }
      },
      {
        test:/\.css$/,
        loader:'style-loader!css-loader'
      }
    ]
  },
  plugins:[
    new CommonsChunkPlugin('commons','commons.bundle.js')//bundle all
  ]
}

#####Bundling vendor files

webpack dev server

#####Setting up the webpack-dev-server

module.exports = {
  entry: './dist/app.js,
  output:{
    path:'build',
    filename:'bundle.js'
  },
  devServer:{
    inline:true,
    contentBase:'./build',
    port:3000
  },
  module:{
    loaders:[
      {
        test:/\.js$/,
        exclude:/(node_modules)/,
        loader:'babel',
        query:{
          presets:['es2015']
        }
      },
      {
        test:/\.css$/,
        loader:'style-loader!css-loader'
      }
    ]
  }
}

lawebpackba's People

Contributors

rengokantai avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.