Best JavaScript code snippet using storybook-root
createConfig.test.js
Source:createConfig.test.js
1'use strict';2const path = require('path');3const createConfig = require('../../../lib/utils/createConfig');4const webpackConfig = require('./../../fixtures/schema/webpack.config.simple');5const webpackConfigNoStats = require('./../../fixtures/schema/webpack.config.no-dev-stats');6const argv = {7 port: 8080,8 // Can be `--no-hot` in CLI (undocumented)9 hot: true,10 // Can be `--no-hot-only` in CLI (misleading and undocumented)11 hotOnly: false,12};13describe('createConfig', () => {14 it('simple', () => {15 const config = createConfig(webpackConfig, Object.assign({}, argv), {16 port: 8080,17 });18 expect(config).toMatchSnapshot();19 });20 it('bonjour option', () => {21 const config = createConfig(22 webpackConfig,23 Object.assign({}, argv, {24 bonjour: true,25 }),26 { port: 8080 }27 );28 expect(config).toMatchSnapshot();29 });30 it('bonjour option (devServer config)', () => {31 const config = createConfig(32 Object.assign({}, webpackConfig, { devServer: { bonjour: true } }),33 argv,34 { port: 8080 }35 );36 expect(config).toMatchSnapshot();37 });38 it('host option', () => {39 const config = createConfig(40 webpackConfig,41 Object.assign({}, argv, {42 host: 'example.dev',43 }),44 { port: 8080 }45 );46 expect(config).toMatchSnapshot();47 });48 it('host option (localhost)', () => {49 const config = createConfig(50 webpackConfig,51 Object.assign({}, argv, {52 host: 'localhost',53 }),54 { port: 8080 }55 );56 expect(config).toMatchSnapshot();57 });58 it('host option (undefined)', () => {59 const config = createConfig(60 webpackConfig,61 Object.assign({}, argv, {62 // eslint-disable-next-line no-undefined63 host: undefined,64 }),65 { port: 8080 }66 );67 expect(config).toMatchSnapshot();68 });69 it('host option (null)', () => {70 const config = createConfig(71 webpackConfig,72 Object.assign({}, argv, {73 // eslint-disable-next-line no-undefined74 host: null,75 }),76 { port: 8080 }77 );78 expect(config).toMatchSnapshot();79 });80 it('host option (devServer config)', () => {81 const config = createConfig(82 Object.assign({}, webpackConfig, { devServer: { host: 'example.dev' } }),83 argv,84 { port: 8080 }85 );86 expect(config).toMatchSnapshot();87 });88 it('host option (specify for CLI and devServer config)', () => {89 const config = createConfig(90 Object.assign({}, webpackConfig, { devServer: { host: 'example.dev' } }),91 Object.assign({}, argv, { host: 'other.dev' }),92 { port: 8080 }93 );94 expect(config).toMatchSnapshot();95 });96 it('allowedHosts option', () => {97 const config = createConfig(98 webpackConfig,99 Object.assign({}, argv, {100 allowedHosts: '.host.com,host2.com',101 }),102 { port: 8080 }103 );104 expect(config).toMatchSnapshot();105 });106 it('allowedHosts option (devServer config)', () => {107 const config = createConfig(108 Object.assign({}, webpackConfig, {109 devServer: { allowedHosts: ['.host.com', 'host2.com'] },110 }),111 argv,112 { port: 8080 }113 );114 expect(config).toMatchSnapshot();115 });116 it('public option', () => {117 const config = createConfig(118 webpackConfig,119 Object.assign({}, argv, {120 public: true,121 }),122 { port: 8080 }123 );124 expect(config).toMatchSnapshot();125 });126 it('public option (devServer config)', () => {127 const config = createConfig(128 Object.assign({}, webpackConfig, {129 devServer: { public: true },130 }),131 argv,132 { port: 8080 }133 );134 expect(config).toMatchSnapshot();135 });136 it('socket option', () => {137 const config = createConfig(138 webpackConfig,139 Object.assign({}, argv, {140 socket: 'socket',141 }),142 { port: 8080 }143 );144 expect(config).toMatchSnapshot();145 });146 it('socket option (devServer config)', () => {147 const config = createConfig(148 Object.assign({}, webpackConfig, {149 devServer: { socket: 'socket' },150 }),151 argv,152 { port: 8080 }153 );154 expect(config).toMatchSnapshot();155 });156 it('progress option', () => {157 const config = createConfig(158 webpackConfig,159 Object.assign({}, argv, {160 progress: true,161 }),162 { port: 8080 }163 );164 expect(config).toMatchSnapshot();165 });166 it('progress option (devServer config)', () => {167 const config = createConfig(168 Object.assign({}, webpackConfig, {169 devServer: { progress: true },170 }),171 argv,172 { port: 8080 }173 );174 expect(config).toMatchSnapshot();175 });176 it('publicPath option (not specify)', () => {177 const config = createConfig(webpackConfig, argv, { port: 8080 });178 expect(config).toMatchSnapshot();179 });180 it('publicPath option (path in devServer option)', () => {181 const config = createConfig(182 Object.assign({}, webpackConfig, {183 devServer: { publicPath: '/assets/' },184 }),185 argv,186 { port: 8080 }187 );188 expect(config).toMatchSnapshot();189 });190 it('publicPath option (url in devServer option)', () => {191 const config = createConfig(192 Object.assign({}, webpackConfig, {193 devServer: { publicPath: 'http://localhost:8080/assets/' },194 }),195 argv,196 { port: 8080 }197 );198 expect(config).toMatchSnapshot();199 });200 it('publicPath option (url in output option)', () => {201 const config = createConfig(202 Object.assign({}, webpackConfig, {203 output: { publicPath: 'http://localhost:8080/assets/' },204 }),205 argv,206 { port: 8080 }207 );208 expect(config).toMatchSnapshot();209 });210 it('publicPath option (path in output option)', () => {211 const config = createConfig(212 Object.assign({}, webpackConfig, {213 output: { publicPath: '/assets/' },214 }),215 argv,216 { port: 8080 }217 );218 expect(config).toMatchSnapshot();219 });220 it('publicPath option (path without starting slash in output option)', () => {221 const config = createConfig(222 Object.assign({}, webpackConfig, {223 output: { publicPath: 'assets/' },224 }),225 argv,226 { port: 8080 }227 );228 expect(config).toMatchSnapshot();229 });230 it('filename option (in webpack config)', () => {231 const config = createConfig(232 Object.assign({}, webpackConfig, {233 output: { filename: '[name]-bundle.js' },234 }),235 argv,236 { port: 8080 }237 );238 expect(config).toMatchSnapshot();239 });240 it('filename option (in output config)', () => {241 const config = createConfig(242 Object.assign({}, webpackConfig, {243 output: { filename: '[name]-output-bundle.js' },244 }),245 argv,246 { port: 8080 }247 );248 expect(config).toMatchSnapshot();249 });250 it('filename option (in devServer config)', () => {251 const config = createConfig(252 Object.assign({}, webpackConfig, {253 devServer: { filename: '[name]-dev-server-bundle.js' },254 }),255 argv,256 { port: 8080 }257 );258 expect(config).toMatchSnapshot();259 });260 it('watchOptions option (in output config)', () => {261 const config = createConfig(262 Object.assign({}, webpackConfig, {263 watchOptions: { poll: true },264 }),265 argv,266 { port: 8080 }267 );268 expect(config).toMatchSnapshot();269 });270 it('watchOptions option (in devServer config)', () => {271 const config = createConfig(272 Object.assign({}, webpackConfig, {273 devServer: { watchOptions: { poll: true } },274 }),275 argv,276 { port: 8080 }277 );278 expect(config).toMatchSnapshot();279 });280 it('hot option', () => {281 const config = createConfig(282 webpackConfig,283 Object.assign({}, argv, { hot: true }),284 { port: 8080 }285 );286 expect(config).toMatchSnapshot();287 });288 it('hot option (in devServer config)', () => {289 const config = createConfig(290 Object.assign({}, webpackConfig, {291 devServer: { hot: true },292 }),293 argv,294 { port: 8080 }295 );296 expect(config).toMatchSnapshot();297 });298 it('hotOnly option', () => {299 const config = createConfig(300 webpackConfig,301 Object.assign({}, argv, { hotOnly: true }),302 { port: 8080 }303 );304 expect(config).toMatchSnapshot();305 });306 it('hotOnly option (in devServer config)', () => {307 const config = createConfig(308 Object.assign({}, webpackConfig, {309 devServer: { hotOnly: true },310 }),311 argv,312 { port: 8080 }313 );314 expect(config).toMatchSnapshot();315 });316 it('clientLogLevel option', () => {317 const config = createConfig(318 webpackConfig,319 Object.assign({}, argv, { clientLogLevel: 'none' }),320 { port: 8080 }321 );322 expect(config).toMatchSnapshot();323 });324 it('clientLogLevel option (in devServer config)', () => {325 const config = createConfig(326 Object.assign({}, webpackConfig, {327 devServer: { clientLogLevel: 'none' },328 }),329 argv,330 { port: 8080 }331 );332 expect(config).toMatchSnapshot();333 });334 it('contentBase option (string)', () => {335 const config = createConfig(336 webpackConfig,337 Object.assign({}, argv, { contentBase: 'assets' }),338 { port: 8080 }339 );340 config.contentBase = path.relative(process.cwd(), config.contentBase);341 expect(config).toMatchSnapshot();342 });343 it('contentBase option (array)', () => {344 const config = createConfig(345 webpackConfig,346 Object.assign({}, argv, { contentBase: ['assets', 'static'] }),347 { port: 8080 }348 );349 config.contentBase = config.contentBase.map((item) =>350 path.relative(process.cwd(), item)351 );352 expect(config).toMatchSnapshot();353 });354 it('contentBase option (boolean)', () => {355 const config = createConfig(356 webpackConfig,357 Object.assign({}, argv, { contentBase: false }),358 { port: 8080 }359 );360 expect(config).toMatchSnapshot();361 });362 it('contentBase option (string) (in devServer config)', () => {363 const config = createConfig(364 Object.assign({}, webpackConfig, {365 devServer: { contentBase: 'assets' },366 }),367 argv,368 { port: 8080 }369 );370 config.contentBase = path.relative(process.cwd(), config.contentBase);371 expect(config).toMatchSnapshot();372 });373 it('watchContentBase option', () => {374 const config = createConfig(375 webpackConfig,376 Object.assign({}, argv, { watchContentBase: true }),377 { port: 8080 }378 );379 expect(config).toMatchSnapshot();380 });381 it('watchContentBase option (in devServer config)', () => {382 const config = createConfig(383 Object.assign({}, webpackConfig, {384 devServer: { watchContentBase: true },385 }),386 argv,387 { port: 8080 }388 );389 expect(config).toMatchSnapshot();390 });391 it('stats option', () => {392 const config = createConfig(393 Object.assign({}, webpackConfig, {394 devServer: { stats: 'errors-only' },395 }),396 argv,397 { port: 8080 }398 );399 expect(config).toMatchSnapshot();400 });401 it('stats option (colors)', () => {402 const config = createConfig(403 Object.assign({}, webpackConfig, {404 devServer: { stats: { errors: true } },405 }),406 Object.assign({}, argv, { color: true }),407 { port: 8080 }408 );409 expect(config).toMatchSnapshot();410 });411 it('lazy option', () => {412 const config = createConfig(413 webpackConfig,414 Object.assign({}, argv, { lazy: true }),415 { port: 8080 }416 );417 expect(config).toMatchSnapshot();418 });419 it('lazy option (in devServer config)', () => {420 const config = createConfig(421 Object.assign({}, webpackConfig, {422 devServer: { lazy: true },423 }),424 argv,425 { port: 8080 }426 );427 expect(config).toMatchSnapshot();428 });429 it('info option', () => {430 const config = createConfig(431 webpackConfig,432 Object.assign({}, argv, { info: false }),433 { port: 8080 }434 );435 expect(config).toMatchSnapshot();436 });437 it('info option (in devServer config)', () => {438 const config = createConfig(439 Object.assign({}, webpackConfig, {440 devServer: { noInfo: false },441 }),442 argv,443 { port: 8080 }444 );445 expect(config).toMatchSnapshot();446 });447 it('mimeTypes option', () => {448 const config = createConfig(449 Object.assign({}, webpackConfig, {450 devServer: { mimeTypes: { 'text/html': ['phtml'] } },451 }),452 argv,453 { port: 8080 }454 );455 expect(config).toMatchSnapshot();456 });457 it('mimeTypes option - with force', () => {458 const config = createConfig(459 Object.assign({}, webpackConfig, {460 devServer: {461 mimeTypes: { typeMap: { 'text/html': ['phtml'] }, force: true },462 },463 }),464 argv,465 { port: 8080 }466 );467 expect(config).toMatchSnapshot();468 });469 it('quiet option', () => {470 const config = createConfig(471 webpackConfig,472 Object.assign({}, argv, { quiet: true }),473 { port: 8080 }474 );475 expect(config).toMatchSnapshot();476 });477 it('quiet option (in devServer config)', () => {478 const config = createConfig(479 Object.assign({}, webpackConfig, {480 devServer: { quiet: true },481 }),482 argv,483 { port: 8080 }484 );485 expect(config).toMatchSnapshot();486 });487 it('https option', () => {488 const config = createConfig(489 webpackConfig,490 Object.assign({}, argv, { https: true }),491 { port: 8080 }492 );493 expect(config).toMatchSnapshot();494 });495 it('https option (in devServer config)', () => {496 const config = createConfig(497 Object.assign({}, webpackConfig, {498 devServer: { https: true },499 }),500 argv,501 { port: 8080 }502 );503 expect(config).toMatchSnapshot();504 });505 it('http2 option', () => {506 const config = createConfig(507 webpackConfig,508 Object.assign({}, argv, { https: true, http2: true }),509 { port: 8080 }510 );511 expect(config).toMatchSnapshot();512 });513 it('http2 option (in devServer config)', () => {514 const config = createConfig(515 Object.assign({}, webpackConfig, {516 devServer: { https: true, http2: true },517 }),518 argv,519 { port: 8080 }520 );521 expect(config).toMatchSnapshot();522 });523 it('key option', () => {524 const config = createConfig(525 webpackConfig,526 Object.assign({}, argv, { https: true, key: '/path/to/server.key' }),527 { port: 8080 }528 );529 expect(config).toMatchSnapshot();530 });531 it('key option (in devServer config)', () => {532 const config = createConfig(533 Object.assign({}, webpackConfig, {534 devServer: { https: true, key: '/path/to/server.key' },535 }),536 argv,537 { port: 8080 }538 );539 expect(config).toMatchSnapshot();540 });541 it('cert option', () => {542 const config = createConfig(543 webpackConfig,544 Object.assign({}, argv, { https: true, cert: '/path/to/server.crt' }),545 { port: 8080 }546 );547 expect(config).toMatchSnapshot();548 });549 it('cert option (in devServer config)', () => {550 const config = createConfig(551 Object.assign({}, webpackConfig, {552 devServer: { https: true, cert: '/path/to/server.crt' },553 }),554 argv,555 { port: 8080 }556 );557 expect(config).toMatchSnapshot();558 });559 it('cacert option', () => {560 const config = createConfig(561 webpackConfig,562 Object.assign({}, argv, { https: true, cacert: '/path/to/ca.pem' }),563 { port: 8080 }564 );565 expect(config).toMatchSnapshot();566 });567 it('cacert option (in devServer config)', () => {568 const config = createConfig(569 Object.assign({}, webpackConfig, {570 // TODO rename `ca` to `cacert` for `v4` to avoid difference between CLI and configuration571 devServer: { https: true, ca: '/path/to/ca.pem' },572 }),573 argv,574 { port: 8080 }575 );576 expect(config).toMatchSnapshot();577 });578 it('pfx option', () => {579 const config = createConfig(580 webpackConfig,581 Object.assign({}, argv, { https: true, pfx: '/path/to/file.pfx' }),582 { port: 8080 }583 );584 expect(config).toMatchSnapshot();585 });586 it('pfx option (in devServer config)', () => {587 const config = createConfig(588 Object.assign({}, webpackConfig, {589 devServer: { https: true, pfx: '/path/to/file.pfx' },590 }),591 argv,592 { port: 8080 }593 );594 expect(config).toMatchSnapshot();595 });596 it('pfxPassphrase option', () => {597 const config = createConfig(598 webpackConfig,599 Object.assign({}, argv, { pfxPassphrase: 'passphrase' }),600 { port: 8080 }601 );602 expect(config).toMatchSnapshot();603 });604 it('https option (in devServer config)', () => {605 const config = createConfig(606 Object.assign({}, webpackConfig, {607 devServer: { pfxPassphrase: 'passphrase' },608 }),609 argv,610 { port: 8080 }611 );612 expect(config).toMatchSnapshot();613 });614 it('inline option', () => {615 const config = createConfig(616 webpackConfig,617 Object.assign({}, argv, { inline: false }),618 { port: 8080 }619 );620 expect(config).toMatchSnapshot();621 });622 it('inline option (in devServer config)', () => {623 const config = createConfig(624 Object.assign({}, webpackConfig, {625 devServer: { inline: false },626 }),627 argv,628 { port: 8080 }629 );630 expect(config).toMatchSnapshot();631 });632 it('historyApiFallback option', () => {633 const config = createConfig(634 webpackConfig,635 Object.assign({}, argv, { historyApiFallback: true }),636 { port: 8080 }637 );638 expect(config).toMatchSnapshot();639 });640 it('historyApiFallback option (in devServer config)', () => {641 const config = createConfig(642 Object.assign({}, webpackConfig, {643 devServer: { historyApiFallback: true },644 }),645 argv,646 { port: 8080 }647 );648 expect(config).toMatchSnapshot();649 });650 it('compress option', () => {651 const config = createConfig(652 webpackConfig,653 Object.assign({}, argv, { compress: true }),654 { port: 8080 }655 );656 expect(config).toMatchSnapshot();657 });658 it('compress option (in devServer config)', () => {659 const config = createConfig(660 Object.assign({}, webpackConfig, {661 devServer: { compress: true },662 }),663 argv,664 { port: 8080 }665 );666 expect(config).toMatchSnapshot();667 });668 it('disableHostCheck option', () => {669 const config = createConfig(670 webpackConfig,671 Object.assign({}, argv, { disableHostCheck: true }),672 { port: 8080 }673 );674 expect(config).toMatchSnapshot();675 });676 it('disableHostCheck option (in devServer config)', () => {677 const config = createConfig(678 Object.assign({}, webpackConfig, {679 devServer: { disableHostCheck: true },680 }),681 argv,682 { port: 8080 }683 );684 expect(config).toMatchSnapshot();685 });686 it('open option (boolean)', () => {687 const config = createConfig(688 webpackConfig,689 Object.assign({}, argv, { open: true }),690 { port: 8080 }691 );692 expect(config).toMatchSnapshot();693 });694 it('open option (boolean) (in devServer config)', () => {695 const config = createConfig(696 Object.assign({}, webpackConfig, {697 devServer: { open: true },698 }),699 argv,700 { port: 8080 }701 );702 expect(config).toMatchSnapshot();703 });704 it('open option (browser)', () => {705 const config = createConfig(706 webpackConfig,707 Object.assign({}, argv, { open: 'Google Chrome' }),708 { port: 8080 }709 );710 expect(config).toMatchSnapshot();711 });712 it('openPage option', () => {713 const config = createConfig(714 webpackConfig,715 Object.assign({}, argv, { openPage: '/different/page' }),716 { port: 8080 }717 );718 expect(config).toMatchSnapshot();719 });720 it('openPage option (in devServer config)', () => {721 const config = createConfig(722 Object.assign({}, webpackConfig, {723 devServer: { open: true, openPage: '/different/page' },724 }),725 argv,726 { port: 8080 }727 );728 expect(config).toMatchSnapshot();729 });730 it('openPage multiple option (in devServer config)', () => {731 const config = createConfig(732 Object.assign({}, webpackConfig, {733 devServer: {734 open: true,735 openPage: ['/different/page', '/different/page2'],736 },737 }),738 argv,739 { port: 8080 }740 );741 expect(config).toMatchSnapshot();742 });743 it('useLocalIp option', () => {744 const config = createConfig(745 webpackConfig,746 Object.assign({}, argv, { useLocalIp: true }),747 { port: 8080 }748 );749 expect(config).toMatchSnapshot();750 });751 it('useLocalIp option (in devServer config)', () => {752 const config = createConfig(753 Object.assign({}, webpackConfig, {754 devServer: { useLocalIp: true },755 }),756 argv,757 { port: 8080 }758 );759 expect(config).toMatchSnapshot();760 });761 it('port option (same)', () => {762 const config = createConfig(763 webpackConfig,764 Object.assign({}, argv, { port: 9090 }),765 { port: 9090 }766 );767 expect(config).toMatchSnapshot();768 });769 it('port option (same) (string)', () => {770 const config = createConfig(771 webpackConfig,772 Object.assign({}, argv, { port: '9090' }),773 { port: '9090' }774 );775 expect(config).toMatchSnapshot();776 });777 it('port option (same) (null)', () => {778 const config = createConfig(779 webpackConfig,780 Object.assign({}, argv, { port: null }),781 { port: null }782 );783 expect(config).toMatchSnapshot();784 });785 it('port option (same) (undefined)', () => {786 const config = createConfig(787 webpackConfig,788 // eslint-disable-next-line no-undefined789 Object.assign({}, argv, { port: undefined }),790 // eslint-disable-next-line no-undefined791 { port: undefined }792 );793 expect(config).toMatchSnapshot();794 });795 it('port option (difference)', () => {796 const config = createConfig(797 webpackConfig,798 Object.assign({}, argv, { port: 7070 }),799 { port: 8080 }800 );801 expect(config).toMatchSnapshot();802 });803 it('use webpack stats', () => {804 expect(805 createConfig(webpackConfigNoStats, argv, { port: 8080 })806 ).toMatchSnapshot();807 expect(webpackConfigNoStats).toMatchSnapshot();808 });809 it('onListening option', () => {810 const config = createConfig(811 Object.assign({}, webpackConfig, {812 devServer: { onListening: () => {} },813 }),814 argv,815 { port: 8080 }816 );817 expect(config).toMatchSnapshot();818 });819 it('overlay option', () => {820 const config = createConfig(821 webpackConfig,822 Object.assign({}, argv, {823 overlay: true,824 }),825 { port: 8080 }826 );827 expect(config).toMatchSnapshot();828 });829 it('overlay option (in devServer config)', () => {830 const config = createConfig(831 Object.assign({}, webpackConfig, {832 devServer: { overlay: true },833 }),834 argv,835 { port: 8080 }836 );837 expect(config).toMatchSnapshot();838 });839 it('sockHost option', () => {840 const config = createConfig(841 webpackConfig,842 Object.assign({}, argv, {843 sockHost: true,844 }),845 { port: 8080 }846 );847 expect(config).toMatchSnapshot();848 });849 it('sockPath option', () => {850 const config = createConfig(851 webpackConfig,852 Object.assign({}, argv, {853 sockPath: 'path',854 }),855 { port: 8080 }856 );857 expect(config).toMatchSnapshot();858 });859 it('sockPort option', () => {860 const config = createConfig(861 webpackConfig,862 Object.assign({}, argv, {863 sockPort: 'port',864 }),865 { port: 8080 }866 );867 expect(config).toMatchSnapshot();868 });869 it('liveReload option', () => {870 const config = createConfig(871 webpackConfig,872 Object.assign({}, argv, {873 liveReload: false,874 }),875 { port: 8080 }876 );877 expect(config).toMatchSnapshot();878 });879 it('profile option', () => {880 const config = createConfig(881 webpackConfig,882 Object.assign({}, argv, {883 profile: 'profile',884 }),885 { port: 8080 }886 );887 expect(config).toMatchSnapshot();888 });...
global.js
Source:global.js
1'use strict';2var domain = 'test.lh'; // домен ÑайÑа3var ab = ''; // a, b или ниÑего4var ab_dir = '/2/'; // диÑекÑоÑÐ¸Ñ Ð´Ð»Ñ AB-ÑеÑÑа5// Depends6var path = require('path');7var glob = require('glob');8var webpack = require('webpack');9var Manifest = require('manifest-revision-webpack-plugin');10var TextPlugin = require('extract-text-webpack-plugin');11var autoprefixer = require('autoprefixer');12var HtmlPlugin = require('html-webpack-plugin');13var AssetInjectHtmlWebpackPlugin = require('../../app/modules/asset-inject-html-webpack-plugin');14/**15 * Global webpack config16 * @param {[type]} _path [description]17 * @return {[type]} [description]18 */19module.exports = function(_path, ENV) {20 // define local variables21 var dependencies = Object.keys(require(_path + '/package').dependencies);22 var rootAssetPath = _path + 'app';23 // return objecy24 var webpackConfig = {25 // ТоÑки вÑ
ода26 entry: {27 application: _path + '/app/app.js',28 vendors: dependencies29 },30 // Ð¤Ð°Ð¹Ð»Ñ Ð²Ñвода31 output: {32 path: path.join(_path, 'dist'),33 chunkFilename: '[id].bundle.[chunkhash].js',34 publicPath: ab == 'b' ? ab_dir : '/'35 },36 // resolves modules37 resolve: {38 extensions: ['', '.js'],39 modulesDirectories: ['node_modules'],40 alias: {41 _svg: path.join(_path, 'app', 'assets', 'svg'),42 _fonts: path.join(_path, 'app', 'assets', 'fonts'),43 _modules: path.join(_path, 'app', 'modules'),44 _images: path.join(_path, 'app', 'assets', 'images'),45 _stylesheets: path.join(_path, 'app', 'assets', 'stylesheets'),46 _templates: path.join(_path, 'app', 'assets', 'templates')47 }48 },49 // modules resolvers50 module: {51 loaders: [52 {53 test: /\.html$/,54 loaders: [55 'html-loader?attrs=source:srcset link:href img:src img:data-src picture:data-src div:data-src a:data-mfp-src source:data-original div:data-mfp-src img:data-original img:scrset source:src img:data-lazy image:href li:data-src div:data-src&interpolate=1',56 'purifycss-loader'57 ]58 },59 {60 loader: 'babel',61 test: /\.js$/,62 query: {63 presets: ['es2015'],64 ignore: ['node_modules', 'bower_components']65 }66 }67 ]68 },69 // post css70 postcss: [autoprefixer({ browsers: ['last 5 versions'] })],71 sassLoader: {72 outputStyle: 'expanded',73 sourceMap: 'true'74 },75 // load plugins76 plugins: [77 new webpack.optimize.CommonsChunkPlugin(78 'vendors',79 'assets/js/vendors.[hash].js'80 ),81 new TextPlugin('assets/css/[name].[chunkhash].css'),82 new Manifest(path.join(_path + '/config', 'manifest.json'), {83 rootAssetPath: rootAssetPath,84 ignorePaths: ['.DS_Store']85 }),86 new webpack.ProvidePlugin({87 $: 'jquery',88 jQuery: 'jquery',89 'window.jQuery': 'jquery'90 }),91 // new AssetInjectHtmlWebpackPlugin({92 // texts: {93 // ab: ENV == "production" && ab == "a" ? "<?php if((!isset($_COOKIE['AB']) && rand(0, 1)) || (isset($_COOKIE['AB']) && $_COOKIE['AB'] == 2)) { SetCookie('AB','2',time()+3600*24*365); $ref = $_SERVER['QUERY_STRING']; if ($ref != '') $ref = '?' . $ref; header('HTTP/1.1 301 Moved Permanently'); header('Location:http://"+domain+ab_dir+"' . $ref); exit(); }else{ SetCookie('AB','1',time()+3600*24*365); } ?>" : " ",94 // utm: ENV == 'production' ? '<?=!empty($_GET["utm_campaign"])?str_replace(array("_poisk", "_kms", "-poisk_g", "-kms"), "", $_GET["utm_campaign"]):""?>' : ' '95 // }96 // }),97 new webpack.DllReferencePlugin({98 context: __dirname,99 manifest: require('../../app/vendor/vendor-manifest.json')100 })101 ]102 };103 if (ENV == 'production') {104 // webpackConfig.devtool = "nosources-source-map";105 webpackConfig.devtool = 'source-map';106 webpackConfig.plugins[webpackConfig.plugins.length] = new TextPlugin(107 'assets/css/[name].[chunkhash].css'108 );109 webpackConfig.module.loaders[webpackConfig.module.loaders.length] = {110 test: /\.scss$/,111 loader: TextPlugin.extract('style', 'css!sass!')112 };113 webpackConfig.module.loaders[webpackConfig.module.loaders.length] = {114 test: /\.(css|ico|png|webp)$/i,115 loaders: [116 'url-loader?limit=4096&context=' +117 rootAssetPath +118 '&name=assets/static/[ext]/[name]_[hash].[ext]'119 ]120 };121 webpackConfig.module.loaders[webpackConfig.module.loaders.length] = {122 test: /\.woff(2)?(\?[a-z0-9=&.]+)?$/i,123 loaders: [124 'url-loader?limit=4096&context=' +125 rootAssetPath +126 '&name=assets/static/[ext]/[name]_[hash].[ext]'127 ]128 };129 webpackConfig.module.loaders[webpackConfig.module.loaders.length] = {130 test: /\.(ttf|eot)(\?[a-z0-9=&.]+)?$/i,131 loaders: [132 'url-loader?limit=4096&context=' +133 rootAssetPath +134 '&name=assets/static/[ext]/[name]_[hash].[ext]'135 ]136 };137 webpackConfig.module.loaders[webpackConfig.module.loaders.length] = {138 test: /\.svg(\?[a-z0-9=&.]+)?$/i,139 loaders: [140 'url-loader?limit=4096&context=' +141 rootAssetPath +142 '&name=assets/static/[ext]/[name]_[hash].[ext]',143 'image-webpack-loader?{optimizationLevel: 8, interlaced: false, pngquant:{quality: "80-90", speed: 4}, mozjpeg: {quality: 80}}'144 ]145 };146 webpackConfig.module.loaders[webpackConfig.module.loaders.length] = {147 test: /\.(gif|jpe?g)$/i,148 loaders: [149 'url-loader?limit=4096&context=' +150 rootAssetPath +151 '&name=assets/static/[ext]/[name]_[hash].[ext]',152 'image-webpack-loader?{optimizationLevel: 8, interlaced: false, pngquant:{quality: "80-90", speed: 4}, mozjpeg: {quality: 80}}'153 ]154 };155 } else {156 webpackConfig.cache = true;157 webpackConfig.devtool = 'eval';158 webpackConfig.module.loaders[webpackConfig.module.loaders.length] = {159 test: /\.scss$/,160 loaders: ['style', 'css?sourceMap', 'sass?sourceMap']161 };162 webpackConfig.module.loaders[webpackConfig.module.loaders.length] = {163 test: /\.(css|ico|png|jpg|jpeg|gif|webp)$/i,164 loaders: [165 'url-loader?limit=4096&context=' +166 rootAssetPath +167 '&name=assets/static/[ext]/[name]_[hash].[ext]'168 ]169 };170 webpackConfig.module.loaders[webpackConfig.module.loaders.length] = {171 test: /\.woff(2)?(\?[a-z0-9=&.]+)?$/i,172 loaders: [173 'url-loader?limit=4096&context=' +174 rootAssetPath +175 '&name=assets/static/[ext]/[name]_[hash].[ext]'176 ]177 };178 webpackConfig.module.loaders[webpackConfig.module.loaders.length] = {179 test: /\.(ttf|eot|svg)(\?[a-z0-9=&.]+)?$/i,180 loaders: [181 'url-loader?limit=4096&context=' +182 rootAssetPath +183 '&name=assets/static/[ext]/[name]_[hash].[ext]'184 ]185 };186 webpackConfig.plugins[187 webpackConfig.plugins.length188 ] = new webpack.HotModuleReplacementPlugin();189 webpackConfig.output.publicPath = 'http://localhost:88/';190 }191 var templates = glob.sync(_path + '/app/assets/templates/layouts/*.html');192 for (var temp in templates) {193 var template = templates[temp].replace(194 path195 .join(_path, 'app', 'assets', 'templates', 'layouts/')196 .replace(/\\/g, '/'),197 ''198 );199 if(template == 'index.html'){200 var destination = template;201 }else{202 var destination = (template.replace('.html', ''))+'/index.html';203 }204 webpackConfig.plugins[webpackConfig.plugins.length] = new HtmlPlugin({205 title: 'Landing',206 chunks: ['application', 'vendors'],207 filename: destination,208 template: path.join(209 _path,210 'app',211 'assets',212 'templates',213 'layouts',214 template215 )216 });217 }218 return webpackConfig;...
merge-webpack.js
Source:merge-webpack.js
1'use strict';2const merge = require('webpack-merge');3const tryRequire = require('try-require');4const { logger } = require('@micro-app/core');5// éå é项é
ç½®6function extralCustomConfig(webpackConfig = {}, extralConfig) {7 const disabled = extralConfig.disabled || extralConfig.disable;8 if (disabled) { // disabled entry9 delete webpackConfig.entry;10 delete webpackConfig.plugins;11 Object.keys(webpackConfig.plugin).forEach(key => {12 if (key.indexOf('-html') > 0) {13 delete webpackConfig.plugin[key];14 }15 });16 }17 return webpackConfig;18}19function removeUselessPlugins(webpackConfig) {20 const plugins = webpackConfig.plugins;21 if (plugins && Array.isArray(plugins)) {22 webpackConfig.plugins = plugins.filter(item => {23 const constru = item.constructor;24 if (constru && constru.name && constru.name !== 'Function') {25 return true;26 }27 return false;28 });29 }30 return webpackConfig;31}32// 修补33function patchWebpack(microConfig) {34 if (!microConfig) {35 return {};36 }37 const webpackConfig = {};38 if (!webpackConfig.resolve) {39 webpackConfig.resolve = {};40 }41 if (!webpackConfig.resolve.modules || !Array.isArray(webpackConfig.resolve.modules)) {42 webpackConfig.resolve.modules = [];43 }44 if (microConfig.nodeModules && !webpackConfig.resolve.modules.includes(microConfig.nodeModules)) {45 webpackConfig.resolve.modules.push(microConfig.nodeModules);46 }47 if (!webpackConfig.entry) {48 webpackConfig.entry = {};49 }50 Object.assign(webpackConfig.entry, microConfig.entry);51 return injectWebpackPlugins(webpackConfig, microConfig);52}53function injectWebpackPlugins(webpackConfig = {}, microConfig) {54 if (!microConfig) {55 return webpackConfig;56 }57 const aliasName = microConfig.aliasName;58 if (!webpackConfig.plugin) {59 webpackConfig.plugin = {};60 }61 const HtmlWebpackPlugin = tryRequire('html-webpack-plugin');62 if (Array.isArray(microConfig.htmls) && HtmlWebpackPlugin) {63 const _htmls = microConfig.htmls;64 _htmls.forEach((item, index) => {65 const id = item.id || index;66 try {67 webpackConfig.plugin[id ? `${aliasName}-html-${id}` : `${aliasName}-html`] = {68 plugin: HtmlWebpackPlugin,69 args: [ item ],70 };71 } catch (error) {72 logger.warn(`[ htmls error] id: ${id}, options: ${JSON.stringify(item, false, 4)}`);73 throw error;74 }75 });76 } else if (!HtmlWebpackPlugin) {77 logger.warn('not found "html-webpack-plugin"');78 }79 const webpack = tryRequire('webpack');80 if (Array.isArray(microConfig.dlls) && webpack) {81 const _dlls = microConfig.dlls;82 _dlls.forEach((item, index) => {83 const id = item.id || index;84 try {85 webpackConfig.plugin[id ? `${aliasName}-dll-${id}` : `${aliasName}-dll`] = {86 plugin: webpack.DllReferencePlugin,87 args: [{88 context: item.context,89 manifest: require(item.manifest),90 }],91 };92 const AddAssetHtmlPlugin = tryRequire('add-asset-html-webpack-plugin');93 if (!AddAssetHtmlPlugin) {94 logger.warn('not found "add-asset-html-webpack-plugin"');95 } else {96 webpackConfig.plugin[id ? `${aliasName}-add-asset-html-${id}` : `${aliasName}-add-asset-html`] = {97 plugin: AddAssetHtmlPlugin,98 args: [ item ],99 };100 }101 } catch (error) {102 logger.warn(`[ dlls error] id: ${id}, options: ${JSON.stringify(item, false, 4)}`);103 throw error;104 }105 });106 } else if (!webpack) {107 logger.warn('not found "webpack"');108 }109 return removeUselessPlugins(webpackConfig);110}111// inject alias112function injectWebpackAlias(webpackConfig, microConfig = {}) {113 if (!webpackConfig) {114 return;115 }116 if (!webpackConfig.resolve) {117 webpackConfig.resolve = {};118 }119 if (!webpackConfig.resolve.alias) {120 webpackConfig.resolve.alias = {};121 }122 Object.assign(webpackConfig.resolve.alias, microConfig.resolveAlias);123 return webpackConfig;124}125// å»éå¤126function uniqArray(webpackConfig, microConfig = {}) {127 if (!webpackConfig) {128 return null;129 }130 if (webpackConfig.resolve && webpackConfig.resolve.modules && Array.isArray(webpackConfig.resolve.modules)) {131 const resolveModules = [ ...new Set(webpackConfig.resolve.modules) ];132 if (resolveModules.length > 0 && microConfig.nodeModules === resolveModules[resolveModules.length - 1]) {133 // å°æåä¸ä¸ªæ¾å¨ç¬¬ä¸ä½134 resolveModules.unshift(resolveModules.pop());135 }136 webpackConfig.resolve.modules = resolveModules;137 }138 if (webpackConfig.entry) {139 const entry = webpackConfig.entry;140 if (typeof entry === 'object') {141 Object.keys(entry).forEach(key => {142 if (Array.isArray(entry[key])) {143 entry[key] = [ ...new Set(entry[key]) ];144 }145 });146 }147 }148 return webpackConfig;149}150function webpackMerge(webpackConfig = {}, opts = {}) {151 let config = patchWebpack(opts.config);152 const names = opts.micros;153 if (!names || names.length <= 0) {154 // inject self155 injectWebpackAlias(config, opts.config);156 return merge.smart(webpackConfig, config);157 }158 // extra config159 const microsExtraConfig = opts.microsExtraConfig || {};160 const microConfigs = [];161 names.forEach(key => {162 const microConfig = opts.microsConfig[key];163 if (microConfig) {164 const wc = patchWebpack(microConfig);165 // inject166 injectWebpackAlias(wc, microConfig);167 const extralConfig = microsExtraConfig[key];168 if (extralConfig) {169 extralCustomConfig(wc, extralConfig);170 }171 microConfigs.push(wc);172 }173 });174 if (microConfigs.length) {175 config = merge.smart(webpackConfig, ...microConfigs, config);176 }177 // inject self178 injectWebpackAlias(config, opts.config);179 return uniqArray(config, opts.config);180}181module.exports = webpackMerge;...
Using AI Code Generation
1const path = require('path');2const rootConfig = require('storybook-root-config');3const webpackConfig = rootConfig.webpackConfig;4module.exports = {5 stories: ['../src/**/*.stories.@(js|mdx)'],6 webpackFinal: (config) => {7 const rootWebpackConfig = webpackConfig({8 configDir: path.resolve(__dirname, '../'),9 });10 return {11 module: {12 },13 };14 },15};16const rootConfig = require('storybook-root-config');17const webpackConfig = rootConfig.webpackConfig;18module.exports = {19 webpackFinal: (config) => {20 const rootWebpackConfig = webpackConfig({21 configDir: path.resolve(__dirname, '../'),22 });23 return {24 module: {25 },26 };27 },28};29const path = require('path');30const rootConfig = require('storybook-root-config');31const webpackConfig = rootConfig.webpackConfig;32module.exports = {33 stories: ['../src/**/*.stories.@(js|mdx)'],34 webpackFinal: (config) => {35 const rootWebpackConfig = webpackConfig({36 configDir: path.resolve(__dirname, '../'),37 });38 return {39 module: {40 },41 };42 },43};44const path = require('path');45const rootConfig = require('storybook-root-config');46const webpackConfig = rootConfig.webpackConfig;47module.exports = (baseConfig, env, defaultConfig) => {
Using AI Code Generation
1const path = require('path');2const { webpackConfig } = require('storybook-root-config');3module.exports = async ({ config, mode }) => {4 return webpackConfig(config, mode, {5 root: path.resolve(__dirname, '..'),6 });7};8module.exports = {9 stories: ['../packages/**/*.stories.@(js|jsx|ts|tsx|mdx)'],10 webpackFinal: require('../test.js'),11};12import { addDecorator } from '@storybook/react';13import { withA11y } from '@storybook/addon-a11y';14import { withRoot } from 'storybook-root-config';15addDecorator(withA11y);16addDecorator(withRoot);17import { withA11y } from '@storybook/addon-a11y';18import { withRoot } from 'storybook-root-config';19export const decorators = [withA11y, withRoot];
Using AI Code Generation
1const path = require('path');2const rootConfig = require('../../storybook-root-config');3module.exports = rootConfig.webpackConfig({4 defaultConfig: {5 module: {6 {7 {8 options: {9 },10 },11 },12 },13 resolve: {14 alias: {15 },16 },17 },18});19const path = require('path');20module.exports = {21 webpackConfig: ({ configDir, configType, defaultConfig }) => {22 const config = {23 module: {24 {25 {26 options: {27 },28 },29 {30 options: {31 },32 },33 include: path.resolve(__dirname, '../'),34 },35 },36 };37 return config;38 },39};
Using AI Code Generation
1const path = require('path');2const { webpackConfig } = require('@nrwl/storybook');3const { addWebpackAlias } = require('@nrwl/storybook');4module.exports = (storybookBaseConfig, configType) => {5 const config = webpackConfig(storybookBaseConfig, configType);6 config.resolve.alias = {7 '@myorg/ui': path.resolve(__dirname, '../dist/libs/ui/src/index.js'),8 };9 return config;10};11{12 "compilerOptions": {13 "paths": {14 }15 },16}17{18 "compilerOptions": {19 "paths": {20 }21 },22}23{24 "compilerOptions": {25 "paths": {26 }27 },28}29{30 "compilerOptions": {31 "paths": {32 }33 },34}35{36 "compilerOptions": {37 "paths": {38 }39 },40}41{
Using AI Code Generation
1const path = require('path');2const rootConfig = require('../../.storybook/storybook-root-config');3const webpackConfig = rootConfig.webpackConfig;4module.exports = {5 entry: {6 test: path.resolve(__dirname, '../src/test.js'),7 },8 output: {9 path: path.resolve(__dirname, '../dist'),10 },11};
Using AI Code Generation
1const path = require('path');2const { getWebpackConfig } = require('@storybook/core/server');3const webpackConfig = getWebpackConfig('WEBPACK_CONFIG', 'PRODUCTION');4const customConfig = {5 module: {6 {7 include: path.resolve(__dirname, '../'),8 },9 },10};11module.exports = { ...webpackConfig, ...customConfig };12import { configure } from '@storybook/react';13import { setOptions } from '@storybook/addon-options';14import { setDefaults } from '@storybook/addon-info';15import '../src/index.scss';16setOptions({
Using AI Code Generation
1const path = require('path');2const { createWebpackConfig } = require('./.storybook/storybook-root-config');3module.exports = async ({ config, mode }) => {4 const webpackConfig = await createWebpackConfig({ config, mode });5 return webpackConfig;6};7const path = require('path');8const { createWebpackConfig } = require('@storybook/react/dist/server/config/defaults/webpack.config.js');9module.exports = async ({ config, mode }) => {10 const webpackConfig = await createWebpackConfig({ config, mode });11 return webpackConfig;12};
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!