This repository was archived by the owner on May 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.common.js
More file actions
130 lines (123 loc) · 4.64 KB
/
webpack.common.js
File metadata and controls
130 lines (123 loc) · 4.64 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Webpack DEV
// Require dependencies:
const path = require('path');
const absoluteDistributionPath = './';
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const globImporter = require('node-sass-glob-importer');
const autoprefixer = require('autoprefixer');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CopyWebpackPlugin = require('copy-webpack-plugin');
// This is the main configuration object.
module.exports = {
// Path for bundles and filename for the javascript bundle:
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.[name].js'
// (The [name] is related to entry.name in webpack.prod & webpack.dev)
},
module: {
rules: [
{
// Apply rule for .javascript files:
test: /\.js$/,
exclude: /(node_modules)/,
use: [
{
// 2. This loader transpiles ES6 to ES5 (for IE11):
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
},
{
// 1. This loader dynamically imports all *.js files:
loader: 'import-glob'
}
],
},
{
// Apply rule for .sass, .scss or .css files:
test: /\.(sa|sc|c)ss$/,
// Set loaders to transform files.
// Loaders are applied from right to left(!)
use: [
{
// 5. This loader extracts css into a separate bundle:
loader: MiniCssExtractPlugin.loader
},
{
// 4. This loader replaces the development path to assets with a relative path for production
loader: "string-replace-loader",
options: {
multiple: [
{
search: '/images/',
replace: absoluteDistributionPath + 'images/',
flags: 'g'
},
{
search: '/fonts/',
replace: absoluteDistributionPath + 'fonts/',
flags: 'g'
},
{
search: '/icons/',
replace: absoluteDistributionPath + 'icons/',
flags: 'g'
}
]
}
},
{
// 3. This loader resolves url's and @imports in CSS:
loader: "css-loader",
// options: {
// url: '/ui/dist'
// }
},
{
// 2. This loader apply postCSS fixes like autoprefixer and minifying:
loader: "postcss-loader",
options: {
plugins: () => [autoprefixer()]
}
},
{
// 1. First loader transforms SASS to vanilla CSS:
loader: "sass-loader",
options: {
sassOptions: {
// 1. This importer dynamically looks for all *.scss files:
importer: globImporter()
}
}
}
]
},
]
},
plugins: [
// Filename for the stylesheet bundle:
new MiniCssExtractPlugin({
filename: 'bundle.[name].css'
// (The [name] is related to entry.name in webpack.prod & webpack.dev)
}),
// Clean the output.path directory:
new CleanWebpackPlugin(),
// Copy static assets to dist
new CopyWebpackPlugin({
patterns: [
{
from: 'src/static',
globOptions: {
ignore: ['**/*.md'],
},
}
],
},
{
ignore: ['*.md', '*.DS_Store'],
},
),
],
};