[关闭]
@bergus 2015-12-02T06:47:16.000000Z 字数 2288 阅读 1766

webpack配置

nodejs 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. module: {
  30. loaders: [
  31. // 凡是遇到jsx结尾的,都用jsx-loader这个插件来加载,
  32. // 且启用harmony模式
  33. //{ test: path.join(__dirname, 'es6'), loader: 'babel-loader' },'jsx-loader?harmony'
  34. { test: /\.js$/, loader: 'babel-loader!jsx-loader?harmony' },
  35. { test: /\.jsx$/, loader: "jsx-loader?insertPragma=React.DOM" },
  36. { test: /\.less$/, loader: 'style-loader!css-loader!less-loader' }, // use ! to chain loaders
  37. { test: /\.css$/, loader: 'style-loader!css-loader' },
  38. { test: /\.(png|jpg)$/, loader: 'url-loader?limit=8192' }, // 内联 base64 URLs, 限定 <=8k 的图片, 其他的用 URL
  39. // required for bootstrap icons
  40. { test: /\.woff$/, loader: "url-loader?prefix=font/&limit=5000&mimetype=application/font-woff" },
  41. { test: /\.ttf$/, loader: "file-loader?prefix=font/" },
  42. { test: /\.eot$/, loader: "file-loader?prefix=font/" },
  43. { test: /\.svg$/, loader: "file-loader?prefix=font/" }
  44. ]
  45. },
  46. resolve: {
  47. // 现在可以写 require('file') 代替 require('file.coffee')
  48. extensions: ['', '.webpack.js', '.coffee', '.json', '.js', '.jsx'],
  49. modulesDirectories: [
  50. 'node_modules',
  51. 'bower_components',
  52. 'lib',
  53. 'src'
  54. ]
  55. // alias: {
  56. // // Bind version of jquery
  57. // jquery: "jquery-2.0.3",
  58. // // Bind version of jquery-ui
  59. // "jquery-ui": "jquery-ui-1.10.3",
  60. // // jquery-ui doesn't contain a index file
  61. // // bind module to the complete module
  62. // "jquery-ui-1.10.3$": "jquery-ui-1.10.3/ui/jquery-ui.js",
  63. // }
  64. },
  65. devtool: 'source-map',
  66. plugins: [
  67. new webpack.DefinePlugin({// definePlugin 接收字符串插入到代码当中, 所以你需要的话可以写上 JS 的字符串
  68. __DEV__: JSON.stringify(JSON.parse(process.env.BUILD_DEV || 'true')),
  69. __PRERELEASE__: JSON.stringify(JSON.parse(process.env.BUILD_PRERELEASE || 'false'))
  70. }),
  71. new webpack.optimize.UglifyJsPlugin(),
  72. new webpack.optimize.CommonsChunkPlugin('common.min.js', 5),
  73. new webpack.ProvidePlugin({
  74. // Automtically detect jQuery and $ as free var in modules
  75. // and inject the jquery library
  76. // This is required by many jquery plugins
  77. $: "jquery",
  78. jQuery: "jquery",
  79. "window.jQuery": "jquery"
  80. })
  81. ]
  82. };
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注