webpack.config.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. const webpack = require('webpack')
  2. const path = require('path')
  3. const CopyWebpackPlugin = require('copy-webpack-plugin')
  4. const Plugins = require('./Plugins')
  5. const ExtractTextPlugin = require('extract-text-webpack-plugin')
  6. const extractSass = new ExtractTextPlugin({
  7. filename: '[name].css',
  8. disable : false
  9. })
  10. module.exports = [{
  11. entry: {
  12. adminlte: './build/js/AdminLTE.js'
  13. },
  14. output: {
  15. path : path.resolve(__dirname, 'dist/js'),
  16. filename : '[name].js',
  17. publicPath: '.'
  18. },
  19. module: {
  20. rules: [
  21. {
  22. test : /\.js$/,
  23. exclude: '/node_modules/',
  24. use : {
  25. loader : 'babel-loader',
  26. options: {
  27. presets: ['env']
  28. }
  29. }
  30. }
  31. ]
  32. },
  33. plugins: []
  34. }, {
  35. entry: {
  36. adminlte: './build/scss/AdminLTE.scss'
  37. },
  38. output: {
  39. path : path.resolve(__dirname, 'dist/css'),
  40. filename : '[name].css',
  41. publicPath: '.'
  42. },
  43. module: {
  44. rules: [
  45. {
  46. test: /\.scss$/,
  47. use : extractSass.extract({
  48. use : [{
  49. loader: 'css-loader'
  50. }, {
  51. loader: 'sass-loader'
  52. }],
  53. // use style-loader in development
  54. fallback: 'style-loader'
  55. })
  56. }
  57. ]
  58. },
  59. plugins: [
  60. extractSass
  61. ]
  62. }]
  63. if (process.env.NODE_ENV === 'production') {
  64. module.exports[0].plugins.push(
  65. new webpack.optimize.UglifyJsPlugin({
  66. sourcemap: true,
  67. compress : {
  68. warnings: false
  69. }
  70. })
  71. )
  72. module.exports[0].plugins.push(
  73. new CopyWebpackPlugin(Plugins)
  74. )
  75. module.exports.map(module => {
  76. module.plugins.push(
  77. new webpack.DefinePlugin({
  78. 'process.env': {
  79. NODE_ENV: '"production"'
  80. }
  81. })
  82. )
  83. })
  84. }