diff options
Diffstat (limited to 'webpack.config.js')
-rw-r--r-- | webpack.config.js | 71 |
1 files changed, 39 insertions, 32 deletions
diff --git a/webpack.config.js b/webpack.config.js index 602147e5..a4aa633e 100644 --- a/webpack.config.js +++ b/webpack.config.js | |||
@@ -2,29 +2,26 @@ const path = require('path'); | |||
2 | const glob = require('glob'); | 2 | const glob = require('glob'); |
3 | 3 | ||
4 | // Minify JS | 4 | // Minify JS |
5 | const MinifyPlugin = require('babel-minify-webpack-plugin'); | 5 | const TerserPlugin = require('terser-webpack-plugin'); |
6 | 6 | ||
7 | // This plugin extracts the CSS into its own file instead of tying it with the JS. | 7 | // This plugin extracts the CSS into its own file instead of tying it with the JS. |
8 | // It prevents: | 8 | // It prevents: |
9 | // - not having styles due to a JS error | 9 | // - not having styles due to a JS error |
10 | // - the flash page without styles during JS loading | 10 | // - the flash page without styles during JS loading |
11 | const ExtractTextPlugin = require("extract-text-webpack-plugin"); | 11 | const MiniCssExtractPlugin = require("mini-css-extract-plugin"); |
12 | 12 | ||
13 | const extractCssDefault = new ExtractTextPlugin({ | 13 | const extractCss = new MiniCssExtractPlugin({ |
14 | filename: "../css/[name].min.css", | 14 | filename: "../css/[name].min.css", |
15 | publicPath: 'tpl/default/css/', | ||
16 | }); | ||
17 | |||
18 | const extractCssVintage = new ExtractTextPlugin({ | ||
19 | filename: "../css/[name].min.css", | ||
20 | publicPath: 'tpl/vintage/css/', | ||
21 | }); | 15 | }); |
22 | 16 | ||
23 | module.exports = [ | 17 | module.exports = [ |
24 | { | 18 | { |
19 | mode: 'production', | ||
25 | entry: { | 20 | entry: { |
21 | shaare_batch: './assets/common/js/shaare-batch.js', | ||
26 | thumbnails: './assets/common/js/thumbnails.js', | 22 | thumbnails: './assets/common/js/thumbnails.js', |
27 | thumbnails_update: './assets/common/js/thumbnails-update.js', | 23 | thumbnails_update: './assets/common/js/thumbnails-update.js', |
24 | metadata: './assets/common/js/metadata.js', | ||
28 | pluginsadmin: './assets/default/js/plugins-admin.js', | 25 | pluginsadmin: './assets/default/js/plugins-admin.js', |
29 | shaarli: [ | 26 | shaarli: [ |
30 | './assets/default/js/base.js', | 27 | './assets/default/js/base.js', |
@@ -45,23 +42,23 @@ module.exports = [ | |||
45 | loader: 'babel-loader', | 42 | loader: 'babel-loader', |
46 | options: { | 43 | options: { |
47 | presets: [ | 44 | presets: [ |
48 | 'babel-preset-env', | 45 | '@babel/preset-env', |
49 | ] | 46 | ] |
50 | } | 47 | } |
51 | } | 48 | } |
52 | }, | 49 | }, |
53 | { | 50 | { |
54 | test: /\.s?css/, | 51 | test: /\.s?css/, |
55 | use: extractCssDefault.extract({ | 52 | use: [ |
56 | use: [{ | 53 | { |
57 | loader: "css-loader", | 54 | loader: MiniCssExtractPlugin.loader, |
58 | options: { | 55 | options: { |
59 | minimize: true, | 56 | publicPath: 'tpl/default/css/', |
60 | } | 57 | }, |
61 | }, { | 58 | }, |
62 | loader: "sass-loader" | 59 | 'css-loader', |
63 | }], | 60 | 'sass-loader', |
64 | }) | 61 | ], |
65 | }, | 62 | }, |
66 | { | 63 | { |
67 | test: /\.(gif|png|jpe?g|svg|ico)$/i, | 64 | test: /\.(gif|png|jpe?g|svg|ico)$/i, |
@@ -81,17 +78,21 @@ module.exports = [ | |||
81 | options: { | 78 | options: { |
82 | name: '../fonts/[name].[ext]', | 79 | name: '../fonts/[name].[ext]', |
83 | // do not add a publicPath here because it's already handled by CSS's publicPath | 80 | // do not add a publicPath here because it's already handled by CSS's publicPath |
84 | publicPath: '', | 81 | publicPath: '../default/', |
85 | } | 82 | } |
86 | }, | 83 | }, |
87 | ], | 84 | ], |
88 | }, | 85 | }, |
86 | optimization: { | ||
87 | minimize: true, | ||
88 | minimizer: [new TerserPlugin()], | ||
89 | }, | ||
89 | plugins: [ | 90 | plugins: [ |
90 | new MinifyPlugin(), | 91 | extractCss, |
91 | extractCssDefault, | ||
92 | ], | 92 | ], |
93 | }, | 93 | }, |
94 | { | 94 | { |
95 | mode: 'production', | ||
95 | entry: { | 96 | entry: { |
96 | shaarli: [ | 97 | shaarli: [ |
97 | './assets/vintage/js/base.js', | 98 | './assets/vintage/js/base.js', |
@@ -100,6 +101,7 @@ module.exports = [ | |||
100 | ].concat(glob.sync('./assets/vintage/img/*')), | 101 | ].concat(glob.sync('./assets/vintage/img/*')), |
101 | markdown: './assets/common/css/markdown.css', | 102 | markdown: './assets/common/css/markdown.css', |
102 | thumbnails: './assets/common/js/thumbnails.js', | 103 | thumbnails: './assets/common/js/thumbnails.js', |
104 | metadata: './assets/common/js/metadata.js', | ||
103 | thumbnails_update: './assets/common/js/thumbnails-update.js', | 105 | thumbnails_update: './assets/common/js/thumbnails-update.js', |
104 | }, | 106 | }, |
105 | output: { | 107 | output: { |
@@ -115,21 +117,23 @@ module.exports = [ | |||
115 | loader: 'babel-loader', | 117 | loader: 'babel-loader', |
116 | options: { | 118 | options: { |
117 | presets: [ | 119 | presets: [ |
118 | 'babel-preset-env', | 120 | '@babel/preset-env', |
119 | ] | 121 | ] |
120 | } | 122 | } |
121 | } | 123 | } |
122 | }, | 124 | }, |
123 | { | 125 | { |
124 | test: /\.css$/, | 126 | test: /\.css$/, |
125 | use: extractCssVintage.extract({ | 127 | use: [ |
126 | use: [{ | 128 | { |
127 | loader: "css-loader", | 129 | loader: MiniCssExtractPlugin.loader, |
128 | options: { | 130 | options: { |
129 | minimize: true, | 131 | publicPath: 'tpl/vintage/css/', |
130 | } | 132 | }, |
131 | }], | 133 | }, |
132 | }) | 134 | 'css-loader', |
135 | 'sass-loader', | ||
136 | ], | ||
133 | }, | 137 | }, |
134 | { | 138 | { |
135 | test: /\.(gif|png|jpe?g|svg|ico)$/i, | 139 | test: /\.(gif|png|jpe?g|svg|ico)$/i, |
@@ -145,9 +149,12 @@ module.exports = [ | |||
145 | }, | 149 | }, |
146 | ], | 150 | ], |
147 | }, | 151 | }, |
152 | optimization: { | ||
153 | minimize: true, | ||
154 | minimizer: [new TerserPlugin()], | ||
155 | }, | ||
148 | plugins: [ | 156 | plugins: [ |
149 | new MinifyPlugin(), | 157 | extractCss, |
150 | extractCssVintage, | ||
151 | ], | 158 | ], |
152 | }, | 159 | }, |
153 | ]; | 160 | ]; |