webpack模板

'use strict';

// Modules
var webpack = require('webpack');
var autoprefixer = require('autoprefixer-core');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var CleanWebpackPlugin = require('clean-webpack-plugin')
var path = require('path')


var config = {};


config.entry = {
  app: './src/app.js',
  vendor:['angular', 'angular-animate', 'jquery', '@uirouter/angularjs']
}

config.output = {
  // target directory for all output files
  // must be absolute path
  path: __dirname + '/build',

  // the url to the output directory resolved relative to the HTML page
  // Uses webpack-dev-server in development
  publicPath: '/',

  // filename template for entry chunks
  filename: '[name].[hash].js',
}

config.devtool = 'eval';


// Initialize module
config.module = {
  rules: [{
    test: /\.js$/,
    use: [
      {
        loader: 'babel-loader',
        options: {
          optional: 'runtime'
        }
      }
    ],
    exclude: /node_modules/
  }, {
    test: /\.(png|jpg|gif)$/, 
    use: [
      {
        loader: 'url-loader',
        options: {
          limit: 8192
        }
      }
    ]
  }, {
      test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, 
      use: [
        {
          loader: 'url-loader',
          options: {
            limit: 10000,
            mimetype: "application/font-woff"
          }
        }
      ]
  }, {
      test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, 
      use: [
        {
          loader: 'file-loader'
        }
      ]
  }, {
    test: /\.html$/,
    use: [
      {
        loader: 'raw-loader'
      }
    ]
  }, {
    test: /\.(less|css)$/,
    use: ExtractTextPlugin.extract({
      fallback: 'style-loader',
      use: ['css-loader', 'less-loader']
    })
  }]
};

config.devServer = {
  // static file location for devServer
  contentBase: path.join(__dirname, '/build'),
  hot: true,
  port: 9000
}

config.plugins = [
  new HtmlWebpackPlugin({
    filename: 'index.html',
    template: 'src/index.html',
    inject: 'body'
  }),
  new ExtractTextPlugin('style.css'),
  new webpack.ProvidePlugin({
    $: 'jquery',
    jQuery: 'jquery'
  }),
  new webpack.optimize.CommonsChunkPlugin({
    name: 'vendor',
    minChunks: 2
  }),
  new CleanWebpackPlugin(
    ['build'], // delete bib directory before every build
    {
      root: __dirname, // root directory
      verbose: true,   // display console infomation
    }
  )
]
module.exports = config 

转载于:https://my.oschina.net/boogoogle/blog/1507379

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值