aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/config
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2017-12-12 11:38:02 +0100
committerChocobozzz <me@florianbigard.com>2017-12-12 11:42:48 +0100
commit7bfd1b1edb7ea4ea6516b6a74c4e9af938d0bdc6 (patch)
tree722781d5d89fe438e7491da7e9d09dedd8c82a74 /client/config
parent63c4db6d71b98523753c51747e308682d9a2e8a0 (diff)
downloadPeerTube-7bfd1b1edb7ea4ea6516b6a74c4e9af938d0bdc6.tar.gz
PeerTube-7bfd1b1edb7ea4ea6516b6a74c4e9af938d0bdc6.tar.zst
PeerTube-7bfd1b1edb7ea4ea6516b6a74c4e9af938d0bdc6.zip
Upgrade scripts and embed webpack config
Diffstat (limited to 'client/config')
-rw-r--r--client/config/empty.js11
-rw-r--r--client/config/helpers.js27
-rw-r--r--client/config/resource-override.js0
-rw-r--r--client/config/webpack.common.js338
-rw-r--r--client/config/webpack.dev.js242
-rw-r--r--client/config/webpack.prod.js293
-rw-r--r--client/config/webpack.video-embed.js184
7 files changed, 0 insertions, 1095 deletions
diff --git a/client/config/empty.js b/client/config/empty.js
deleted file mode 100644
index a5c628d81..000000000
--- a/client/config/empty.js
+++ /dev/null
@@ -1,11 +0,0 @@
1module.exports = {
2 hmrModule: function (ngmodule) {
3 return ngmodule
4 },
5 NgProbeToken: {},
6 HmrState: function () {},
7 _createConditionalRootRenderer: function (rootRenderer, extraTokens, coreTokens) {
8 return rootRenderer
9 },
10 __platform_browser_private__: {}
11}
diff --git a/client/config/helpers.js b/client/config/helpers.js
deleted file mode 100644
index ca5923472..000000000
--- a/client/config/helpers.js
+++ /dev/null
@@ -1,27 +0,0 @@
1const path = require('path')
2
3// Helper functions
4const ROOT = path.resolve(__dirname, '..')
5const EVENT = process.env.npm_lifecycle_event || ''
6
7function hasProcessFlag (flag) {
8 return process.argv.join('').indexOf(flag) > -1
9}
10
11function hasNpmFlag (flag) {
12 return EVENT.includes(flag)
13}
14
15function isWebpackDevServer () {
16 return process.argv[1] && !!(/webpack-dev-server$/.exec(process.argv[1]))
17}
18
19function root (args) {
20 args = Array.prototype.slice.call(arguments, 0)
21 return path.join.apply(path, [ROOT].concat(args))
22}
23
24exports.hasProcessFlag = hasProcessFlag
25exports.hasNpmFlag = hasNpmFlag
26exports.isWebpackDevServer = isWebpackDevServer
27exports.root = root
diff --git a/client/config/resource-override.js b/client/config/resource-override.js
deleted file mode 100644
index e69de29bb..000000000
--- a/client/config/resource-override.js
+++ /dev/null
diff --git a/client/config/webpack.common.js b/client/config/webpack.common.js
deleted file mode 100644
index f387b44f9..000000000
--- a/client/config/webpack.common.js
+++ /dev/null
@@ -1,338 +0,0 @@
1const helpers = require('./helpers')
2
3/*
4 * Webpack Plugins
5 */
6
7const AssetsPlugin = require('assets-webpack-plugin')
8const ContextReplacementPlugin = require('webpack/lib/ContextReplacementPlugin')
9const CommonsChunkPlugin = require('webpack/lib/optimize/CommonsChunkPlugin')
10const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin
11const HtmlWebpackPlugin = require('html-webpack-plugin')
12const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin')
13const ScriptExtHtmlWebpackPlugin = require('script-ext-html-webpack-plugin')
14const InlineManifestWebpackPlugin = require('inline-manifest-webpack-plugin')
15const ngcWebpack = require('ngc-webpack')
16const CopyWebpackPlugin = require('copy-webpack-plugin')
17
18const WebpackNotifierPlugin = require('webpack-notifier')
19
20const HMR = helpers.hasProcessFlag('hot')
21const AOT = process.env.BUILD_AOT || helpers.hasNpmFlag('aot')
22const METADATA = {
23 title: 'PeerTube',
24 baseUrl: '/',
25 isDevServer: helpers.isWebpackDevServer(),
26 HMR: HMR,
27 AOT: AOT
28}
29
30/*
31 * Webpack configuration
32 *
33 * See: http://webpack.github.io/docs/configuration.html#cli
34 */
35module.exports = function (options) {
36 const isProd = options.env === 'production'
37 const AOT = isProd
38
39 return {
40
41 /*
42 * Cache generated modules and chunks to improve performance for multiple incremental builds.
43 * This is enabled by default in watch mode.
44 * You can pass false to disable it.
45 *
46 * See: http://webpack.github.io/docs/configuration.html#cache
47 */
48 // cache: false,
49
50 /*
51 * The entry point for the bundle
52 * Our Angular.js app
53 *
54 * See: http://webpack.github.io/docs/configuration.html#entry
55 */
56 entry: {
57 'polyfills': './src/polyfills.browser.ts',
58 'main': AOT
59 ? './src/main.browser.aot.ts'
60 : './src/main.browser.ts'
61 },
62
63 /*
64 * Options affecting the resolving of modules.
65 *
66 * See: http://webpack.github.io/docs/configuration.html#resolve
67 */
68 resolve: {
69 /*
70 * An array of extensions that should be used to resolve modules.
71 *
72 * See: http://webpack.github.io/docs/configuration.html#resolve-extensions
73 */
74 extensions: [ '.ts', '.js', '.json', '.scss' ],
75
76 modules: [ helpers.root('src'), helpers.root('node_modules') ]
77 },
78
79 /*
80 * Options affecting the normal modules.
81 *
82 * See: http://webpack.github.io/docs/configuration.html#module
83 */
84 module: {
85
86 rules: [
87
88 /*
89 * Typescript loader support for .ts and Angular async routes via .async.ts
90 *
91 * See: https://github.com/s-panferov/awesome-typescript-loader
92 */
93 {
94 test: /\.ts$/,
95 use: [
96 {
97 loader: 'ng-router-loader',
98 options: {
99 loader: 'async-import',
100 genDir: 'compiled',
101 aot: AOT
102 }
103 },
104 {
105 loader: 'awesome-typescript-loader',
106 options: {
107 configFileName: 'tsconfig.webpack.json',
108 useCache: !isProd
109 }
110 },
111 {
112 loader: 'angular2-template-loader'
113 }
114 ],
115 exclude: [/\.(spec|e2e)\.ts$/]
116 },
117
118 /*
119 * Json loader support for *.json files.
120 *
121 * See: https://github.com/webpack/json-loader
122 */
123 {
124 test: /\.json$/,
125 use: 'json-loader'
126 },
127
128 {
129 test: /\.(sass|scss)$/,
130 use: [
131 'css-to-string-loader',
132 {
133 loader: 'css-loader',
134 options: {
135 sourceMap: true,
136 importLoaders: 1
137 }
138 },
139 'resolve-url-loader',
140 {
141 loader: 'sass-loader',
142 options: {
143 sourceMap: true
144 }
145 },
146 {
147 loader: 'sass-resources-loader',
148 options: {
149 resources: [
150 helpers.root('src/sass/_variables.scss'),
151 helpers.root('src/sass/_mixins.scss')
152 ]
153 }
154 }
155 ]
156 },
157 { test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, use: 'url-loader?limit=10000&minetype=application/font-woff' },
158 { test: /\.(otf|ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, use: 'url-loader?limit=10000' },
159
160 /* Raw loader support for *.html
161 * Returns file content as string
162 *
163 * See: https://github.com/webpack/raw-loader
164 */
165 {
166 test: /\.html$/,
167 use: 'raw-loader',
168 exclude: [
169 helpers.root('src/index.html'),
170 helpers.root('src/standalone/videos/embed.html')
171 ]
172 },
173
174 /* File loader for supporting images, for example, in CSS files.
175 */
176 {
177 test: /\.(jpg|png|gif)$/,
178 use: 'url-loader'
179 }
180
181 ]
182
183 },
184
185 /*
186 * Add additional plugins to the compiler.
187 *
188 * See: http://webpack.github.io/docs/configuration.html#plugins
189 */
190 plugins: [
191 new AssetsPlugin({
192 path: helpers.root('dist'),
193 filename: 'webpack-assets.json',
194 prettyPrint: true
195 }),
196
197 /*
198 * Plugin: ForkCheckerPlugin
199 * Description: Do type checking in a separate process, so webpack don't need to wait.
200 *
201 * See: https://github.com/s-panferov/awesome-typescript-loader#forkchecker-boolean-defaultfalse
202 */
203 new CheckerPlugin(),
204
205 /*
206 * Plugin: CommonsChunkPlugin
207 * Description: Shares common code between the pages.
208 * It identifies common modules and put them into a commons chunk.
209 *
210 * See: https://webpack.github.io/docs/list-of-plugins.html#commonschunkplugin
211 * See: https://github.com/webpack/docs/wiki/optimization#multi-page-app
212 */
213 new CommonsChunkPlugin({
214 name: 'polyfills',
215 chunks: ['polyfills']
216 }),
217
218 // This enables tree shaking of the vendor modules
219 new CommonsChunkPlugin({
220 name: 'vendor',
221 chunks: ['main'],
222 minChunks: module => {
223 return /node_modules\//.test(module.resource)
224 }
225 }),
226
227 // Specify the correct order the scripts will be injected in
228 new CommonsChunkPlugin({
229 name: ['polyfills', 'vendor'].reverse()
230 }),
231
232 /**
233 * Plugin: ContextReplacementPlugin
234 * Description: Provides context to Angular's use of System.import
235 *
236 * See: https://webpack.github.io/docs/list-of-plugins.html#contextreplacementplugin
237 * See: https://github.com/angular/angular/issues/11580
238 */
239 new ContextReplacementPlugin(
240 /**
241 * The (\\|\/) piece accounts for path separators in *nix and Windows
242 */
243 /(.+)?angular(\\|\/)core(.+)?/,
244 helpers.root('src'), // location of your src
245 {
246 /**
247 * Your Angular Async Route paths relative to this root directory
248 */
249 }
250 ),
251
252 /*
253 * Plugin: HtmlWebpackPlugin
254 * Description: Simplifies creation of HTML files to serve your webpack bundles.
255 * This is especially useful for webpack bundles that include a hash in the filename
256 * which changes every compilation.
257 *
258 * See: https://github.com/ampedandwired/html-webpack-plugin
259 */
260 new HtmlWebpackPlugin({
261 template: 'src/index.html',
262 title: METADATA.title,
263 chunksSortMode: function (a, b) {
264 const entryPoints = [ 'inline', 'polyfills', 'sw-register', 'styles', 'vendor', 'main' ]
265 return entryPoints.indexOf(a.names[0]) - entryPoints.indexOf(b.names[0])
266 },
267 metadata: METADATA,
268 inject: 'body'
269 }),
270
271 new CopyWebpackPlugin([
272 {
273 from: helpers.root('src/assets/images/favicon.png'),
274 to: 'assets/images/favicon.png'
275 },
276 {
277 from: helpers.root('src/assets/images/default-avatar.png'),
278 to: 'assets/images/default-avatar.png'
279 }
280 ]),
281
282 /*
283 * Plugin: ScriptExtHtmlWebpackPlugin
284 * Description: Enhances html-webpack-plugin functionality
285 * with different deployment options for your scripts including:
286 *
287 * See: https://github.com/numical/script-ext-html-webpack-plugin
288 */
289 new ScriptExtHtmlWebpackPlugin({
290 sync: [ /polyfill|vendor/ ],
291 defaultAttribute: 'async',
292 preload: [/polyfill|vendor|main/],
293 prefetch: [/chunk/]
294 }),
295
296 new WebpackNotifierPlugin({ alwaysNotify: true }),
297
298 /**
299 * Plugin LoaderOptionsPlugin (experimental)
300 *
301 * See: https://gist.github.com/sokra/27b24881210b56bbaff7
302 */
303 new LoaderOptionsPlugin({
304 options: {
305 context: '',
306 sassLoader: {
307 precision: 10,
308 includePaths: [ helpers.root('src/sass') ]
309 }
310 }
311 }),
312
313 new ngcWebpack.NgcWebpackPlugin({
314 disabled: !AOT,
315 tsConfig: helpers.root('tsconfig.webpack.json')
316 }),
317
318 new InlineManifestWebpackPlugin()
319 ],
320
321 /*
322 * Include polyfills or mocks for various node stuff
323 * Description: Node configuration
324 *
325 * See: https://webpack.github.io/docs/configuration.html#node
326 */
327 node: {
328 global: true,
329 crypto: 'empty',
330 process: true,
331 module: false,
332 clearImmediate: false,
333 setImmediate: false,
334 setInterval: false,
335 setTimeout: false
336 }
337 }
338}
diff --git a/client/config/webpack.dev.js b/client/config/webpack.dev.js
deleted file mode 100644
index d825f40e0..000000000
--- a/client/config/webpack.dev.js
+++ /dev/null
@@ -1,242 +0,0 @@
1const helpers = require('./helpers')
2const webpackMerge = require('webpack-merge') // used to merge webpack configs
3const webpackMergeDll = webpackMerge.strategy({plugins: 'replace'})
4const commonConfig = require('./webpack.common.js') // the settings that are common to prod and dev
5const videoEmbedConfig = require('./webpack.video-embed.js')
6
7/**
8 * Webpack Plugins
9 */
10const AddAssetHtmlPlugin = require('add-asset-html-webpack-plugin')
11const DefinePlugin = require('webpack/lib/DefinePlugin')
12const NamedModulesPlugin = require('webpack/lib/NamedModulesPlugin')
13const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin')
14const HotModuleReplacementPlugin = require('webpack/lib/HotModuleReplacementPlugin')
15
16/**
17 * Webpack Constants
18 */
19const ENV = process.env.ENV = process.env.NODE_ENV = 'development'
20const HOST = process.env.HOST || 'localhost'
21const PORT = process.env.PORT || 3000
22const PUBLIC = process.env.PUBLIC_DEV || HOST + ':' + PORT
23const AOT = process.env.BUILD_AOT || helpers.hasNpmFlag('aot')
24const HMR = helpers.hasProcessFlag('hot')
25const METADATA = {
26 host: HOST,
27 port: PORT,
28 public: PUBLIC,
29 ENV: ENV,
30 HMR: HMR,
31 AOT: AOT,
32 API_URL: 'http://localhost:9000'
33}
34
35const DllBundlesPlugin = require('webpack-dll-bundles-plugin').DllBundlesPlugin
36
37/**
38 * Webpack configuration
39 *
40 * See: http://webpack.github.io/docs/configuration.html#cli
41 */
42module.exports = function (env) {
43 return [
44
45 webpackMerge(commonConfig({ env: ENV }), {
46 /**
47 * Developer tool to enhance debugging
48 *
49 * See: http://webpack.github.io/docs/configuration.html#devtool
50 * See: https://github.com/webpack/docs/wiki/build-performance#sourcemaps
51 */
52 devtool: 'cheap-module-source-map',
53
54 /**
55 * Options affecting the output of the compilation.
56 *
57 * See: http://webpack.github.io/docs/configuration.html#output
58 */
59 output: {
60 /**
61 * The output directory as absolute path (required).
62 *
63 * See: http://webpack.github.io/docs/configuration.html#output-path
64 */
65 path: helpers.root('dist'),
66
67 /**
68 * Specifies the name of each output file on disk.
69 * IMPORTANT: You must not specify an absolute path here!
70 *
71 * See: http://webpack.github.io/docs/configuration.html#output-filename
72 */
73 filename: '[name].bundle.js',
74
75 /**
76 * The filename of the SourceMaps for the JavaScript files.
77 * They are inside the output.path directory.
78 *
79 * See: http://webpack.github.io/docs/configuration.html#output-sourcemapfilename
80 */
81 sourceMapFilename: '[name].map',
82
83 /** The filename of non-entry chunks as relative path
84 * inside the output.path directory.
85 *
86 * See: http://webpack.github.io/docs/configuration.html#output-chunkfilename
87 */
88 chunkFilename: '[id].chunk.js',
89
90 library: 'ac_[name]',
91 libraryTarget: 'var'
92 },
93
94 plugins: [
95
96 /**
97 * Plugin: DefinePlugin
98 * Description: Define free variables.
99 * Useful for having development builds with debug logging or adding global constants.
100 *
101 * Environment helpers
102 *
103 * See: https://webpack.github.io/docs/list-of-plugins.html#defineplugin
104 */
105 // NOTE: when adding more properties, make sure you include them in custom-typings.d.ts
106 new DefinePlugin({
107 'ENV': JSON.stringify(METADATA.ENV),
108 'HMR': METADATA.HMR,
109 'API_URL': JSON.stringify(METADATA.API_URL),
110 'process.version': JSON.stringify(process.version),
111 'process.env.ENV': JSON.stringify(METADATA.ENV),
112 'process.env.NODE_ENV': JSON.stringify(METADATA.ENV),
113 'process.env.HMR': METADATA.HMR
114 }),
115
116 new DllBundlesPlugin({
117 bundles: {
118 polyfills: [
119 'core-js',
120 {
121 name: 'zone.js',
122 path: 'zone.js/dist/zone.js'
123 },
124 {
125 name: 'zone.js',
126 path: 'zone.js/dist/long-stack-trace-zone.js'
127 }
128 ],
129 vendor: [
130 '@angular/platform-browser',
131 '@angular/platform-browser-dynamic',
132 '@angular/core',
133 '@angular/common',
134 '@angular/forms',
135 '@angular/http',
136 '@angular/router',
137 '@angularclass/hmr',
138 'rxjs'
139 ]
140 },
141 dllDir: helpers.root('dll'),
142 webpackConfig: webpackMergeDll(commonConfig({env: ENV}), {
143 devtool: 'cheap-module-source-map',
144 plugins: []
145 })
146 }),
147
148 /**
149 * Plugin: AddAssetHtmlPlugin
150 * Description: Adds the given JS or CSS file to the files
151 * Webpack knows about, and put it into the list of assets
152 * html-webpack-plugin injects into the generated html.
153 *
154 * See: https://github.com/SimenB/add-asset-html-webpack-plugin
155 */
156 new AddAssetHtmlPlugin([
157 { filepath: helpers.root(`dll/${DllBundlesPlugin.resolveFile('polyfills')}`) },
158 { filepath: helpers.root(`dll/${DllBundlesPlugin.resolveFile('vendor')}`) }
159 ]),
160
161 /**
162 * Plugin: NamedModulesPlugin (experimental)
163 * Description: Uses file names as module name.
164 *
165 * See: https://github.com/webpack/webpack/commit/a04ffb928365b19feb75087c63f13cadfc08e1eb
166 */
167 new NamedModulesPlugin(),
168
169 /**
170 * Plugin LoaderOptionsPlugin (experimental)
171 *
172 * See: https://gist.github.com/sokra/27b24881210b56bbaff7
173 */
174 new LoaderOptionsPlugin({
175 debug: true,
176 options: {
177
178 /**
179 * Static analysis linter for TypeScript advanced options configuration
180 * Description: An extensible linter for the TypeScript language.
181 *
182 * See: https://github.com/wbuchwalter/tslint-loader
183 */
184 tslint: {
185 emitErrors: false,
186 failOnHint: false,
187 typeCheck: true,
188 resourcePath: 'src'
189 },
190
191 // FIXME: Remove
192 // https://github.com/bholloway/resolve-url-loader/issues/36
193 // https://github.com/jtangelder/sass-loader/issues/289
194 context: __dirname,
195 output: {
196 path: helpers.root('dist')
197 }
198
199 }
200 }),
201
202 new HotModuleReplacementPlugin()
203 ],
204
205 /**
206 * Webpack Development Server configuration
207 * Description: The webpack-dev-server is a little node.js Express server.
208 * The server emits information about the compilation state to the client,
209 * which reacts to those events.
210 *
211 * See: https://webpack.github.io/docs/webpack-dev-server.html
212 */
213 devServer: {
214 port: METADATA.port,
215 host: METADATA.host,
216 historyApiFallback: true,
217 hot: METADATA.HMR,
218 watchOptions: {
219 ignored: /node_modules/
220 }
221 },
222
223 /*
224 * Include polyfills or mocks for various node stuff
225 * Description: Node configuration
226 *
227 * See: https://webpack.github.io/docs/configuration.html#node
228 */
229 node: {
230 global: true,
231 crypto: 'empty',
232 fs: 'empty',
233 process: true,
234 module: false,
235 clearImmediate: false,
236 setImmediate: false
237 }
238 }),
239
240 videoEmbedConfig({env: ENV})
241 ]
242}
diff --git a/client/config/webpack.prod.js b/client/config/webpack.prod.js
deleted file mode 100644
index e2dde854d..000000000
--- a/client/config/webpack.prod.js
+++ /dev/null
@@ -1,293 +0,0 @@
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
8const videoEmbedConfig = require('./webpack.video-embed.js')
9
10/**
11 * Webpack Plugins
12 */
13const DefinePlugin = require('webpack/lib/DefinePlugin')
14const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
15const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin')
16const NormalModuleReplacementPlugin = require('webpack/lib/NormalModuleReplacementPlugin')
17const OptimizeJsPlugin = require('optimize-js-plugin')
18const HashedModuleIdsPlugin = require('webpack/lib/HashedModuleIdsPlugin')
19const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
20const ExtractTextPlugin = require('extract-text-webpack-plugin')
21
22/**
23 * Webpack Constants
24 */
25const ENV = process.env.NODE_ENV = process.env.ENV = 'production'
26const HOST = process.env.HOST || 'localhost'
27const PORT = process.env.PORT || 8080
28const AOT = process.env.BUILD_AOT || helpers.hasNpmFlag('aot')
29const METADATA = {
30 host: HOST,
31 port: PORT,
32 ENV: ENV,
33 HMR: false,
34 AOT: AOT,
35 API_URL: ''
36}
37
38module.exports = function (env) {
39 return [
40 videoEmbedConfig({ env: ENV }),
41
42 webpackMerge(commonConfig({ env: ENV }), {
43 /**
44 * Developer tool to enhance debugging
45 *
46 * See: http://webpack.github.io/docs/configuration.html#devtool
47 * See: https://github.com/webpack/docs/wiki/build-performance#sourcemaps
48 */
49 devtool: 'source-map',
50
51 /**
52 * Options affecting the output of the compilation.
53 *
54 * See: http://webpack.github.io/docs/configuration.html#output
55 */
56 output: {
57
58 /**
59 * The output directory as absolute path (required).
60 *
61 * See: http://webpack.github.io/docs/configuration.html#output-path
62 */
63 path: helpers.root('dist'),
64
65 /**
66 * Specifies the name of each output file on disk.
67 * IMPORTANT: You must not specify an absolute path here!
68 *
69 * See: http://webpack.github.io/docs/configuration.html#output-filename
70 */
71 filename: '[name].[chunkhash].bundle.js',
72
73 /**
74 * The filename of the SourceMaps for the JavaScript files.
75 * They are inside the output.path directory.
76 *
77 * See: http://webpack.github.io/docs/configuration.html#output-sourcemapfilename
78 */
79 sourceMapFilename: '[file].map',
80
81 /**
82 * The filename of non-entry chunks as relative path
83 * inside the output.path directory.
84 *
85 * See: http://webpack.github.io/docs/configuration.html#output-chunkfilename
86 */
87 chunkFilename: '[name].[chunkhash].chunk.js',
88
89 publicPath: '/client/'
90 },
91
92 module: {
93 rules: [
94 {
95 test: /junk\/index\.js$/,
96 // exclude: /(node_modules|bower_components)/,
97 use: {
98 loader: 'babel-loader',
99 options: {
100 presets: [ 'env' ]
101 }
102 }
103 }
104 ]
105 },
106
107 /**
108 * Add additional plugins to the compiler.
109 *
110 * See: http://webpack.github.io/docs/configuration.html#plugins
111 */
112 plugins: [
113
114 /**
115 * Webpack plugin to optimize a JavaScript file for faster initial load
116 * by wrapping eagerly-invoked functions.
117 *
118 * See: https://github.com/vigneshshanmugam/optimize-js-plugin
119 */
120
121 new OptimizeJsPlugin({
122 sourceMap: false
123 }),
124
125 new ExtractTextPlugin({
126 filename: '[name].[contenthash].css',
127 allChunks: true
128 }),
129
130 /**
131 * Plugin: DefinePlugin
132 * Description: Define free variables.
133 * Useful for having development builds with debug logging or adding global constants.
134 *
135 * Environment helpers
136 *
137 * See: https://webpack.github.io/docs/list-of-plugins.html#defineplugin
138 */
139 // NOTE: when adding more properties make sure you include them in custom-typings.d.ts
140 new DefinePlugin({
141 'ENV': JSON.stringify(METADATA.ENV),
142 'HMR': METADATA.HMR,
143 'API_URL': JSON.stringify(METADATA.API_URL),
144 'AOT': METADATA.AOT,
145 'process.version': JSON.stringify(process.version),
146 'process.env.ENV': JSON.stringify(METADATA.ENV),
147 'process.env.NODE_ENV': JSON.stringify(METADATA.ENV),
148 'process.env.HMR': METADATA.HMR
149 }),
150
151 /**
152 * Plugin: UglifyJsPlugin
153 * Description: Minimize all JavaScript output of chunks.
154 * Loaders are switched into minimizing mode.
155 *
156 * See: https://webpack.github.io/docs/list-of-plugins.html#uglifyjsplugin
157 */
158 new UglifyJsPlugin({
159 parallel: true,
160 uglifyOptions: {
161 ie8: false,
162 ecma: 6,
163 warnings: false,
164 mangle: true,
165 output: {
166 comments: false,
167 beautify: false
168 }
169 }
170 }),
171
172 /**
173 * Plugin: NormalModuleReplacementPlugin
174 * Description: Replace resources that matches resourceRegExp with newResource
175 *
176 * See: http://webpack.github.io/docs/list-of-plugins.html#normalmodulereplacementplugin
177 */
178 new NormalModuleReplacementPlugin(
179 /(angular2|@angularclass)((\\|\/)|-)hmr/,
180 helpers.root('config/empty.js')
181 ),
182
183 new NormalModuleReplacementPlugin(
184 /zone\.js(\\|\/)dist(\\|\/)long-stack-trace-zone/,
185 helpers.root('config/empty.js')
186 ),
187
188 new HashedModuleIdsPlugin(),
189
190 /**
191 * AoT
192 */
193 (AOT ? (
194 new NormalModuleReplacementPlugin(
195 /@angular(\\|\/)compiler/,
196 helpers.root('config/empty.js')
197 )
198 ) : (new LoaderOptionsPlugin({}))),
199
200 /**
201 * Plugin LoaderOptionsPlugin (experimental)
202 *
203 * See: https://gist.github.com/sokra/27b24881210b56bbaff7
204 */
205 new LoaderOptionsPlugin({
206 minimize: true,
207 debug: false,
208 options: {
209
210 /**
211 * Static analysis linter for TypeScript advanced options configuration
212 * Description: An extensible linter for the TypeScript language.
213 *
214 * See: https://github.com/wbuchwalter/tslint-loader
215 */
216 tslint: {
217 emitErrors: true,
218 failOnHint: true,
219 resourcePath: 'src'
220 },
221
222 /**
223 * Html loader advanced options
224 *
225 * See: https://github.com/webpack/html-loader#advanced-options
226 */
227 // TODO: Need to workaround Angular 2's html syntax => #id [bind] (event) *ngFor
228 htmlLoader: {
229 minimize: true,
230 removeAttributeQuotes: false,
231 caseSensitive: true,
232 customAttrSurround: [
233 [/#/, /(?:)/],
234 [/\*/, /(?:)/],
235 [/\[?\(?/, /(?:)/]
236 ],
237 customAttrAssign: [/\)?]?=/]
238 },
239
240 // FIXME: Remove
241 // https://github.com/bholloway/resolve-url-loader/issues/36
242 // https://github.com/jtangelder/sass-loader/issues/289
243 context: __dirname,
244 output: {
245 path: helpers.root('dist')
246 }
247 }
248 }),
249
250 new BundleAnalyzerPlugin({
251 // Can be `server`, `static` or `disabled`.
252 // In `server` mode analyzer will start HTTP server to show bundle report.
253 // In `static` mode single HTML file with bundle report will be generated.
254 // In `disabled` mode you can use this plugin to just generate Webpack Stats JSON file by setting `generateStatsFile` to `true`.
255 analyzerMode: 'static',
256 // Path to bundle report file that will be generated in `static` mode.
257 // Relative to bundles output directory.
258 reportFilename: 'report.html',
259 // Automatically open report in default browser
260 openAnalyzer: false,
261 // If `true`, Webpack Stats JSON file will be generated in bundles output directory
262 generateStatsFile: true,
263 // Name of Webpack Stats JSON file that will be generated if `generateStatsFile` is `true`.
264 // Relative to bundles output directory.
265 statsFilename: 'stats.json',
266 // Options for `stats.toJson()` method.
267 // For example you can exclude sources of your modules from stats file with `source: false` option.
268 // See more options here: https://github.com/webpack/webpack/blob/webpack-1/lib/Stats.js#L21
269 statsOptions: null,
270 // Log level. Can be 'info', 'warn', 'error' or 'silent'.
271 logLevel: 'info'
272 })
273 ],
274
275 /*
276 * Include polyfills or mocks for various node stuff
277 * Description: Node configuration
278 *
279 * See: https://webpack.github.io/docs/configuration.html#node
280 */
281 node: {
282 global: true,
283 crypto: 'empty',
284 fs: 'empty',
285 process: true,
286 module: false,
287 clearImmediate: false,
288 setImmediate: false
289 }
290
291 })
292 ]
293}
diff --git a/client/config/webpack.video-embed.js b/client/config/webpack.video-embed.js
deleted file mode 100644
index 2b70b6681..000000000
--- a/client/config/webpack.video-embed.js
+++ /dev/null
@@ -1,184 +0,0 @@
1const helpers = require('./helpers')
2
3const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin
4const HtmlWebpackPlugin = require('html-webpack-plugin')
5const UglifyJsPlugin = require('webpack/lib/optimize/UglifyJsPlugin')
6const HashedModuleIdsPlugin = require('webpack/lib/HashedModuleIdsPlugin')
7const ExtractTextPlugin = require('extract-text-webpack-plugin')
8const PurifyCSSPlugin = require('purifycss-webpack')
9
10module.exports = function (options) {
11 const isProd = options && options.env === 'production'
12
13 const configuration = {
14 entry: {
15 'video-embed': './src/standalone/videos/embed.ts'
16 },
17
18 resolve: {
19 /*
20 * An array of extensions that should be used to resolve modules.
21 *
22 * See: http://webpack.github.io/docs/configuration.html#resolve-extensions
23 */
24 extensions: [ '.ts', '.js', '.json', '.scss' ],
25
26 modules: [ helpers.root('src'), helpers.root('node_modules') ]
27 },
28
29 output: {
30 path: helpers.root('dist/standalone/videos'),
31 filename: '[name].[hash].bundle.js',
32 sourceMapFilename: '[file].map',
33 chunkFilename: '[id].chunk.js',
34 publicPath: '/client/standalone/videos/'
35 },
36
37 module: {
38
39 rules: [
40 {
41 test: /\.ts$/,
42 use: [
43 {
44 loader: 'awesome-typescript-loader',
45 options: {
46 configFileName: 'tsconfig.webpack.json',
47 useCache: !isProd
48 }
49 }
50 ],
51 exclude: [/\.(spec|e2e)\.ts$/]
52 },
53
54 {
55 test: /\.(sass|scss)$/,
56 use: ExtractTextPlugin.extract({
57 fallback: 'style-loader',
58 use: [
59 {
60 loader: 'css-loader',
61 options: {
62 sourceMap: true,
63 importLoaders: 1
64 }
65 },
66 'resolve-url-loader',
67 {
68 loader: 'sass-loader',
69 options: {
70 sourceMap: true
71 }
72 },
73 {
74 loader: 'sass-resources-loader',
75 options: {
76 resources: [
77 helpers.root('src/sass/_variables.scss'),
78 helpers.root('src/sass/_mixins.scss')
79 ]
80 }
81 }
82 ]
83 })
84 },
85
86 {
87 test: /\.html$/,
88 use: 'raw-loader',
89 exclude: [
90 helpers.root('src/index.html'),
91 helpers.root('src/standalone/videos/embed.html')
92 ]
93 },
94
95 {
96 test: /\.(jpg|png|gif)$/,
97 use: 'url-loader'
98 },
99
100 { test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, use: 'url-loader?limit=10000&minetype=application/font-woff' },
101 { test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, use: 'file-loader' }
102 ]
103
104 },
105
106 plugins: [
107 new ExtractTextPlugin({
108 filename: '[name].[contenthash].css'
109 }),
110
111 new PurifyCSSPlugin({
112 paths: [ helpers.root('src/standalone/videos/embed.ts') ],
113 purifyOptions: {
114 minify: true,
115 whitelist: [ '*vjs*', '*video-js*' ]
116 }
117 }),
118
119 new CheckerPlugin(),
120
121 new HtmlWebpackPlugin({
122 template: 'src/standalone/videos/embed.html',
123 filename: 'embed.html',
124 title: 'PeerTube',
125 chunksSortMode: 'dependency',
126 inject: 'body'
127 })
128 ],
129
130 node: {
131 global: true,
132 crypto: 'empty',
133 fs: 'empty',
134 process: true,
135 module: false,
136 clearImmediate: false,
137 setImmediate: false
138 }
139 }
140
141 if (isProd) {
142 configuration.module.rules.push(
143 {
144 test: /junk\/index\.js$/,
145 // exclude: /(node_modules|bower_components)/,
146 use: {
147 loader: 'babel-loader',
148 options: {
149 presets: [ 'env' ]
150 }
151 }
152 }
153 )
154
155 configuration.plugins.push(
156 new UglifyJsPlugin({
157 beautify: false,
158 output: {
159 comments: false
160 }, // prod
161 mangle: {
162 screw_ie8: true
163 }, // prod
164 compress: {
165 screw_ie8: true,
166 warnings: false,
167 conditionals: true,
168 unused: true,
169 comparisons: true,
170 sequences: true,
171 dead_code: true,
172 evaluate: true,
173 if_return: true,
174 join_vars: true,
175 negate_iife: false // we need this for lazy v8
176 }
177 }),
178
179 new HashedModuleIdsPlugin()
180 )
181 }
182
183 return configuration
184}