Created
May 15, 2017 12:59
-
-
Save EmranAhmed/c24d15cbef94ebe98265378ffbbc81e3 to your computer and use it in GitHub Desktop.
ignore-file-loader create `loaders` dir and put `ignore-file-loader.js`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var loaderUtils = require("loader-utils"); | |
module.exports = function (content) { | |
this.cacheable && this.cacheable(); | |
if (!this.emitFile) throw new Error("emitFile is required from module system"); | |
var query = loaderUtils.getOptions(this) || {}; | |
var configKey = query.config || "ignoreFilesLoader"; | |
var options = this.options[configKey] || {}; | |
var config = { | |
publicPath : false, | |
name : "[hash].[ext]" | |
}; | |
// options takes precedence over config | |
Object.keys(options).forEach(function (attr) { | |
config[attr] = options[attr]; | |
}); | |
// query takes precedence over config and options | |
Object.keys(query).forEach(function (attr) { | |
config[attr] = query[attr]; | |
}); | |
var url = loaderUtils.interpolateName(this, config.name, { | |
context : config.context || this.options.context, | |
content : content, | |
regExp : config.regExp | |
}); | |
var publicPath = "__webpack_public_path__ + " + JSON.stringify(url); | |
if (config.publicPath) { | |
// support functions as publicPath to generate them dynamically | |
publicPath = JSON.stringify( | |
typeof config.publicPath === "function" ? config.publicPath(url) : config.publicPath + url | |
); | |
} | |
return "module.exports = " + publicPath + ";"; | |
} | |
module.exports.raw = true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let rules = [ | |
{ | |
test : /\.css$/, | |
exclude : /assets/, | |
loaders : ['style-loader', 'css-loader'] | |
}, | |
{ | |
test : /\.s[ac]ss$/, | |
include : /node_modules/, | |
loaders : ['style-loader', 'css-loader', 'sass-loader'] | |
}, | |
{ | |
test : /\.html$/, | |
loaders : ['html-loader'] | |
}, | |
{ | |
test : /\.(png|jpe?g|gif)$/, | |
exclude : path.resolve(__dirname, "images"), | |
loaders : [ | |
{ | |
loader : 'file-loader', | |
options : { | |
name : path => { | |
if (!/node_modules|bower_components/.test(path)) { | |
return 'images/[name].[ext]?[hash]'; | |
} | |
return 'images/' + path.replace(/\\/g, '/').replace(/((.*(node_modules|bower_components))|images|image|img|assets|src)\//g, '') + '?[hash]'; | |
}, | |
publicPath : '../../' | |
} | |
}, | |
'img-loader' | |
] | |
}, | |
{ | |
test : /\.(png|jpe?g|gif)$/, | |
include : path.resolve(__dirname, "images"), | |
loaders : [ | |
{ | |
loader : 'ignore-files-loader', | |
options : { | |
name : path => { | |
return 'images/[name].[ext]?[hash]'; | |
}, | |
publicPath : '../../' | |
} | |
}, | |
'img-loader' | |
] | |
}, | |
{ | |
test : /\.(woff2?|ttf|eot|svg|otf)$/, | |
loader : 'file-loader', | |
options : { | |
name : path => { | |
if (!/node_modules|bower_components/.test(path)) { | |
return 'fonts/[name].[ext]?[hash]'; | |
} | |
return 'fonts/' + path.replace(/\\/g, '/').replace(/((.*(node_modules|bower_components))|fonts|font|assets)\//g, '') + '?[hash]'; | |
}, | |
publicPath : '../../' | |
} | |
}, | |
{ | |
test : /\.(cur|ani)$/, | |
loader : 'file-loader', | |
options : { | |
name : '[name].[ext]?[hash]', | |
publicPath : '../../' | |
} | |
} | |
]; | |
module.exports = { | |
// … | |
module: { | |
rules, | |
}, | |
resolveLoader: { | |
modules: [ | |
path.resolve(__dirname, "src/loaders"), // put your ignore-file-loader.js on loaders directory on root path | |
path.resolve(__dirname, "node_modules") | |
] | |
}, | |
// … | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment