1
1
import { WebpackConfig , get } from '@easy-webpack/core'
2
+ import * as easyCss from '@easy-webpack/config-css'
2
3
const ExtractTextPlugin = require ( 'extract-text-webpack-plugin' )
3
4
4
5
/**
@@ -9,43 +10,7 @@ const ExtractTextPlugin = require('extract-text-webpack-plugin')
9
10
* extractText: do you want to extract all css to a separate file? boolean, configuration object or instance of ExtractTextPlugin, defaults to true
10
11
* resolveRelativeUrl: boolean or object with parameters
11
12
*/
12
- export = function less ( { filename = '[name].css' , allChunks = false , sourceMap = false , extractText = undefined , resolveRelativeUrl = undefined } = { } ) {
13
- return function less ( this : WebpackConfig ) : WebpackConfig {
14
- const loaders = [ 'style' , `css${ sourceMap ? '?sourceMap' : '' } ` ]
15
-
16
- if ( resolveRelativeUrl ) {
17
- loaders . push ( `resolve-url${ sourceMap ? '?sourceMap' : '' } ` )
18
- sourceMap = true // source maps need to be on for this
19
- }
20
-
21
- loaders . push ( `less${ sourceMap ? '?sourceMap' : '' } ` )
22
-
23
- const extractCss = extractText !== false
24
- const providedInstance = extractText instanceof ExtractTextPlugin
25
- if ( ! providedInstance )
26
- extractText = extractCss ? new ExtractTextPlugin ( filename , extractText instanceof Object ? extractText : { allChunks, sourceMap } ) : null
27
- const config = {
28
- module : {
29
- loaders : get ( this , 'module.loaders' , [ ] ) . concat ( [ {
30
- test : / \. l e s s $ / i,
31
- loaders : extractCss ? extractText . extract ( ...loaders . slice ( 1 ) ) : loaders
32
- } ] )
33
- }
34
- } as WebpackConfig
35
- if ( extractText && ! providedInstance ) {
36
- config . plugins = [
37
- /**
38
- * Plugin: ExtractTextPlugin
39
- * It moves every import "style.css" in entry chunks into a single concatenated css output file.
40
- * So your styles are no longer inlined into the javascript, but separate in a css bundle file (styles.css).
41
- * If your total stylesheet volume is big, it will be faster because the stylesheet bundle is loaded in parallel to the javascript bundle.
42
- */
43
- extractText
44
- ] . concat ( get ( this , 'plugins' , [ ] ) )
45
- }
46
- if ( resolveRelativeUrl instanceof Object ) {
47
- config [ 'resolveUrlLoader' ] = resolveRelativeUrl
48
- }
49
- return config
50
- }
51
- }
13
+ export = function less ( { filename = '[name].css' , allChunks = false , sourceMap = false , extractText = undefined , resolveRelativeUrl = undefined , additionalLoaders = [ ] } = { } ) {
14
+ additionalLoaders . push ( `less${ sourceMap ? '?sourceMap' : '' } ` )
15
+ return easyCss ( { test : / \. l e s s $ / i, filename, allChunks, extractText, resolveRelativeUrl, sourceMap, additionalLoaders } )
16
+ }
0 commit comments