]>
Commit | Line | Data |
---|---|---|
1 | const helpers = require('./helpers') | |
2 | ||
3 | const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin | |
4 | const HtmlWebpackPlugin = require('html-webpack-plugin') | |
5 | const UglifyJsPlugin = require('uglifyjs-webpack-plugin') | |
6 | const HashedModuleIdsPlugin = require('webpack/lib/HashedModuleIdsPlugin') | |
7 | const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin') | |
8 | const ExtractTextPlugin = require('extract-text-webpack-plugin') | |
9 | const PurifyCSSPlugin = require('purifycss-webpack') | |
10 | ||
11 | module.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 | } |