-
Notifications
You must be signed in to change notification settings - Fork 42
/
webpack.common.js
68 lines (60 loc) · 1.86 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
56
57
58
59
60
61
62
63
64
65
66
67
68
const path = require('path');
const glob = require('glob');
const loaders = require('./loaders');
const plugins = require('./plugins');
const webpackDir = path.resolve(__dirname);
const rootDir = path.resolve(__dirname, '..');
const distDir = path.resolve(rootDir, 'dist');
// Glob pattern for scss files that ignore file names prefixed with underscore.
const scssPattern = path.resolve(rootDir, 'components/**/!(_*).scss');
// Glob pattern for JS files.
const jsPattern = path.resolve(
rootDir,
'components/**/!(*.stories|*.component|*.min|*.test).js',
);
// Prepare list of scss and js file for "entry".
function getEntries(scssPattern, jsPattern) {
const entries = {};
// SCSS entries
glob.sync(scssPattern).forEach((file) => {
const filePath = file.split('components/')[1];
const newfilePath = `css/${filePath.replace('.scss', '')}`;
entries[newfilePath] = file;
});
// JS entries
glob.sync(jsPattern).forEach((file) => {
const filePath = file.split('components/')[1];
const newfilePath = `js/${filePath.replace('.js', '')}`;
entries[newfilePath] = file;
});
entries.svgSprite = path.resolve(webpackDir, 'svgSprite.js');
// entries.css must renamed into entries.style in order to keep style.css file name.
// Since each css file in derives its name from own entries.property name.
entries.style = path.resolve(webpackDir, 'css.js');
return entries;
}
module.exports = {
stats: {
errorDetails: true,
},
entry: getEntries(scssPattern, jsPattern),
module: {
rules: [
loaders.CSSLoader,
loaders.SVGSpriteLoader,
loaders.ImageLoader,
loaders.JSLoader,
],
},
plugins: [
plugins.MiniCssExtractPlugin,
plugins.ImageminPlugin,
plugins.SpriteLoaderPlugin,
plugins.ProgressPlugin,
plugins.CleanWebpackPlugin,
],
output: {
path: distDir,
filename: '[name].js',
},
};