aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/webpack
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/webpack
parent63c4db6d71b98523753c51747e308682d9a2e8a0 (diff)
downloadPeerTube-7bfd1b1edb7ea4ea6516b6a74c4e9af938d0bdc6.tar.gz
PeerTube-7bfd1b1edb7ea4ea6516b6a74c4e9af938d0bdc6.tar.zst
PeerTube-7bfd1b1edb7ea4ea6516b6a74c4e9af938d0bdc6.zip
Upgrade scripts and embed webpack config
Diffstat (limited to 'client/webpack')
-rw-r--r--client/webpack/helpers.js27
-rw-r--r--client/webpack/webpack.video-embed.js173
2 files changed, 200 insertions, 0 deletions
diff --git a/client/webpack/helpers.js b/client/webpack/helpers.js
new file mode 100644
index 000000000..ca5923472
--- /dev/null
+++ b/client/webpack/helpers.js
@@ -0,0 +1,27 @@
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/webpack/webpack.video-embed.js b/client/webpack/webpack.video-embed.js
new file mode 100644
index 000000000..b51808dc2
--- /dev/null
+++ b/client/webpack/webpack.video-embed.js
@@ -0,0 +1,173 @@
1const helpers = require('./helpers')
2
3const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin
4const HtmlWebpackPlugin = require('html-webpack-plugin')
5const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
6const HashedModuleIdsPlugin = require('webpack/lib/HashedModuleIdsPlugin')
7const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin')
8const ExtractTextPlugin = require('extract-text-webpack-plugin')
9const PurifyCSSPlugin = require('purifycss-webpack')
10
11module.exports = function () {
12 const isProd = process.env.NODE_ENV === 'production'
13
14 const configuration = {
15 entry: {
16 'video-embed': './src/standalone/videos/embed.ts'
17 },
18
19 resolve: {
20 /*
21 * An array of extensions that should be used to resolve modules.
22 *
23 * See: http://webpack.github.io/docs/configuration.html#resolve-extensions
24 */
25 extensions: [ '.ts', '.js', '.json', '.scss' ],
26
27 modules: [ helpers.root('src'), helpers.root('node_modules') ]
28 },
29
30 output: {
31 path: helpers.root('dist/standalone/videos'),
32 filename: '[name].[hash].bundle.js',
33 sourceMapFilename: '[file].map',
34 chunkFilename: '[id].chunk.js',
35 publicPath: '/client/standalone/videos/'
36 },
37
38 module: {
39
40 rules: [
41 {
42 test: /\.ts$/,
43 use: [
44 {
45 loader: 'awesome-typescript-loader',
46 options: {
47 configFileName: 'tsconfig.json'
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 includePaths: [
72 helpers.root('src/sass/include')
73 ]
74 }
75 }
76 ]
77 })
78 },
79
80 {
81 test: /\.html$/,
82 use: 'raw-loader',
83 exclude: [
84 helpers.root('src/index.html'),
85 helpers.root('src/standalone/videos/embed.html')
86 ]
87 },
88
89 {
90 test: /\.(jpg|png|gif)$/,
91 use: 'url-loader'
92 },
93
94 { test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, use: 'url-loader?limit=10000&minetype=application/font-woff' },
95 { test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, use: 'file-loader' }
96 ]
97
98 },
99
100 plugins: [
101 new ExtractTextPlugin({
102 filename: '[name].[contenthash].css'
103 }),
104
105 new PurifyCSSPlugin({
106 paths: [ helpers.root('src/standalone/videos/embed.ts') ],
107 purifyOptions: {
108 minify: true,
109 whitelist: [ '*vjs*', '*video-js*' ]
110 }
111 }),
112
113 new CheckerPlugin(),
114
115 new HtmlWebpackPlugin({
116 template: 'src/standalone/videos/embed.html',
117 filename: 'embed.html',
118 title: 'PeerTube',
119 chunksSortMode: 'dependency',
120 inject: 'body'
121 }),
122
123 /**
124 * Plugin LoaderOptionsPlugin (experimental)
125 *
126 * See: https://gist.github.com/sokra/27b24881210b56bbaff7
127 */
128 new LoaderOptionsPlugin({
129 options: {
130 context: __dirname,
131 output: {
132 path: helpers.root('dist')
133 }
134 }
135 })
136 ],
137
138 node: {
139 global: true,
140 crypto: 'empty',
141 fs: 'empty',
142 process: true,
143 module: false,
144 clearImmediate: false,
145 setImmediate: false
146 }
147 }
148
149 if (isProd) {
150 configuration.plugins.push(
151 new UglifyJsPlugin({
152 uglifyOptions: {
153 ecma: 6,
154 warnings: false,
155 ie8: false,
156 mangle: true,
157 compress: {
158 passes: 3,
159 pure_getters: true
160 },
161 output: {
162 ascii_only: true,
163 comments: false
164 }
165 }
166 }),
167
168 new HashedModuleIdsPlugin()
169 )
170 }
171
172 return configuration
173}