├── .nvmrc
├── .eslintignore
├── test
├── fixtures
│ ├── entry.css
│ ├── entry.js
│ ├── entry-es6-import.js
│ ├── entry-with-styles.js
│ ├── entry-with-styles2.js
│ ├── styles.css
│ ├── styles2.css
│ ├── styles4.css
│ ├── extract-text-webpack-plugin
│ │ └── with-commons-chunk-plugin
│ │ │ ├── entry.js
│ │ │ ├── entry2.js
│ │ │ ├── entry3.js
│ │ │ └── styles.css
│ ├── custom-runtime-generator.js
│ ├── entry.html
│ ├── styles3.css
│ ├── html-webpack-plugin
│ │ └── template.ejs
│ └── img
│ │ ├── image.svg
│ │ └── image2.svg
├── _setup.js
├── .eslintrc
├── _config.js
├── utils
│ ├── create-compiler.js
│ └── index.js
├── configurator.test.js
├── utils.test.js
└── loader.test.js
├── .mocharc.json
├── plugin.js
├── runtime
├── .eslintrc
├── sprite.js
├── package.json
├── types.d.ts
├── browser-sprite.js
├── sprite.build.js
└── browser-sprite.build.js
├── scripts
├── .eslintrc
├── bootstrap.js
├── utils.js
├── build-runtime.js
├── build.sh
└── select-env.js
├── .npmignore
├── .gitignore
├── lib
├── utils
│ ├── get-matched-rule.js
│ ├── generate-sprite-placeholder.js
│ ├── generate-export.js
│ ├── stringify-symbol.js
│ ├── stringify.js
│ ├── is-webpack-1.js
│ ├── interpolate.js
│ ├── generate-import.js
│ ├── replace-in-module-source.js
│ ├── replace-sprite-placeholder.js
│ ├── normalize-rule.js
│ ├── get-loader-options.js
│ ├── get-matched-rule-5.js
│ ├── get-matched-rule-4.js
│ ├── index.js
│ ├── is-module-should-be-extracted.js
│ ├── get-module-chunk.js
│ ├── get-all-modules.js
│ └── mapped-list.js
├── exceptions.js
├── configurator.js
├── runtime-generator.js
├── loader.js
├── config.js
└── plugin.js
├── .travis.yml
├── .nycrc
├── .github
├── PULL_REQUEST_TEMPLATE.md
└── ISSUE_TEMPLATE.md
├── .editorconfig
├── env
├── webpack-1
│ └── package.json
├── webpack-2
│ └── package.json
├── webpack-3
│ └── package.json
├── webpack-4
│ └── package.json
└── webpack-5
│ └── package.json
├── .eslintrc
├── LICENSE
├── karma.conf.js
├── package.json
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── 2.0.md
├── README.md
└── CHANGELOG.md
/.nvmrc:
--------------------------------------------------------------------------------
1 | v16.20.0
2 |
--------------------------------------------------------------------------------
/.eslintignore:
--------------------------------------------------------------------------------
1 | build
2 | runtime/*.build.js
3 |
--------------------------------------------------------------------------------
/test/fixtures/entry.css:
--------------------------------------------------------------------------------
1 | @import "styles.css";
2 |
--------------------------------------------------------------------------------
/.mocharc.json:
--------------------------------------------------------------------------------
1 | {
2 | "require": "test/_setup.js"
3 | }
--------------------------------------------------------------------------------
/plugin.js:
--------------------------------------------------------------------------------
1 | module.exports = require('./lib/plugin');
2 |
--------------------------------------------------------------------------------
/test/fixtures/entry.js:
--------------------------------------------------------------------------------
1 | require('./img/image.svg');
2 |
--------------------------------------------------------------------------------
/test/fixtures/entry-es6-import.js:
--------------------------------------------------------------------------------
1 | import './img/image.svg';
2 |
--------------------------------------------------------------------------------
/test/fixtures/entry-with-styles.js:
--------------------------------------------------------------------------------
1 | require('./styles.css');
2 |
--------------------------------------------------------------------------------
/test/fixtures/entry-with-styles2.js:
--------------------------------------------------------------------------------
1 | require('./styles2.css');
2 |
--------------------------------------------------------------------------------
/runtime/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "env": {
3 | "browser": true
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/test/fixtures/styles.css:
--------------------------------------------------------------------------------
1 | .img {
2 | background-image: url('img/image.svg');
3 | }
4 |
--------------------------------------------------------------------------------
/test/fixtures/styles2.css:
--------------------------------------------------------------------------------
1 | .img {
2 | background-image: url('img/image2.svg');
3 | }
4 |
--------------------------------------------------------------------------------
/test/fixtures/styles4.css:
--------------------------------------------------------------------------------
1 | .img {
2 | background-image: url('img/image.svg?sprite');
3 | }
4 |
--------------------------------------------------------------------------------
/scripts/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "rules": {
3 | "import/no-extraneous-dependencies": "off"
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/test/fixtures/extract-text-webpack-plugin/with-commons-chunk-plugin/entry.js:
--------------------------------------------------------------------------------
1 | require('./styles.css');
2 |
--------------------------------------------------------------------------------
/test/fixtures/extract-text-webpack-plugin/with-commons-chunk-plugin/entry2.js:
--------------------------------------------------------------------------------
1 | require('./styles.css');
2 |
--------------------------------------------------------------------------------
/test/fixtures/extract-text-webpack-plugin/with-commons-chunk-plugin/entry3.js:
--------------------------------------------------------------------------------
1 | require('./styles.css');
2 |
--------------------------------------------------------------------------------
/test/_setup.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable import/no-extraneous-dependencies */
2 | const chai = require('chai');
3 |
4 | chai.should();
5 |
--------------------------------------------------------------------------------
/test/fixtures/extract-text-webpack-plugin/with-commons-chunk-plugin/styles.css:
--------------------------------------------------------------------------------
1 | .img {
2 | background-image: url('../../img/image.svg');
3 | }
4 |
--------------------------------------------------------------------------------
/runtime/sprite.js:
--------------------------------------------------------------------------------
1 | import Sprite from '@workato/svg-baker-runtime/src/sprite';
2 |
3 | export default new Sprite({ attrs: { id: '__SVG_SPRITE_NODE__' } });
4 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | lib-cov
2 | *.seed
3 | *.log
4 | *.csv
5 | *.dat
6 | *.out
7 | *.pid
8 | *.gz
9 |
10 | pids
11 | logs
12 | results
13 |
14 | npm-debug.log
15 | node_modules
16 | test
17 | .idea
--------------------------------------------------------------------------------
/test/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "env": {
3 | "mocha": true
4 | },
5 | "rules": {
6 | "no-unused-expressions": "off",
7 | "import/no-extraneous-dependencies": "off"
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/test/fixtures/custom-runtime-generator.js:
--------------------------------------------------------------------------------
1 | const { generateExport, stringify } = require('../../lib/utils');
2 |
3 | module.exports = () => {
4 | return generateExport(stringify('olala'));
5 | };
6 |
--------------------------------------------------------------------------------
/test/fixtures/entry.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/test/fixtures/styles3.css:
--------------------------------------------------------------------------------
1 | .a {background-image: url('img/image.svg');}
2 | .a2 {background-image: url('img/image.svg');}
3 | .b {background-image: url('img/image2.svg');}
4 | .b2 {background-image: url('img/image2.svg');}
5 |
--------------------------------------------------------------------------------
/test/_config.js:
--------------------------------------------------------------------------------
1 | const path = require('path');
2 |
3 | module.exports.fixturesPath = path.resolve(__dirname, 'fixtures');
4 | module.exports.loaderPath = require.resolve('..');
5 | module.exports.rootDir = path.resolve(__dirname, '..');
6 |
--------------------------------------------------------------------------------
/runtime/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@workato/svg-sprite-loader-runtime",
3 | "version": "6.1.0",
4 | "main": "browser-sprite.build.js",
5 | "types": "types.d.ts",
6 | "files": [
7 | "browser-sprite.build.js",
8 | "types.d.ts"
9 | ]
10 | }
11 |
--------------------------------------------------------------------------------
/test/fixtures/html-webpack-plugin/template.ejs:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | <%= htmlWebpackPlugin.options.title %>
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | lib-cov
2 | *.seed
3 | *.log
4 | *.csv
5 | *.dat
6 | *.out
7 | *.pid
8 | *.gz
9 | *.iml
10 | *~
11 | .DS_Store
12 |
13 | pids
14 | logs
15 | results
16 |
17 | npm-debug.log
18 | node_modules
19 | coverage
20 | .idea
21 | .current-env
22 | .nyc_output
23 | .vscode/launch.json
24 |
--------------------------------------------------------------------------------
/lib/utils/get-matched-rule.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable global-require */
2 |
3 | let getMatchedRule = null;
4 |
5 | try {
6 | getMatchedRule = require('./get-matched-rule-4');
7 | } catch (e) {
8 | getMatchedRule = require('./get-matched-rule-5');
9 | }
10 |
11 | module.exports = getMatchedRule;
12 |
--------------------------------------------------------------------------------
/lib/utils/generate-sprite-placeholder.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Because of extract-text-webpack-plugin interop returns just absolute path to filepath
3 | * @param {string} filepath
4 | * @return {string}
5 | */
6 | function generateSpritePlaceholder(filepath) {
7 | return filepath;
8 | }
9 |
10 | module.exports = generateSpritePlaceholder;
11 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | sudo: false
2 | language: node_js
3 |
4 | node_js:
5 | - 12.18.1
6 |
7 | branches:
8 | except:
9 | - v0
10 |
11 | env:
12 | global:
13 | - ISTANBUL_COVERAGE: yes
14 |
15 | script:
16 | - nvm install 8.17.0
17 | - sh scripts/build.sh webpack-4
18 | - yarn lint
19 | - yarn test:webpack-2
20 | - yarn test:webpack-3
21 | - yarn test:webpack-4
22 |
--------------------------------------------------------------------------------
/.nycrc:
--------------------------------------------------------------------------------
1 | {
2 | "check-coverage": false,
3 | "per-file": true,
4 | "statements": 85,
5 | "branches": 75,
6 | "functions": 85,
7 | "lines": 85,
8 | "reporter": [
9 | "lcov",
10 | "text",
11 | "html"
12 | ],
13 | "cache": true,
14 | "include": [
15 | "lib/**"
16 | ],
17 | "exclude": [
18 | "lib/utils/generate-import.js",
19 | "lib/utils/get-all-modules.js"
20 | ]
21 | }
22 |
--------------------------------------------------------------------------------
/lib/utils/generate-export.js:
--------------------------------------------------------------------------------
1 | const loaderDefaults = require('../config').loader;
2 |
3 | /**
4 | * @param {string} content
5 | * @param {boolean} [esModule=false]
6 | * @return {string}
7 | */
8 | function generateExport(content, esModule = loaderDefaults.esModule) {
9 | return esModule ?
10 | `export default ${content}` :
11 | `module.exports = ${content}`;
12 | }
13 |
14 | module.exports = generateExport;
15 |
--------------------------------------------------------------------------------
/lib/utils/stringify-symbol.js:
--------------------------------------------------------------------------------
1 | const stringify = require('./stringify');
2 |
3 | /**
4 | * @param {SpriteSymbol} symbol
5 | * @return {string}
6 | */
7 | function stringifySymbol(symbol) {
8 | return stringify({
9 | id: symbol.id,
10 | use: symbol.useId,
11 | viewBox: symbol.viewBox,
12 | content: symbol.render(),
13 | ...symbol.dimensions
14 | });
15 | }
16 |
17 | module.exports = stringifySymbol;
18 |
--------------------------------------------------------------------------------
/lib/utils/stringify.js:
--------------------------------------------------------------------------------
1 | const stringifiedRegexp = /^'|".*'|"$/;
2 |
3 | /**
4 | * If already stringified - return original content
5 | * @param {Object|Array} content
6 | * @return {string}
7 | */
8 | function stringify(content) {
9 | if (typeof content === 'string' && stringifiedRegexp.test(content)) {
10 | return content;
11 | }
12 | return JSON.stringify(content, null, 2);
13 | }
14 |
15 | module.exports = stringify;
16 |
--------------------------------------------------------------------------------
/runtime/types.d.ts:
--------------------------------------------------------------------------------
1 | export interface SvgIcon {
2 | id: string;
3 | width?: number;
4 | height?: number;
5 | }
6 |
7 | export interface SvgSprite {
8 | symbols: SvgSpriteSymbol[];
9 | find: (id: SvgIcon['id']) => SvgIcon;
10 | }
11 |
12 | export interface SvgSpriteSymbol {
13 | id: string;
14 | viewBox: string;
15 | width: number;
16 | height: number;
17 | content: string;
18 | }
19 |
20 | declare const sprite: SvgSprite;
21 |
22 | export default sprite;
23 |
--------------------------------------------------------------------------------
/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | **What kind of change does this PR introduce? (bugfix, feature, docs update, improvement)**
2 |
3 | **What is the current behavior? (You can also link to an open issue here)**
4 |
5 | **What is the new behavior (if this is a feature change)?**
6 |
7 | **Does this PR introduce a breaking change?**
8 |
9 | **Please check if the PR fulfills [contributing guidelines](https://github.com/JetBrains/svg-sprite-loader/blob/master/CONTRIBUTING.md#develop)**
10 |
--------------------------------------------------------------------------------
/lib/utils/is-webpack-1.js:
--------------------------------------------------------------------------------
1 | // eslint-disable-next-line import/no-extraneous-dependencies, import/no-unresolved, global-require
2 | const webpackPkg = require('webpack/package.json') || {};
3 | // eslint-disable-next-line import/no-extraneous-dependencies, import/no-unresolved, global-require
4 | const webpackVersion = webpackPkg.version || require('webpack').version;
5 |
6 | const webpackMajorVersion = parseInt(webpackVersion.split('.')[0], 10);
7 |
8 | module.exports = webpackMajorVersion === 1;
9 |
--------------------------------------------------------------------------------
/lib/utils/interpolate.js:
--------------------------------------------------------------------------------
1 | const { interpolateName } = require('loader-utils');
2 |
3 | /**
4 | * @param {string} pattern
5 | * @param {Object} options
6 | * @param {string} options.resourcePath
7 | * @param {string} [options.context]
8 | * @param {string} [options.content]
9 | */
10 | function interpolate(pattern, options) {
11 | const { resourcePath, context, content } = options;
12 | return interpolateName({ resourcePath }, pattern, { context, content });
13 | }
14 |
15 | module.exports = interpolate;
16 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | # EditorConfig helps developers define and maintain consistent
2 | # coding styles between different editors and IDEs
3 | # editorconfig.org
4 |
5 | root = true
6 |
7 |
8 | [*]
9 |
10 | # Change these settings to your own preference
11 | indent_style = space
12 | indent_size = 2
13 |
14 | # We recommend you to keep these unchanged
15 | end_of_line = lf
16 | charset = utf-8
17 | trim_trailing_whitespace = true
18 | insert_final_newline = true
19 |
20 | [*.md]
21 | trim_trailing_whitespace = false
22 |
--------------------------------------------------------------------------------
/env/webpack-1/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "private": true,
3 | "devDependencies": {
4 | "extract-text-webpack-plugin": "1",
5 | "file-loader": "^0.11.1",
6 | "html-loader": "^0.4.5",
7 | "html-webpack-plugin": "2.28.0",
8 | "webpack": "1",
9 | "eslint": "^3.18.0"
10 | },
11 | "packagesToLink": [
12 | "enhanced-resolve",
13 | "extract-text-webpack-plugin",
14 | "file-loader",
15 | "html-loader",
16 | "html-webpack-plugin",
17 | "webpack",
18 | "eslint"
19 | ]
20 | }
21 |
--------------------------------------------------------------------------------
/env/webpack-2/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "private": true,
3 | "devDependencies": {
4 | "extract-text-webpack-plugin": "2",
5 | "file-loader": "^0.11.1",
6 | "html-loader": "^0.4.5",
7 | "html-webpack-plugin": "2.28.0",
8 | "webpack": "2",
9 | "eslint": "^3.18.0"
10 | },
11 | "packagesToLink": [
12 | "enhanced-resolve",
13 | "extract-text-webpack-plugin",
14 | "file-loader",
15 | "html-loader",
16 | "html-webpack-plugin",
17 | "webpack",
18 | "eslint"
19 | ]
20 | }
21 |
--------------------------------------------------------------------------------
/env/webpack-3/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "private": true,
3 | "devDependencies": {
4 | "extract-text-webpack-plugin": "3",
5 | "file-loader": "^0.11.1",
6 | "html-loader": "^0.4.5",
7 | "html-webpack-plugin": "2.29.0",
8 | "webpack": "3",
9 | "eslint": "^3.18.0"
10 | },
11 | "packagesToLink": [
12 | "enhanced-resolve",
13 | "extract-text-webpack-plugin",
14 | "file-loader",
15 | "html-loader",
16 | "html-webpack-plugin",
17 | "webpack",
18 | "eslint"
19 | ]
20 | }
21 |
--------------------------------------------------------------------------------
/env/webpack-4/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "private": true,
3 | "devDependencies": {
4 | "eslint": "6.8.0",
5 | "extract-text-webpack-plugin": "next",
6 | "file-loader": "1.1.10",
7 | "html-loader": "^0.4.5",
8 | "html-webpack-plugin": "^3.0.6",
9 | "webpack": "^4.43.0"
10 | },
11 | "packagesToLink": [
12 | "enhanced-resolve",
13 | "extract-text-webpack-plugin",
14 | "file-loader",
15 | "html-loader",
16 | "html-webpack-plugin",
17 | "webpack",
18 | "eslint"
19 | ]
20 | }
21 |
--------------------------------------------------------------------------------
/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "extends": [
3 | "airbnb-base"
4 | ],
5 | "env": {
6 | "es6": true,
7 | "node": true
8 | },
9 | "rules": {
10 | "max-len": ["error", 120],
11 | "no-unneeded-ternary": "error",
12 | "arrow-body-style": "off",
13 | "no-return-assign": "off",
14 | "no-param-reassign": "off",
15 | "no-underscore-dangle": "off",
16 | "comma-dangle": ["error", "never"],
17 | "import/no-extraneous-dependencies": ["error", {"devDependencies": ["utils/*.js", "**/*.test.js"]}]
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/lib/utils/generate-import.js:
--------------------------------------------------------------------------------
1 | const loaderDefaults = require('../config').loader;
2 | const stringify = require('./stringify');
3 |
4 | /**
5 | * @param {string} symbol - Symbol name
6 | * @param {string} module - Module name
7 | * @param {boolean} esModule
8 | * @return {string}
9 | */
10 | function generateImport(symbol, module, esModule = loaderDefaults.esModule) {
11 | return esModule ?
12 | `import ${symbol} from ${stringify(module)}` :
13 | `var ${symbol} = require(${stringify(module)})`;
14 | }
15 |
16 | module.exports = generateImport;
17 |
--------------------------------------------------------------------------------
/env/webpack-5/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "private": true,
3 | "devDependencies": {
4 | "mini-css-extract-plugin": "^0.6.0",
5 | "extract-text-webpack-plugin": "^4.0.0-beta.0",
6 | "file-loader": "1.1.10",
7 | "html-loader": "^0.4.5",
8 | "html-webpack-plugin": "^4.5.0",
9 | "webpack": "^5.0.0",
10 | "eslint":"6.8.0"
11 | },
12 | "packagesToLink": [
13 | "enhanced-resolve",
14 | "mini-css-extract-plugin",
15 | "extract-text-webpack-plugin",
16 | "file-loader",
17 | "html-loader",
18 | "html-webpack-plugin",
19 | "webpack",
20 | "eslint"
21 | ]
22 | }
23 |
--------------------------------------------------------------------------------
/scripts/bootstrap.js:
--------------------------------------------------------------------------------
1 | const path = require('path');
2 | const shell = require('shelljs');
3 | const { getCliArgs, getEnvsList } = require('./utils');
4 |
5 | const { cd, echo, exec } = shell;
6 | const projectDir = path.resolve(__dirname, '..');
7 |
8 | const envFromCli = getCliArgs().env;
9 | const envs = getEnvsList(projectDir);
10 | const envToSelect = envFromCli
11 | ? envs.find(e => e.name === envFromCli)
12 | : envs.find(e => e.name === 'webpack-3');
13 |
14 | exec('yarn');
15 |
16 | envs.forEach((env) => {
17 | cd(env.path);
18 | exec('yarn');
19 | echo(`${env.name} env installed`);
20 | });
21 |
22 | cd(projectDir);
23 | exec(`node ${projectDir}/scripts/select-env ${envToSelect.name}`);
24 |
--------------------------------------------------------------------------------
/lib/utils/replace-in-module-source.js:
--------------------------------------------------------------------------------
1 | const replaceSpritePlaceholder = require('./replace-sprite-placeholder');
2 |
3 | /**
4 | * @param {NormalModule|ExtractedModule} module
5 | * @param {Object} replacements
6 | * @return {NormalModule|ExtractedModule}
7 | */
8 | function replaceInModuleSource(module, replacements) {
9 | const source = module._source;
10 |
11 | if (typeof source === 'string') {
12 | module._source = replaceSpritePlaceholder(source, replacements);
13 | } else if (typeof source === 'object' && typeof source._value === 'string') {
14 | source._value = replaceSpritePlaceholder(source._value, replacements);
15 | }
16 |
17 | return module;
18 | }
19 |
20 | module.exports = replaceInModuleSource;
21 |
--------------------------------------------------------------------------------
/lib/utils/replace-sprite-placeholder.js:
--------------------------------------------------------------------------------
1 | const escapeRegExpSpecialChars = require('escape-string-regexp');
2 |
3 | const isWindows = /^win/i.test(process.platform);
4 |
5 | /**
6 | * @param {string} content
7 | * @param {Object} replacements
8 | * @return {string}
9 | */
10 | function replaceSpritePlaceholder(content, replacements) {
11 | let result = content;
12 | Object.keys(replacements)
13 | .forEach((subj) => {
14 | let re = new RegExp(escapeRegExpSpecialChars(subj), 'g');
15 | result = result.replace(re, replacements[subj]);
16 |
17 | if (isWindows) {
18 | re = new RegExp(escapeRegExpSpecialChars(subj), 'g');
19 | result = result.replace(/\\\\/g, '\\').replace(re, replacements[subj]);
20 | }
21 | });
22 |
23 | return result;
24 | }
25 |
26 | module.exports = replaceSpritePlaceholder;
27 |
--------------------------------------------------------------------------------
/lib/utils/normalize-rule.js:
--------------------------------------------------------------------------------
1 | const { parseQuery } = require('loader-utils');
2 | const isWebpack1 = require('./is-webpack-1');
3 |
4 | /**
5 | * webpack 1 compat rule normalizer
6 | * @param {string|Rule} rule (string - webpack 1, Object - webpack 2)
7 | * @return {Object}
8 | */
9 | function normalizeRule(rule) {
10 | if (!rule) {
11 | throw new Error('Rule should be string or object');
12 | }
13 |
14 | let data;
15 |
16 | if (typeof rule === 'string') {
17 | const parts = rule.split('?');
18 | data = {
19 | loader: parts[0],
20 | options: parts[1] ? parseQuery(`?${parts[1]}`) : null
21 | };
22 | } else {
23 | const options = isWebpack1 ? rule.query : rule.options;
24 | data = {
25 | loader: rule.loader,
26 | options: options || null
27 | };
28 | }
29 |
30 | return data;
31 | }
32 |
33 | module.exports = normalizeRule;
34 |
--------------------------------------------------------------------------------
/scripts/utils.js:
--------------------------------------------------------------------------------
1 | const path = require('path');
2 | const minimist = require('minimist');
3 | const glob = require('glob');
4 |
5 | /**
6 | * @return {Array}
7 | */
8 | function getCliArgs() {
9 | return minimist(process.argv.slice(2));
10 | }
11 |
12 | /**
13 | * @param {string} dir Absolute path to folder with env directories
14 | * @return {Array