Advertisement
Guest User

Untitled

a guest
Apr 4th, 2017
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var production = process.env.NODE_ENV == 'production'
  2. if (!production) { require('dotenv').config(); }
  3.  
  4. var webpack = require('webpack');
  5. var path = require('path');
  6. var webpackMerge = require('webpack-merge');
  7.  
  8. // Webpack Config
  9. var webpackConfig = {
  10.   entry: {
  11.     'main': './src/main.browser.ts',
  12.   },
  13.  
  14.   output: {
  15.     publicPath: '',
  16.     path: path.resolve(__dirname, './dist'),
  17.   },
  18.  
  19.   plugins: [
  20.     new webpack.ContextReplacementPlugin(
  21.       // The (\\|\/) piece accounts for path separators in *nix and Windows
  22.       /angular(\\|\/)core(\\|\/)src(\\|\/)linker/,
  23.       path.resolve(__dirname, './src'),
  24.       {
  25.         // your Angular Async Route paths relative to this root directory
  26.       }
  27.     ),
  28.     new webpack.EnvironmentPlugin([
  29.       'CONFIG_VAR', 'NODE_ENV'
  30.       ])
  31.   ],
  32.  
  33.   module: {
  34.     loaders: [
  35.       // .ts files for TypeScript
  36.       {
  37.         test: /\.ts$/,
  38.         loaders: [
  39.           'awesome-typescript-loader',
  40.           'angular2-template-loader',
  41.           'angular2-router-loader'
  42.         ]
  43.       },
  44.       { test: /\.css$/, loaders: ['to-string-loader', 'css-loader'] },
  45.       { test: /\.html$/, loader: 'raw-loader' }
  46.     ]
  47.   }
  48.  
  49. };
  50.  
  51. // Our Webpack Defaults
  52. var defaultConfig = {
  53.   devtool: 'source-map',
  54.  
  55.   output: {
  56.     filename: '[name].bundle.js',
  57.     sourceMapFilename: '[name].map',
  58.     chunkFilename: '[id].chunk.js'
  59.   },
  60.  
  61.   resolve: {
  62.     extensions: [ '.ts', '.js' ],
  63.     modules: [ path.resolve(__dirname, 'node_modules') ]
  64.   },
  65.  
  66.   devServer: {
  67.     historyApiFallback: true,
  68.     watchOptions: { aggregateTimeout: 300, poll: 1000 },
  69.     headers: {
  70.       "Access-Control-Allow-Origin": "*",
  71.       "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
  72.       "Access-Control-Allow-Headers": "X-Requested-With, content-type, Authorization"
  73.     }
  74.   },
  75.  
  76.   node: {
  77.     global: true,
  78.     crypto: 'empty',
  79.     __dirname: true,
  80.     __filename: true,
  81.     process: true,
  82.     Buffer: false,
  83.     clearImmediate: false,
  84.     setImmediate: false
  85.   }
  86. };
  87.  
  88. if (production) {
  89.   webpackConfig.plugins.push(new webpack.optimize.UglifyJsPlugin({
  90.     mangle: true,
  91.     output: {
  92.       comments: false
  93.     },
  94.     compress: {
  95.       warnings: false
  96.     }}));
  97. }
  98.  
  99. module.exports = webpackMerge(defaultConfig, webpackConfig);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement