Skip to content

Commit

Permalink
feat: 新增rename loader
Browse files Browse the repository at this point in the history
  • Loading branch information
ximing committed Feb 1, 2020
1 parent 1ac4dc3 commit 92c5b5d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mpbuild",
"version": "1.4.0",
"version": "1.4.1",
"description": "",
"main": "src/index.js",
"scripts": {
Expand Down
9 changes: 7 additions & 2 deletions src/loader/rename-loader.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
/**
* Created by ximing on 2019-03-14.
*/
module.exports = function(asset, opts) {
return asset;

module.exports = function(opts = {}) {
return function(asset) {
const [prefixPath, ext] = this.helper.splitExtension(asset.outputFilePath);
asset.outputFilePath = `${prefixPath}.${opts[ext] || ext}`;
return asset;
};
};
6 changes: 4 additions & 2 deletions src/loaderManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const tsLoader = require('./loader/ts-loader');
const tsLoaderNext = require('./loader/ts-loader-next');
const postcssLoader = require('./loader/postcss-loader');
const jsonLoader = require('./loader/json-loader');
const renameLoader = require('./loader/rename-loader');

const map = {
'babel-loader': babelLoader,
Expand All @@ -18,7 +19,8 @@ const map = {
'ts-loader': tsLoader,
'json-loader': jsonLoader,
'ts-loader-next': tsLoaderNext,
'postcss-loader': postcssLoader
'postcss-loader': postcssLoader,
'rename-loader': renameLoader
};

module.exports = class LoaderManager {
Expand Down Expand Up @@ -66,7 +68,7 @@ module.exports = class LoaderManager {
this.rules = [];
for (let i = this.mpb.config.module.rules.length - 1; i >= 0; i--) {
const rule = this.mpb.config.module.rules[i];
let { use, test, exclude, include } = rule;
const { use, test, exclude, include } = rule;
for (let j = use.length - 1; j >= 0; j--) {
const { loader, options } = use[j];
if (!use[j].loaderInstance) {
Expand Down

0 comments on commit 92c5b5d

Please sign in to comment.