generated from Accuraty/AccuTheme-2021
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.SCSS.config.js
160 lines (153 loc) · 4.69 KB
/
webpack.SCSS.config.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
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
// This needs to be the very first import so that it is the first to run,
// otherwise the env global variable might not contain the contents of the .env file.
import './gulpfileDir/config/envLoader.js';
import path, { resolve } from 'path';
import {
skinStyles,
moduleStyles,
containerStyles,
} from './gulpfileDir/config/paths.js';
/*
Used to dynamically create a key:value mapping from found entry files where the key is the filename without extension.
This is needed because the name token in "filename: '[name].css'" is the key in the mappings.
*/
import { glob } from 'glob';
import autoprefixer from 'autoprefixer';
// ES6 doesn't have __filename or __dirname global variables so this creates them for us.
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// Dynamically set entry points for all JS files in the src directory
const skinFiles = glob.sync(skinStyles.src).reduce((entries, file) => {
// Use the file name (excluding the path) as the key for entry
const entryName = path.basename(file, '.scss');
entries[entryName] = `./${file}`; //Have to add ./ or else webpack will think it is a module
return entries;
}, {});
const moduleFiles = glob.sync(moduleStyles.src).reduce((entries, file) => {
// Use the file name (excluding the path) as the key for entry
const entryName = path.basename(file, '.scss');
entries[entryName] = `./${file}`; //Have to add ./ or else webpack will think it is a module
return entries;
}, {});
/* eslint-disable */ //filename length makes linter want to format this differently than above so turning off to keep same styling
const containerFiles = glob.sync(containerStyles.src).reduce((entries, file) => {
// Use the file name (excluding the path) as the key for entry
const entryName = path.basename(file, '.scss');
entries[entryName] = `./${file}`; //Have to add ./ or else webpack will think it is a module
return entries;
}, {});
/* eslint-enable */
//Array of configs for the webpack version of the skinStylesTask, moduleStylesTask, and containerStylesTask
// Need to figure out how to trigger all 3 in parallel for stand alone webpack
const skinConfig = {
//Skin Styles
mode: 'production',
// stats: 'verbose',
entry: skinFiles,
output: {
path: resolve(__dirname, `${skinStyles.dist}`),
// filename: 'test/[name].css', // Output JS file name based on file name
},
module: {
rules: [
{
test: /\.scss$/,
exclude: /node_modules/,
type: 'asset/resource',
generator: {
filename: '[name].css',
},
use: [
{
loader: 'postcss-loader', // Run PostCSS on the CSS
options: {
postcssOptions: {
plugins: [
[
autoprefixer, // Add vendor prefixes automatically
],
],
},
},
},
'sass-loader',
],
},
],
},
};
const moduleConfig = {
//Module Styles
mode: 'production',
entry: moduleFiles,
output: {
path: resolve(__dirname, `${moduleStyles.dist}`),
// filename: '[name].css', // Output JS file name based on file name
},
module: {
rules: [
{
test: /\.scss$/,
exclude: /node_modules/,
type: 'asset/resource',
generator: {
filename: '[name].css',
},
use: [
{
loader: 'postcss-loader', // Run PostCSS on the CSS
options: {
postcssOptions: {
plugins: [
[
autoprefixer, // Add vendor prefixes automatically
],
],
},
},
},
'sass-loader',
],
},
],
},
};
const containerConfig = {
// Container Styles
mode: 'production',
entry: containerFiles,
output: {
path: resolve(__dirname, `${containerStyles.dist}`),
// filename: '[name].css', // Output JS file name based on file name
},
module: {
rules: [
{
test: /\.scss$/,
exclude: /node_modules/,
type: 'asset/resource',
generator: {
filename: '[name].css',
},
use: [
{
loader: 'postcss-loader', // Run PostCSS on the CSS
options: {
postcssOptions: {
plugins: [
[
autoprefixer, // Add vendor prefixes automatically
],
],
},
},
},
'sass-loader',
],
},
],
},
};
export default skinConfig;
export { skinConfig, moduleConfig, containerConfig };