aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/config
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-06-03 22:47:55 +0200
committerChocobozzz <florian.bigard@gmail.com>2016-06-03 22:47:55 +0200
commitb20b5fed405f0ab24d24709d7db65625a79f3b37 (patch)
tree70d4b81dc0865ea2b56e278fed77146e5a89934b /client/config
parentfc76359be11956f8514fc0dda1f66bb1c3397d26 (diff)
downloadPeerTube-b20b5fed405f0ab24d24709d7db65625a79f3b37.tar.gz
PeerTube-b20b5fed405f0ab24d24709d7db65625a79f3b37.tar.zst
PeerTube-b20b5fed405f0ab24d24709d7db65625a79f3b37.zip
Add production webpack, big thanks to @AngularClass
Diffstat (limited to 'client/config')
-rw-r--r--client/config/webpack.common.js4
-rw-r--r--client/config/webpack.dev.js4
-rw-r--r--client/config/webpack.prod.js228
3 files changed, 233 insertions, 3 deletions
diff --git a/client/config/webpack.common.js b/client/config/webpack.common.js
index 5f3f44bb1..abbf84fb0 100644
--- a/client/config/webpack.common.js
+++ b/client/config/webpack.common.js
@@ -72,6 +72,10 @@ module.exports = {
72 72
73 }, 73 },
74 74
75 output: {
76 publicPath: '/client/'
77 },
78
75 /* 79 /*
76 * Options affecting the normal modules. 80 * Options affecting the normal modules.
77 * 81 *
diff --git a/client/config/webpack.dev.js b/client/config/webpack.dev.js
index 19768d872..02e9857f7 100644
--- a/client/config/webpack.dev.js
+++ b/client/config/webpack.dev.js
@@ -81,9 +81,7 @@ module.exports = webpackMerge(commonConfig, {
81 * 81 *
82 * See: http://webpack.github.io/docs/configuration.html#output-chunkfilename 82 * See: http://webpack.github.io/docs/configuration.html#output-chunkfilename
83 */ 83 */
84 chunkFilename: '[id].chunk.js', 84 chunkFilename: '[id].chunk.js'
85
86 publicPath: '/client/'
87 85
88 }, 86 },
89 87
diff --git a/client/config/webpack.prod.js b/client/config/webpack.prod.js
index e69de29bb..23e2fabfe 100644
--- a/client/config/webpack.prod.js
+++ b/client/config/webpack.prod.js
@@ -0,0 +1,228 @@
1/**
2 * @author: @AngularClass
3 */
4
5const helpers = require('./helpers')
6const webpackMerge = require('webpack-merge') // used to merge webpack configs
7const commonConfig = require('./webpack.common.js') // the settings that are common to prod and dev
8
9/**
10 * Webpack Plugins
11 */
12const ProvidePlugin = require('webpack/lib/ProvidePlugin')
13const DefinePlugin = require('webpack/lib/DefinePlugin')
14const DedupePlugin = require('webpack/lib/optimize/DedupePlugin')
15const UglifyJsPlugin = require('webpack/lib/optimize/UglifyJsPlugin')
16const CompressionPlugin = require('compression-webpack-plugin')
17const WebpackMd5Hash = require('webpack-md5-hash')
18
19/**
20 * Webpack Constants
21 */
22const ENV = process.env.NODE_ENV = process.env.ENV = 'production'
23const HOST = process.env.HOST || 'localhost'
24const PORT = process.env.PORT || 8080
25const METADATA = webpackMerge(commonConfig.metadata, {
26 host: HOST,
27 port: PORT,
28 ENV: ENV,
29 HMR: false
30})
31
32module.exports = webpackMerge(commonConfig, {
33 /**
34 * Switch loaders to debug mode.
35 *
36 * See: http://webpack.github.io/docs/configuration.html#debug
37 */
38 debug: false,
39
40 /**
41 * Developer tool to enhance debugging
42 *
43 * See: http://webpack.github.io/docs/configuration.html#devtool
44 * See: https://github.com/webpack/docs/wiki/build-performance#sourcemaps
45 */
46 devtool: 'source-map',
47
48 /**
49 * Options affecting the output of the compilation.
50 *
51 * See: http://webpack.github.io/docs/configuration.html#output
52 */
53 output: {
54 /**
55 * The output directory as absolute path (required).
56 *
57 * See: http://webpack.github.io/docs/configuration.html#output-path
58 */
59 path: helpers.root('dist'),
60
61 /**
62 * Specifies the name of each output file on disk.
63 * IMPORTANT: You must not specify an absolute path here!
64 *
65 * See: http://webpack.github.io/docs/configuration.html#output-filename
66 */
67 filename: '[name].[chunkhash].bundle.js',
68
69 /**
70 * The filename of the SourceMaps for the JavaScript files.
71 * They are inside the output.path directory.
72 *
73 * See: http://webpack.github.io/docs/configuration.html#output-sourcemapfilename
74 */
75 sourceMapFilename: '[name].[chunkhash].bundle.map',
76
77 /**
78 * The filename of non-entry chunks as relative path
79 * inside the output.path directory.
80 *
81 * See: http://webpack.github.io/docs/configuration.html#output-chunkfilename
82 */
83 chunkFilename: '[id].[chunkhash].chunk.js'
84
85 },
86
87 /**
88 * Add additional plugins to the compiler.
89 *
90 * See: http://webpack.github.io/docs/configuration.html#plugins
91 */
92 plugins: [
93
94 /**
95 * Plugin: WebpackMd5Hash
96 * Description: Plugin to replace a standard webpack chunkhash with md5.
97 *
98 * See: https://www.npmjs.com/package/webpack-md5-hash
99 */
100 new WebpackMd5Hash(),
101
102 /**
103 * Plugin: DedupePlugin
104 * Description: Prevents the inclusion of duplicate code into your bundle
105 * and instead applies a copy of the function at runtime.
106 *
107 * See: https://webpack.github.io/docs/list-of-plugins.html#defineplugin
108 * See: https://github.com/webpack/docs/wiki/optimization#deduplication
109 */
110 new DedupePlugin(),
111
112 /**
113 * Plugin: DefinePlugin
114 * Description: Define free variables.
115 * Useful for having development builds with debug logging or adding global constants.
116 *
117 * Environment helpers
118 *
119 * See: https://webpack.github.io/docs/list-of-plugins.html#defineplugin
120 */
121 // NOTE: when adding more properties make sure you include them in custom-typings.d.ts
122 new DefinePlugin({
123 'ENV': JSON.stringify(METADATA.ENV),
124 'HMR': METADATA.HMR,
125 'process.env': {
126 'ENV': JSON.stringify(METADATA.ENV),
127 'NODE_ENV': JSON.stringify(METADATA.ENV),
128 'HMR': METADATA.HMR
129 }
130 }),
131
132 /**
133 * Plugin: UglifyJsPlugin
134 * Description: Minimize all JavaScript output of chunks.
135 * Loaders are switched into minimizing mode.
136 *
137 * See: https://webpack.github.io/docs/list-of-plugins.html#uglifyjsplugin
138 */
139 // NOTE: To debug prod builds uncomment //debug lines and comment //prod lines
140 new UglifyJsPlugin({
141 // beautify: true, //debug
142 // mangle: false, //debug
143 // dead_code: false, //debug
144 // unused: false, //debug
145 // deadCode: false, //debug
146 // compress: {
147 // screw_ie8: true,
148 // keep_fnames: true,
149 // drop_debugger: false,
150 // dead_code: false,
151 // unused: false
152 // }, // debug
153 // comments: true, //debug
154
155 beautify: false, // prod
156
157 mangle: {
158 screw_ie8: true,
159 keep_fnames: true
160 }, // prod
161
162 compress: {
163 screw_ie8: true
164 }, // prod
165
166 comments: false // prod
167 }),
168
169 /**
170 * Plugin: CompressionPlugin
171 * Description: Prepares compressed versions of assets to serve
172 * them with Content-Encoding
173 *
174 * See: https://github.com/webpack/compression-webpack-plugin
175 */
176 new CompressionPlugin({
177 regExp: /\.css$|\.html$|\.js$|\.map$/,
178 threshold: 2 * 1024
179 })
180
181 ],
182
183 /**
184 * Static analysis linter for TypeScript advanced options configuration
185 * Description: An extensible linter for the TypeScript language.
186 *
187 * See: https://github.com/wbuchwalter/tslint-loader
188 */
189 tslint: {
190 emitErrors: true,
191 failOnHint: true,
192 resourcePath: 'src'
193 },
194
195 /**
196 * Html loader advanced options
197 *
198 * See: https://github.com/webpack/html-loader#advanced-options
199 */
200 // TODO: Need to workaround Angular 2's html syntax => #id [bind] (event) *ngFor
201 htmlLoader: {
202 minimize: true,
203 removeAttributeQuotes: false,
204 caseSensitive: true,
205 customAttrSurround: [
206 [/#/, /(?:)/],
207 [/\*/, /(?:)/],
208 [/\[?\(?/, /(?:)/]
209 ],
210 customAttrAssign: [/\)?\]?=/]
211 },
212
213 /*
214 * Include polyfills or mocks for various node stuff
215 * Description: Node configuration
216 *
217 * See: https://webpack.github.io/docs/configuration.html#node
218 */
219 node: {
220 global: 'window',
221 crypto: 'empty',
222 process: false,
223 module: false,
224 clearImmediate: false,
225 setImmediate: false
226 }
227
228})