-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwebpack.common.js
More file actions
170 lines (169 loc) · 4.75 KB
/
Copy pathwebpack.common.js
File metadata and controls
170 lines (169 loc) · 4.75 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
const path = require('path');
const glob = require('glob');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const RemovePlugin = require('remove-files-webpack-plugin');
const StylelintPlugin = require('stylelint-webpack-plugin');
const SpriteLoaderPlugin = require('svg-sprite-loader/plugin');
const embeddedSass = require('sass-embedded');
module.exports = {
entry: () => {
// Grab any JS files.
const jsFiles = glob
.sync('source/**/!(*.stories).js', {
ignore: ['**/_*'],
})
.reduce((entries, currentFile) => {
const updatedEntries = entries;
const filePaths = currentFile.split(path.sep);
const sourceDirIndex = filePaths.indexOf('source');
if (sourceDirIndex >= 0) {
const fileName = path.basename(currentFile, '.js');
const newFilePath = `js/${fileName}`;
// Throw an error if duplicate files detected.
if (updatedEntries[newFilePath]) {
throw new Error(`More than one file named ${fileName}.js found.`);
}
updatedEntries[newFilePath] = {
import: path.resolve(__dirname, currentFile),
};
}
return updatedEntries;
}, {});
// Grab any SCSS files that aren't prefixed with _.
const scssFiles = glob
.sync('source/**/*.scss', {
ignore: ['**/_*'],
})
.reduce((entries, currentFile) => {
const updatedEntries = entries;
const filePaths = currentFile.split(path.sep);
const sourceDirIndex = filePaths.indexOf('source');
if (sourceDirIndex >= 0) {
const fileName = path.basename(currentFile, '.scss');
const newFilePath = `css/${fileName}`;
// Throw an error if duplicate files detected.
if (updatedEntries[newFilePath]) {
throw new Error(`More that one file named ${fileName}.scss found.`);
}
updatedEntries[newFilePath] = {
import: `./${currentFile}`,
};
}
return updatedEntries;
}, {});
return {
...jsFiles,
...scssFiles,
};
},
plugins: [
new MiniCssExtractPlugin(),
new RemovePlugin({
after: {
test: [
{
folder: './dist/css',
method: absolutePath =>
new RegExp(/\.js(\.map)?$/, 'm').test(absolutePath),
recursive: true,
},
],
},
}),
new StylelintPlugin({
exclude: ['node_modules', 'dist', 'storybook'],
}),
new SpriteLoaderPlugin(),
],
module: {
rules: [
{
test: /config\.design-tokens\.yml$/,
exclude: /node_modules/,
use: [path.resolve(__dirname, './lib/configLoader.js')],
type: 'asset/source',
},
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: ['babel-loader'],
},
{
test: /\.scss$/i,
exclude: /node_modules/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
publicPath: '../',
},
},
{
loader: 'css-loader',
options: {
// Ignore /core/ URLs
url: {
filter: url => !url.includes('/core/'),
},
},
},
'postcss-loader',
{
loader: 'sass-loader',
options: {
implementation: embeddedSass,
webpackImporter: false,
sassOptions: {
loadPaths: [path.resolve(__dirname, 'source')],
},
},
},
],
},
{
test: /images\/_sprite-source-files\/.*\.svg$/,
exclude: /node_modules/,
use: [
{
loader: 'svg-sprite-loader',
options: {
extract: true,
spriteFilename: 'sprite.artifact.svg',
outputPath: 'images/',
},
},
'svg-transform-loader',
'svgo-loader',
],
},
{
test: /fonts\/.*\.(woff2?|ttf|otf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/i,
exclude: ['/node_modules/'],
type: 'asset/resource',
generator: {
filename: 'fonts/[hash][ext][query]',
},
},
{
test: /\.(png|svg|jpg|gif)$/i,
exclude: [/images\/_sprite-source-files\/.*\.svg$/, '/node_modules/'],
type: 'asset',
generator: {
filename: 'images/[hash][ext][query]',
},
},
],
},
externals: {
jquery: 'jQuery',
drupal: 'Drupal',
drupalSettings: 'drupalSettings',
once: 'once',
},
resolve: {
modules: [path.resolve(__dirname, 'source'), 'node_modules'],
},
output: {
path: path.resolve(__dirname, 'dist'),
},
};