Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 1 | 'use strict'; |
| 2 | |
| 3 | const path = require('path'); |
| 4 | const merge = require('webpack-merge'); |
| 5 | const webpack = require('webpack'); |
| 6 | const ServerConfig = require('./webpack.server'); |
| 7 | const webpackCommonConfig = require('./webpack.common'); |
Michael Lando | 6e60006 | 2017-06-19 19:51:24 +0300 | [diff] [blame] | 8 | const {BaseHrefWebpackPlugin} = require('@angular/cli/plugins/webpack'); |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 9 | const CopyWebpackPlugin = require('copy-webpack-plugin'); |
| 10 | |
| 11 | // Print server configuration |
| 12 | //process.stdout.write('webpack.server: ' + JSON.stringify(ServerConfig) + '\n'); |
| 13 | //process.stdout.write('webpack.common: ' + JSON.stringify(webpackCommonConfig) + '\n'); |
Michael Lando | 6e60006 | 2017-06-19 19:51:24 +0300 | [diff] [blame] | 14 | var currentTime = new Date().getTime(); |
| 15 | |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 16 | const params = { |
| 17 | // entryPoints: [ |
| 18 | // '/scripts/inline', |
| 19 | // '/scripts/polyfills', |
| 20 | // '/scripts/vendor', |
| 21 | // '/scripts/main', |
| 22 | // '/scripts/sw-register', |
| 23 | // '/scripts/scripts', |
| 24 | // '/scripts/styles' |
| 25 | // ] |
| 26 | }; |
| 27 | |
Michael Lando | 6e60006 | 2017-06-19 19:51:24 +0300 | [diff] [blame] | 28 | module.exports = function (env) { |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 29 | |
| 30 | const webpackDevConfig = { |
| 31 | devtool: "source-map", |
| 32 | devServer: ServerConfig(env), |
| 33 | module: { |
| 34 | rules: [ |
Michael Lando | 6e60006 | 2017-06-19 19:51:24 +0300 | [diff] [blame] | 35 | {test: /\.(eot|svg)$/, loader: "file-loader?name=scripts/fonts/[name].[hash:20].[ext]"}, |
| 36 | { |
| 37 | test: /\.(jpg|png|gif|otf|ttf|woff|woff2|cur|ani)$/, |
| 38 | loader: "url-loader?name=scripts/images/[name].[hash:20].[ext]&limit=10000" |
| 39 | } |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 40 | ] |
| 41 | }, |
| 42 | output: { |
| 43 | path: path.join(process.cwd(), "dist"), |
Michael Lando | 6e60006 | 2017-06-19 19:51:24 +0300 | [diff] [blame] | 44 | filename: "[name]." + currentTime + ".bundle.js", |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 45 | chunkFilename: "[id].chunk.js" |
| 46 | //publicPath: "/" |
| 47 | }, |
| 48 | plugins: [ |
Michael Lando | 6e60006 | 2017-06-19 19:51:24 +0300 | [diff] [blame] | 49 | |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 50 | // Replace /sdc1 inside index.html with '' (because /sdc1 is used only in production). |
| 51 | new CopyWebpackPlugin([ |
Michael Lando | 6e60006 | 2017-06-19 19:51:24 +0300 | [diff] [blame] | 52 | { |
| 53 | from: './src/index.html', transform: function (content, path) { |
| 54 | content = (content + '').replace(/\/sdc1/g, ''); |
| 55 | content = (content + '').replace(/\.bundle/g, '.' + currentTime + '.bundle'); |
| 56 | return content; |
| 57 | } |
| 58 | } |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 59 | ]), |
| 60 | new webpack.DefinePlugin({ |
| 61 | __DEBUG__: JSON.stringify(true), |
| 62 | __ENV__: JSON.stringify('dev'), |
| 63 | __HMR__: JSON.stringify('HMR') |
| 64 | }), |
| 65 | new webpack.HotModuleReplacementPlugin() |
| 66 | ] |
| 67 | |
| 68 | }; |
| 69 | |
| 70 | return merge(webpackDevConfig, webpackCommonConfig(params)); |
Michael Lando | 6e60006 | 2017-06-19 19:51:24 +0300 | [diff] [blame] | 71 | } |