webpack配置

 1 var webpack = require('webpack');
 2 var path = require("path");
 3 module.exports = {
 4     // context: __dirname + "/src",//The base directory (absolute path!)
 5     // 表示入口文件
 6     cache: true,
 7     entry: {
 8         'bundle': './src',
 9         // 'app2': '/src/app2'
10     },
11     minimize: true,
12     // 表示输出文件
13     output: {
14         path: path.join(__dirname, "build"),// 编译好的文件目录
15         filename: '[name].min.js',
16         chunkFilename: "[chunkhash].min.js"
17         // sourceMapFilename: '[file].map'
18         // publicPath: "/build/" // 引用你的文件时考虑使用的地址
19     },
20     // 表示这个依赖项是外部lib,遇到require它不需要编译,
21     // 且在浏览器端对应window.React
22     externals: [
23         {
24             'react': 'window.React',
25             'react-bootstrap': 'window.ReactBootstrap',
26             'jquery': 'window.jQuery'
27         }
28     ],
29 
30     module: {
31         loaders: [
32             // 凡是遇到jsx结尾的,都用jsx-loader这个插件来加载,
33             // 且启用harmony模式
34             //{ test: path.join(__dirname, 'es6'), loader: 'babel-loader' },'jsx-loader?harmony'
35             { test: /\.js$/, loader: 'babel-loader!jsx-loader?harmony' },
36             { test: /\.jsx$/, loader: "jsx-loader?insertPragma=React.DOM" },
37             { test: /\.less$/, loader: 'style-loader!css-loader!less-loader' }, // use ! to chain loaders
38             { test: /\.css$/, loader: 'style-loader!css-loader' },
39             { test: /\.(png|jpg)$/, loader: 'url-loader?limit=8192' }, // 内联 base64 URLs, 限定 <=8k 的图片, 其他的用 URL
40 
41             // required for bootstrap icons
42             { test: /\.woff$/, loader: "url-loader?prefix=font/&limit=5000&mimetype=application/font-woff" },
43             { test: /\.ttf$/, loader: "file-loader?prefix=font/" },
44             { test: /\.eot$/, loader: "file-loader?prefix=font/" },
45             { test: /\.svg$/, loader: "file-loader?prefix=font/" }
46 
47         ]
48     },
49     resolve: {
50         // 现在可以写 require('file') 代替 require('file.coffee')
51         extensions: ['', '.webpack.js', '.coffee', '.json', '.js', '.jsx'],
52         modulesDirectories: [
53             'node_modules',
54             'bower_components',
55             'lib',
56             'src'
57         ]
58         // alias: {
59         //     // Bind version of jquery
60         //     jquery: "jquery-2.0.3",
61 
62         //     // Bind version of jquery-ui
63         //     "jquery-ui": "jquery-ui-1.10.3",
64 
65         //     // jquery-ui doesn't contain a index file
66         //     // bind module to the complete module
67         //     "jquery-ui-1.10.3$": "jquery-ui-1.10.3/ui/jquery-ui.js",
68         // }
69     },
70     devtool: 'source-map',
71     plugins: [
72         new webpack.DefinePlugin({// definePlugin 接收字符串插入到代码当中, 所以你需要的话可以写上 JS 的字符串
73             __DEV__: JSON.stringify(JSON.parse(process.env.BUILD_DEV || 'true')),
74             __PRERELEASE__: JSON.stringify(JSON.parse(process.env.BUILD_PRERELEASE || 'false'))
75         }),
76         new webpack.optimize.UglifyJsPlugin(),
77         new webpack.optimize.CommonsChunkPlugin('common.min.js', 5),
78         new webpack.ProvidePlugin({
79             // Automtically detect jQuery and $ as free var in modules
80             // and inject the jquery library
81             // This is required by many jquery plugins
82             $: "jquery",
83             jQuery: "jquery",
84             "window.jQuery": "jquery"
85         })
86     ]
87 };