How to use the getOptions function from loader-utils
Find comprehensive JavaScript loader-utils.getOptions code examples handpicked from public code repositorys.
290 291 292 293 294 295 296 297 298 299
```javascript const loaderUtils = require('loader-utils'); module.exports = function(content) { leanpub-start-insert const { name } = loaderUtils.getOptions(this); leanpub-end-insert const url = loaderUtils.interpolateName( leanpub-start-delete this, '[hash].[ext]', { content }
328
3
7
+ 3 other calls in file
61 62 63 64 65 66 67 68 69
```js module.exports = function(content) { // 获取 options 配置,上面已经讲过了就不在重复 var options = loaderUtils.getOptions(this) || {}; // Options `dataUrlLimit` is backward compatibility with first loader versions // limit 参数,只有文件大小小于这个数值的时候我们才进行base64编码,否则将直接调用 file-loader var limit = options.limit || (this.options && this.options.url && this.options.url.dataUrlLimit);
90
741
30
+ 23 other calls in file
15 16 17 18 19 20 21 22 23 24
async function stylexLoader(input, inputSourceMap) { const { inlineLoader = '', inject = true, ...options } = loaderUtils.getOptions(this) || {}; const callback = this.async(); const {code, map, metadata} = await babel.transformAsync(input, {
18
196
0
103 104 105 106 107 108 109 110 111
```js const loaderUtils = require('loader-utils'); module.exports = function (source) { // 获取到用户句给当前 Loader 传入的 options const options = loaderUtils.getOptions(this); return source; }; ```
19
190
1
+ 11 other calls in file
216 217 218 219 220 221 222 223 224 225
// 拿到babel的参数 需要工具 loaderUtils let loaderUtils =require('loader-utils') function loader(source) { // loader的参数就是源代码 这里的this就是loader的上下文 let options = loaderUtils.getOptions(this) console.log(this.resourcePath, 444); // [./src/index.js] let callback = this.async(); // babel的转换是异步的,同步的返回是不行的, 不能用return 同步就是直接掉用 异步会在async中 babel.transform(source, { ...options,
88
188
12
+ 47 other calls in file
141 142 143 144 145 146 147 148 149
```javascript const loaderUtils = require('loader-utils'); module.exports = function(source) { const options = loaderUtils.getOptions(this); return source.replace('darrell', options.name); } ```
47
191
6
+ 15 other calls in file
12 13 14 15 16 17 18 19 20
// make loader async const cb = this.async(); // merge loader's options with plugin's options from store const options = Object.assign(store.options, getOptions(this)); // basename gets used later to build the key for media query store options.basename = interpolateName(this, '[name]', {});
27
201
9
+ 13 other calls in file
GitHub: tinajs/mina-webpack
13 14 15 16 17 18 19 20 21 22
{ name: '[hash].[ext]', context: this.rootContext, regExp: void 0, }, utils.getOptions(this) ) const publicPath = getPublicPath({}, this) const interpolateName = (content = 'PLACEHOLDER') => toSafeOutputPath(utils.interpolateName(this, options.name, {
20
91
4
+ 15 other calls in file
GitHub: didi/mpx
2 3 4 5 6 7 8 9 10 11
const toPosix = require('./utils/to-posix') const parseRequest = require('./utils/parse-request') const RecordResourceMapDependency = require('./dependencies/RecordResourceMapDependency') module.exports = function loader (content, prevOptions) { const options = prevOptions || loaderUtils.getOptions(this) || {} const context = options.context || this.rootContext let url = loaderUtils.interpolateName(this, options.name, { context,
350
0
91
+ 3 other calls in file
216 217 218 219 220 221 222 223 224 225
```javascript const loaderUtils = require('loader-utils') module.exports = function(content){ // content为文件内容 // 获取webpack关于本loader的配置内容 const options = loaderUtils.getOptions(this) || {} // 获取url路径 const url = loaderUtils.interpolateName(this, options.name, { context: options.context || this.rootContext, content,
5
73
10
GitHub: Baumgaer/Game
20 21 22 23 24 25 26 27 28 29 30 31 32
module.exports = function (source) { this.cacheable(); if (!hasRun) { var query = loaderUtils.getOptions(this); var envOpts = query.opts || {}; if (query) { env = new nunjucks.Environment([], envOpts);
1
2
0
7 8 9 10 11 12 13 14 15 16 17 18
var compileExports = require("./compile-exports"); module.exports = function(content, map) { var callback = this.async(); var query = loaderUtils.getOptions(this) || {}; var moduleMode = query.modules; var camelCaseKeys = query.camelCase; var sourceMap = query.sourceMap || false;
0
1
0
11 12 13 14 15 16 17 18 19 20 21 22
function randomIdent() { return "xxxHTMLLINKxxx" + Math.random() + Math.random() + "xxx"; } function getLoaderConfig(context) { var query = loaderUtils.getOptions(context) || {}; var configKey = query.config || 'htmlLoader'; var config = context.options && context.options.hasOwnProperty(configKey) ? context.options[configKey] : {}; delete query.config;
1
0
0
GitHub: harby9/tphone-core
48 49 50 51 52 53 54 55 56 57
rootContext, resourcePath, resourceQuery } = loaderContext const options = loaderUtils.getOptions(loaderContext) || {} const filename = path.basename(resourcePath) const context = rootContext || process.cwd() const sourceRoot = path.dirname(path.relative(context, resourcePath))
0
0
1
+ 4 other calls in file
36 37 38 39 40 41 42 43 44 45 46 47
* - Execute any entrypoints specified in tui.json (entry and preEntry) */ module.exports = function(jsonSource, map) { const self = this; const options = getOptions(this); const config = JSON.parse(jsonSource); if (!config || !config.component) { throw new Error(
0
0
0
+ 4 other calls in file
GitHub: leechipang/grpc007
20 21 22 23 24 25 26 27 28 29
// webpack 1 compat const resourceQuery = loaderContext.resourceQuery || ''; const compiler = loaderContext._compiler; const isChildCompiler = compiler.isChild(); const parentCompiler = isChildCompiler ? compiler.parentCompilation.compiler : null; const matchedRules = getOptions(loaderContext); if (!content.includes('<svg')) { throw new Exceptions.InvalidSvg(content, matchedRules); }
0
0
1
+ 3 other calls in file
GitHub: leechipang/grpc007
64 65 66 67 68 69 70 71 72 73 74
} function _loader() { _loader = _asyncToGenerator(function* (source, inputSourceMap, overrides) { const filename = this.resourcePath; let loaderOptions = loaderUtils.getOptions(this) || {}; validateOptions(schema, loaderOptions, { name: "Babel loader" });
0
0
1
+ 3 other calls in file
GitHub: Jotti-lohano/BARTLEE
9 10 11 12 13 14 15 16 17 18 19 20 21 22
module.exports = function () {}; module.exports.pitch = function (request) { if (this.cacheable) this.cacheable(); var options = loaderUtils.getOptions(this) || {}; validateOptions(require('./options.json'), options, 'Style Loader (URL)'); options.hmr = typeof options.hmr === 'undefined' ? true : options.hmr;
0
0
1
+ 3 other calls in file
50 51 52 53 54 55 56 57 58 59
this.cacheable() const isServer = this.target === 'node' const isProduction = this.minimize || process.env.NODE_ENV === 'production' const loaderContext = this const query = loaderUtils.getOptions(this) || {} const options = Object.assign( { esModule: true },
0
0
0
+ 2 other calls in file
18 19 20 21 22 23 24 25 26 27 28
module.exports = function svgReactLoader (source) { var context = this; var callback = context.async(); var ctxOpts = context.svgReactLoader; var filters = ctxOpts && ctxOpts.filters || []; var query = lutils.getOptions(context); var rsrcQuery = context.resourceQuery && lutils.parseQuery(context.resourceQuery); var params = R.merge(query || {}, rsrcQuery || {}); var titleCaseDelim = params.titleCaseDelim || /[._-]/;
0
0
0
loader-utils.interpolateName is the most popular function in loader-utils (294 examples)