Git Product home page Git Product logo

study-webpack's Introduction

study-webpack

this is a study project for webpack !

The kewords of webpack

Install

  • npm install --save webpack
  • npm install --save webpack@
  • npm install --save-dev webpack-cli
  • package.json
    • "scripts": { "build": "webpack --config webpack.config.js" }
    • npm run build
  • 不建议全局安装

Start

const path = require('path')

module.exports = {
    entry: './src/index.js',
    output: {
        filename: 'bundle.js',
        path: path.resolve(__dirname, 'dist')
    }
};

Assets Management

  • npm install --save-dev style-loader css-loader
  • npm install --save-dev file-loader
  • image-webpack-loader
  • url-loader
  • csv-loader
  • xml-loader

Output Management

  • npm install --save-dev html-webpack-plugin
  • npm install --save-dev clean-webpack-plugin

Development

  • webpack.config.js -> devtool: 'inline-source-map'
  • webpack自动编译
    • webpack's Watch Mode
      • package.json -> "watch": "webpack --watch"
    • webpack-dev-server
      • npm install --save-dev webpack-dev-server
      • webpack.config.js -> devServer: { contentBase: './dist' }
      • package.json -> "start": "webpack-dev-server --open"
    • webpack-dev-middleware
      • webpack-dev-middleware 配合 express server 的示例
      • npm install --save-dev express webpack-dev-middleware
      • webpack.config.js -> output -> publicPath: '/'
      • package.json -> "server": "node server.js"
      • server.js 如下:
const express = require('express')
const webpack = require('webpack')
const webpackDevMiddleware = require('webpack-dev-middleware')

const app = express()
const config = require('./webpack.config.js')
const compiler = webpack(config)

app.use(webpackDevMiddleware(compiler, {
    publicPath: config.output.publicPath
}))

app.listen(3000, function(){
    console.log('xample app listening on port 3000!\n')
})

Hot Module Replacement (HMR)

study-webpack's People

Contributors

jinlixing avatar

Watchers

James Cloos 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.