22const path = require ( 'path' ) ;
33const fs = require ( 'fs' ) ;
44const MiniCssExtractPlugin = require ( 'mini-css-extract-plugin' ) ;
5+ const { STYLE_LOADER } = require ( '../core/constant' ) ;
56
67module . exports = {
78
@@ -16,9 +17,10 @@ module.exports = {
1617 if ( loaders [ name ] ) {
1718 return loaders [ name ] ;
1819 }
20+ const mappingName = this . loaderKeyLabelMapping [ name ] ;
1921 return rules . find ( loader => {
2022 const label = this . utils . getLoaderLabel ( loader ) ;
21- if ( name === label ) {
23+ if ( name === label || mappingName === label ) {
2224 return true ;
2325 }
2426 return false ;
@@ -44,7 +46,7 @@ module.exports = {
4446 } ,
4547
4648 createBabelLoader ( babel = { } ) {
47- babel = this . merge ( { loader : 'babel-loader' , options : { } } , babel ) ;
49+ babel = this . merge ( { loader : 'babel-loader' , options : { } } , babel ) ;
4850 const babelEnv = process . env . BABEL_ENV ;
4951 if ( babelEnv ) {
5052 if ( this . isBabel7 ) { // @babel /core use envName key
@@ -229,6 +231,55 @@ module.exports = {
229231 return webpackLoaders ;
230232 } ,
231233
234+
235+ createFrameworkLoader ( styleLoader = 'style-loader' , options ) {
236+ const preLoaders = { } ;
237+ const loaders = { js : this . createBabelLoader ( ) } ; // fix vue entry babel compile
238+ const extract = this . isUse ( 'extract' ) ;
239+ Object . keys ( this . loaders ) . forEach ( name => {
240+ const itemLoader = this . loaders [ name ] ;
241+ if ( itemLoader . framework && ( itemLoader . enable || itemLoader . enable === undefined ) ) {
242+ const useLoaders = this . utils . cloneDeep ( itemLoader ) . use ;
243+ if ( name !== 'css' ) {
244+ const preLoader = useLoaders [ useLoaders . length - 1 ] ; // get last loader
245+ if ( this . utils . isString ( preLoader ) ) {
246+ preLoaders [ name ] = preLoader ;
247+ } else if ( this . utils . isObject ( preLoader ) && preLoader . options ) {
248+ preLoaders [ name ] = `${ preLoader . loader } ?${ JSON . stringify ( preLoader . options ) } ` ;
249+ } else {
250+ preLoaders [ name ] = preLoader . loader ;
251+ }
252+ }
253+ if ( extract ) {
254+ useLoaders . forEach ( item => {
255+ if ( item . loader === STYLE_LOADER ) {
256+ item . loader = styleLoader ;
257+ }
258+ } ) ;
259+ loaders [ name ] = useLoaders ;
260+ } else {
261+ const filterLoaders = useLoaders . filter ( item => {
262+ return item . loader !== STYLE_LOADER && item . loader !== styleLoader ;
263+ } ) ;
264+ filterLoaders . unshift ( { loader : styleLoader , options } ) ;
265+ loaders [ name ] = filterLoaders ;
266+ }
267+ }
268+ } ) ;
269+ // https://github.com/TypeStrong/ts-loader/pull/782
270+ // vue-loader 14 版本中,需在 options 重复配置 ts-loader,升级 15 以后可移除
271+ if ( this . typescript && ! loaders . ts ) {
272+ const use = this . utils . isFunction ( this . typescript . use ) ? this . typescript . use . apply ( this ) : this . typescript . use ;
273+ const tsLoader = use . find ( item => {
274+ return item . loader === 'ts-loader' ;
275+ } ) ;
276+ if ( tsLoader ) {
277+ loaders . ts = tsLoader ;
278+ }
279+ }
280+ return { preLoaders, loaders } ;
281+ } ,
282+
232283 installLoader ( loaders ) {
233284 const dependencies = this . dependencies ;
234285 const webpackLoaders = this . createLoader ( loaders ) ;
0 commit comments