5
5
const path = require ( 'path' ) ;
6
6
const FileConfig = require ( '@automattic/calypso-build/webpack/file-loader' ) ;
7
7
const Minify = require ( '@automattic/calypso-build/webpack/minify' ) ;
8
- const SassConfig = require ( '@automattic/calypso-build/webpack/sass' ) ;
9
8
const TranspileConfig = require ( '@automattic/calypso-build/webpack/transpile' ) ;
10
- const {
11
- cssNameFromFilename,
12
- shouldTranspileDependency,
13
- } = require ( '@automattic/calypso-build/webpack/util' ) ;
9
+ const { shouldTranspileDependency } = require ( '@automattic/calypso-build/webpack/util' ) ;
14
10
const ExtensiveLodashReplacementPlugin = require ( '@automattic/webpack-extensive-lodash-replacement-plugin' ) ;
15
11
const InlineConstantExportsPlugin = require ( '@automattic/webpack-inline-constant-exports-plugin' ) ;
16
12
const ReactRefreshWebpackPlugin = require ( '@pmmmwh/react-refresh-webpack-plugin' ) ;
17
13
const SentryCliPlugin = require ( '@sentry/webpack-plugin' ) ;
18
- const autoprefixerPlugin = require ( 'autoprefixer' ) ;
19
14
const CircularDependencyPlugin = require ( 'circular-dependency-plugin' ) ;
20
15
const Dotenv = require ( 'dotenv-webpack' ) ;
21
16
const DuplicatePackageCheckerPlugin = require ( 'duplicate-package-checker-webpack-plugin' ) ;
@@ -29,7 +24,7 @@ const GenerateChunksMapPlugin = require( '../build-tools/webpack/generate-chunks
29
24
const ReadOnlyCachePlugin = require ( '../build-tools/webpack/readonly-cache-plugin' ) ;
30
25
const RequireChunkCallbackPlugin = require ( '../build-tools/webpack/require-chunk-callback-plugin' ) ;
31
26
const config = require ( './server/config' ) ;
32
- const { workerCount } = require ( './webpack.common' ) ;
27
+ const { workerCount, getSCSSConfig , getOutputFileName } = require ( './webpack.common' ) ;
33
28
/**
34
29
* Internal variables
35
30
*/
@@ -140,18 +135,8 @@ if ( ! process.env.BROWSERSLIST_ENV ) {
140
135
process . env . BROWSERSLIST_ENV = browserslistEnv ;
141
136
}
142
137
143
- let outputFilename = '[name].[contenthash].min.js' ;
144
- let outputChunkFilename = '[name].[contenthash].min.js' ;
145
-
146
- // we should not use chunkhash in development: https://github.com/webpack/webpack-dev-server/issues/377#issuecomment-241258405
147
- // also we don't minify so dont name them .min.js
148
- if ( isDevelopment ) {
149
- outputFilename = '[name].js' ;
150
- outputChunkFilename = '[name].js' ;
151
- }
152
-
153
- const cssFilename = cssNameFromFilename ( outputFilename ) ;
154
- const cssChunkFilename = cssNameFromFilename ( outputChunkFilename ) ;
138
+ const { outputFilename, outputChunkFilename } = getOutputFileName ( { isDevelopment } ) ;
139
+ const scssConfig = getSCSSConfig ( { outputFilename, outputChunkFilename } ) ;
155
140
156
141
const outputDir = path . resolve ( '.' ) ;
157
142
@@ -235,29 +220,7 @@ const webpackConfig = {
235
220
cacheCompression : false ,
236
221
include : shouldTranspileDependency ,
237
222
} ) ,
238
- SassConfig . loader ( {
239
- includePaths : [ __dirname ] ,
240
- postCssOptions : {
241
- // Do not use postcss.config.js. This ensure we have the final say on how PostCSS is used in calypso.
242
- // This is required because Calypso imports `@automattic/notifications` and that package defines its
243
- // own `postcss.config.js` that they use for their webpack bundling process.
244
- config : false ,
245
- plugins : [ autoprefixerPlugin ( ) ] ,
246
- } ,
247
- // Since `prelude` string will be appended to each Sass file
248
- // We need to ensure that the import path (inside a sass file) is a posix path, regardless of the OS/platform
249
- // Final result should be something like `@use 'client/assets/stylesheets/shared/_utils.scss' as *;`
250
- prelude : `@use '${
251
- path
252
- // Path, relative to Node CWD
253
- . relative (
254
- process . cwd ( ) ,
255
- path . join ( __dirname , 'assets/stylesheets/shared/_utils.scss' )
256
- )
257
- . split ( path . sep ) // Break any path (posix/win32) by path separator
258
- . join ( path . posix . sep ) // Convert the path explicitly to posix to ensure imports work fine
259
- } ' as *;`,
260
- } ) ,
223
+ scssConfig . loader ,
261
224
{
262
225
include : path . join ( __dirname , 'sections.js' ) ,
263
226
loader : path . join ( __dirname , '../build-tools/webpack/sections-loader' ) ,
@@ -320,10 +283,7 @@ const webpackConfig = {
320
283
} ) ,
321
284
new webpack . NormalModuleReplacementPlugin ( / ^ p a t h $ / , 'path-browserify' ) ,
322
285
new webpack . IgnorePlugin ( { resourceRegExp : / ^ \. \/ l o c a l e $ / , contextRegExp : / m o m e n t $ / } ) ,
323
- ...SassConfig . plugins ( {
324
- chunkFilename : cssChunkFilename ,
325
- filename : cssFilename ,
326
- } ) ,
286
+ ...scssConfig . plugins ,
327
287
new AssetsWriter ( {
328
288
filename : `assets.json` ,
329
289
path : path . join ( outputDir , 'build' ) ,
0 commit comments