-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathwebpack.common.js
55 lines (54 loc) · 1.59 KB
/
webpack.common.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const path = require('path');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const csso = require('csso');
const fs = require('fs');
const cssDist = path.resolve(__dirname, 'css/dist');
const cssTransform = (content, filename) => {
const basename = path.basename(filename);
const result = csso.minify(content.toString(), {
filename: basename,
sourceMap: true
});
const output = basename === 'index.css' ? 'chartist.css' : basename;
fs.writeFile(`css/dist/${output}.map`, result.map.toString(), (err) => { if (err) { throw err; }});
return `${result.css}\n/*# sourceMappingURL=${output}.map */`;
}
module.exports = {
entry: './js/src/ulogger.js',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'js/dist'),
publicPath: 'js/dist/'
},
plugins: [
new CleanWebpackPlugin({
cleanOnceBeforeBuildPatterns: [ '**/*', '!.*' ]
}),
new CopyWebpackPlugin({
patterns: [
{ from: 'css/src/*.css', to: `${cssDist}/[name][ext]`, transform: cssTransform },
{ from: 'node_modules/ol/ol.css', to: `${cssDist}/[name][ext]`, transform: cssTransform },
{ from: 'node_modules/chartist/dist/index.css', to: `${cssDist}/chartist[ext]`, transform: cssTransform }
]
})
],
optimization: {
splitChunks: {
cacheGroups: {
vendors: {
test: /[\\/]node_modules[\\/]|[\\/]ol.js/,
name: 'ol'
}
}
}
},
module: {
rules: [
{
resourceQuery: /raw/,
type: 'asset/source'
}
]
}
};