webpack.common.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. var CopyWebpackPlugin = require('copy-webpack-plugin');
  2. var HtmlWebpackPlugin = require('html-webpack-plugin');
  3. var WriteFileWebpackPlugin = require('write-file-webpack-plugin');
  4. var autoPrefixer = require('autoprefixer');
  5. var path = require('path');
  6. var webpack = require('webpack');
  7. var outDir = path.resolve(__dirname, 'dist');
  8. module.exports = {
  9. devServer: {
  10. contentBase: outDir,
  11. outputPath: outDir,
  12. port: 4000
  13. },
  14. devtool: 'cheap-module-source-map',
  15. // Externals copied to /dist via CopyWebpackPlugin
  16. externals:
  17. {
  18. 'angular': true,
  19. // Wrapped in window because of hyphens
  20. 'angular-ui-router': 'window["angular-ui-router"]',
  21. 'angular-translate': 'window["angular-translate"]'
  22. },
  23. module: {
  24. preLoaders: [
  25. {
  26. test: /\.ts$/,
  27. loader: 'tslint'
  28. }
  29. ],
  30. loaders: [
  31. {
  32. test: /\.ts$/,
  33. loader: 'ts',
  34. exclude: /node_modules/
  35. },
  36. {
  37. test: /index\.html$/,
  38. loader: 'html',
  39. exclude: /node_modules/
  40. },
  41. {
  42. test: /\.html$/,
  43. loader: 'ngtemplate?relativeTo=' + (path.resolve(__dirname, './src')) + '/!html',
  44. exclude: /index\.html$/
  45. },
  46. {
  47. test: /\.scss$/,
  48. loaders: [ 'style', 'css', 'sass', 'postcss' ]
  49. },
  50. {
  51. test: /\.json/,
  52. loaders: [ 'json' ]
  53. },
  54. {
  55. test: /\.(png|jpg|jpeg|gif|svg)$/,
  56. loaders: [ 'url?limit=25000' ]
  57. }
  58. ]
  59. },
  60. // [name] is replaced by entry point name
  61. output: {
  62. filename: '[name].js',
  63. path: outDir
  64. },
  65. plugins: [
  66. new CopyWebpackPlugin([
  67. { from: 'vendor/angular-ui-router.js', to: 'vendor/' },
  68. { from: 'node_modules/angular/angular.js', to: 'vendor/' },
  69. { from: 'node_modules/angular-sanitize/angular-sanitize.js', to: 'vendor/' },
  70. { from: 'node_modules/angular-translate/dist/angular-translate.js', to: 'vendor/' },
  71. { from: 'images/', to: 'images/' }
  72. ]),
  73. new HtmlWebpackPlugin({
  74. template: 'index.html',
  75. inject: 'body'
  76. }),
  77. // Because we copy the output to another directory, we need file system watch support.
  78. // Webpack-dev-server does not do this without the plugin.
  79. new WriteFileWebpackPlugin()
  80. ],
  81. postcss: function() {
  82. return [
  83. autoPrefixer({
  84. browsers: ['last 2 versions']
  85. })
  86. ];
  87. },
  88. resolve: {
  89. extensions: [ '', '.ts', '.js', '.json' ],
  90. modulesDirectories: ['./src', './vendor', 'node_modules']
  91. }
  92. };