当前位置: 首页>>代码示例>>Python>>正文


Python compiler.webpack函数代码示例

本文整理汇总了Python中webpack.compiler.webpack函数的典型用法代码示例。如果您正苦于以下问题:Python webpack函数的具体用法?Python webpack怎么用?Python webpack使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了webpack函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_config_file_can_be_watched_to_rebuild_the_bundle

    def test_config_file_can_be_watched_to_rebuild_the_bundle(self):
        self.assertIn('./entry1.js', WATCHED_CONFIG_CONTENT)
        self.assertEqual(read_file(PATH_TO_WATCHED_CONFIG), WATCHED_CONFIG_CONTENT)

        bundle = webpack(PATH_TO_WATCHED_CONFIG, watch_config=True)

        assets = bundle.get_assets()
        self.assertTrue(len(assets), 1)
        contents = read_file(assets[0]['path'])
        self.assertIn('__DJANGO_WEBPACK_WATCH_CONFIG_ONE__', contents)
        self.assertNotIn('__DJANGO_WEBPACK_WATCH_CONFIG_TWO__', contents)

        time.sleep(WATCH_WAIT)
        changed_config = WATCHED_CONFIG_CONTENT.replace('./entry1.js', './entry2.js')
        self.assertNotIn('./entry1.js', changed_config)
        write_file(PATH_TO_WATCHED_CONFIG, changed_config)
        time.sleep(WATCH_WAIT)

        bundle = webpack(PATH_TO_WATCHED_CONFIG, watch_config=True)

        assets = bundle.get_assets()
        self.assertTrue(len(assets), 1)
        contents = read_file(assets[0]['path'])
        self.assertNotIn('__DJANGO_WEBPACK_WATCH_CONFIG_ONE__', contents)
        self.assertIn('__DJANGO_WEBPACK_WATCH_CONFIG_TWO__', contents)
开发者ID:infrastructure-wixproducts,项目名称:python-webpack,代码行数:25,代码来源:test_watching.py

示例2: test_a_manifest_can_be_generated_with_multiple_contexts

    def test_a_manifest_can_be_generated_with_multiple_contexts(self):
        manifest = generate_manifest({
            ConfigFiles.BASIC_CONFIG: (
                {'foo': 'bar'},
            ),
            ConfigFiles.LIBRARY_CONFIG: (
                {'foo': 'bar'},
                {'woz': 'woo'},
            ),
        })
        self.assertIsInstance(manifest, dict)
        self.assertEqual(len(manifest.keys()), 3)

        key1 = generate_key(ConfigFiles.BASIC_CONFIG, {'foo': 'bar'})
        self.assertIn(key1, manifest)
        entry1 = manifest[key1]
        bundle1 = webpack(ConfigFiles.BASIC_CONFIG, context={'foo': 'bar'})
        self.assertEqual(entry1, bundle1.data)

        key2 = generate_key(ConfigFiles.LIBRARY_CONFIG, {'foo': 'bar'})
        self.assertIn(key2, manifest)
        entry2 = manifest[key2]
        bundle2 = webpack(ConfigFiles.LIBRARY_CONFIG, context={'foo': 'bar'})
        self.assertEqual(entry2, bundle2.data)

        key3 = generate_key(ConfigFiles.LIBRARY_CONFIG, {'woz': 'woo'})
        self.assertIn(key3, manifest)
        entry3 = manifest[key3]
        bundle3 = webpack(ConfigFiles.LIBRARY_CONFIG, context={'woz': 'woo'})
        self.assertEqual(entry3, bundle3.data)
开发者ID:appelstroop,项目名称:python-webpack,代码行数:30,代码来源:test_manifest.py

示例3: test_can_render_a_webpack_bundle

 def test_can_render_a_webpack_bundle(self):
     bundle = webpack(ConfigFiles.BASIC_CONFIG)
     urls = bundle.get_urls()
     self.assertTrue(len(urls['main']['js']), 1)
     rendered = bundle.render_js()
     self.assertIn(urls['main']['js'][0], rendered)
     self.assertEqual(rendered, '<script src="' + urls['main']['js'][0] + '"></script>')
开发者ID:appelstroop,项目名称:python-webpack,代码行数:7,代码来源:test_bundles.py

示例4: index

def index():
    config_file = os.path.join(BASE_DIR, 'example.webpack.js')

    component = os.path.join(BASE_DIR, 'app', 'CommentBox.jsx')

    props = {
        'comments': comments,
        'url': '/comment/',
    }

    rendered = render_component(component, props)

    webpack_context = {
        'component': component,
        'props_var': 'window.mountProps',
        'container': 'mount-container',
    }

    bundle = webpack(config_file, context=webpack_context)

    return render_template(
        'index.html',
        bundle=bundle,
        webpack_context=webpack_context,
        rendered=rendered,
    )
开发者ID:bluebirdlboro,项目名称:python-react,代码行数:26,代码来源:example.py

示例5: bundle_component

def bundle_component(path, client_path, translate=None, path_to_react=None, devtool=None, client=False):
    if not os.path.isabs(path):
        abs_path = staticfiles.find(path)
        if not abs_path:
            raise ComponentSourceFileNotFound(path)
        path = abs_path

    if not os.path.exists(path):
        raise ComponentSourceFileNotFound(path)

    if not os.path.isabs(client_path):
        abs_client_path = staticfiles.find(client_path)
        if not abs_client_path:
            raise ComponentSourceFileNotFound(client_path)
        client_path = abs_client_path

    if not os.path.exists(client_path):
        raise ComponentSourceFileNotFound(client_path)

    config = generate_config_for_component(path, client_path, translate=translate, path_to_react=path_to_react, devtool=devtool)

    config_file = generate_config_file(config)

    var = generate_var_from_path(client_path)

    path_to_config_file = get_path_to_config_file(config_file, prefix=var + '.')

    return webpack(path_to_config_file)
开发者ID:HorizonXP,项目名称:python-react-router,代码行数:28,代码来源:bundle.py

示例6: test_can_render_a_bundle_with_multiple_entries

 def test_can_render_a_bundle_with_multiple_entries(self):
     bundle = webpack(PATH_TO_MULTIPLE_ENTRY_CONFIG)
     urls = bundle.get_urls()
     self.assertTrue(len(urls), 1)
     rendered = bundle.render()
     self.assertIn(urls[0], rendered)
     self.assertEqual(rendered, '<script src="' + urls[0] + '"></script>')
开发者ID:infrastructure-wixproducts,项目名称:python-webpack,代码行数:7,代码来源:test_bundles.py

示例7: test_can_render_a_webpack_bundle

 def test_can_render_a_webpack_bundle(self):
     bundle = webpack(PATH_TO_BASIC_CONFIG)
     urls = bundle.get_urls()
     self.assertTrue(len(urls), 1)
     rendered = bundle.render()
     self.assertIn(urls[0], rendered)
     self.assertEqual(rendered, '<script src="' + urls[0] + '"></script>')
开发者ID:infrastructure-wixproducts,项目名称:python-webpack,代码行数:7,代码来源:test_bundles.py

示例8: test_can_render_a_bundle_with_multiple_entry_points

 def test_can_render_a_bundle_with_multiple_entry_points(self):
     bundle = webpack(ConfigFiles.MULTIPLE_ENTRY_CONFIG)
     urls = bundle.get_urls()
     self.assertTrue(len(urls), 1)
     rendered = bundle.render_js()
     self.assertIn(urls['main']['js'][0], rendered)
     self.assertEqual(rendered, '<script src="' + urls['main']['js'][0] + '"></script>')
开发者ID:appelstroop,项目名称:python-webpack,代码行数:7,代码来源:test_bundles.py

示例9: test_bundle_create_a_file_with_contents

 def test_bundle_create_a_file_with_contents(self):
     bundle = webpack(ConfigFiles.BASIC_CONFIG)
     assets = bundle.get_assets()
     self.assertEqual(len(assets), 1)
     asset = assets[0]
     output = bundle.get_output()['main']['js'][0]
     self.assertEqual(asset, output)
     self.assertEqual(
         asset,
         os.path.join(
             settings.get_path_to_output_dir(),
             bundle.options['__python_webpack_hash__'],
             'bundle-{}.js'.format(bundle.data['stats']['hash'])
         )
     )
     self.assertTrue(os.path.exists(asset))
     self.assertEqual(
         bundle.get_urls()['main']['js'][0],
         (
             settings.STATIC_URL +
             settings.OUTPUT_DIR +
             '/' +
             bundle.options['__python_webpack_hash__'] +
             '/' +
             'bundle-{}.js'.format(bundle.data['stats']['hash'])
         ).replace('\\', '/'),
     )
     contents = read_file(asset)
     self.assertIn('__DJANGO_WEBPACK_ENTRY_TEST__', contents)
     self.assertIn('__DJANGO_WEBPACK_REQUIRE_TEST__', contents)
开发者ID:appelstroop,项目名称:python-webpack,代码行数:30,代码来源:test_bundles.py

示例10: test_bundle_can_render_multiple_bundles

 def test_bundle_can_render_multiple_bundles(self):
     bundle = webpack(PATH_TO_MULTIPLE_BUNDLES_CONFIG)
     urls = bundle.get_urls()
     self.assertTrue(len(urls), 2)
     rendered = bundle.render()
     for url in urls:
         self.assertIn(url, bundle.render())
     self.assertEqual(rendered, '<script src="' + urls[0] + '"></script><script src="' + urls[1] + '"></script>')
开发者ID:infrastructure-wixproducts,项目名称:python-webpack,代码行数:8,代码来源:test_bundles.py

示例11: test_webpack_bundles_can_return_urls_to_assets

 def test_webpack_bundles_can_return_urls_to_assets(self):
     bundle = webpack(ConfigFiles.BASIC_CONFIG)
     assets = bundle.get_assets()
     urls = bundle.get_urls()
     self.assertTrue(len(urls['main']['js']), 1)
     self.assertEqual(
         urls['main']['js'][0],
         '/static/webpack_assets/' + bundle.options['__python_webpack_hash__'] + '/' + os.path.basename(assets[0]),
     )
开发者ID:appelstroop,项目名称:python-webpack,代码行数:9,代码来源:test_bundles.py

示例12: test_bundle_can_expose_the_bundling_processes_output

 def test_bundle_can_expose_the_bundling_processes_output(self):
     bundle = webpack(PATH_TO_LIBRARY_CONFIG)
     stats = bundle.stats
     self.assertIsInstance(stats, dict)
     self.assertIn('webpackConfig', stats)
     self.assertIsInstance(stats['webpackConfig'], dict)
     self.assertIn('pathsToAssets', stats)
     self.assertIsInstance(stats['pathsToAssets'], dict)
     self.assertIn('urlsToAssets', stats)
     self.assertIsInstance(stats['urlsToAssets'], dict)
开发者ID:infrastructure-wixproducts,项目名称:python-webpack,代码行数:10,代码来源:test_bundles.py

示例13: test_bundle_can_handle_a_bundle_with_multiple_entries

 def test_bundle_can_handle_a_bundle_with_multiple_entries(self):
     bundle = webpack(ConfigFiles.MULTIPLE_ENTRY_CONFIG)
     assets = bundle.get_assets()
     self.assertTrue(len(assets), 1)
     contents = read_file(assets[0])
     self.assertIn('__DJANGO_WEBPACK_ENTRY_TEST__', contents)
     self.assertIn('__DJANGO_WEBPACK_ENTRY_ONE__', contents)
     self.assertIn('__DJANGO_WEBPACK_ENTRY_TWO__', contents)
     self.assertIn('__DJANGO_WEBPACK_ENTRY_THREE__', contents)
     self.assertIn('__DJANGO_WEBPACK_ENTRY_FOUR__', contents)
     self.assertIn('__DJANGO_WEBPACK_ENTRY_FIVE__', contents)
开发者ID:appelstroop,项目名称:python-webpack,代码行数:11,代码来源:test_bundles.py

示例14: test_default_context_can_be_extended

 def test_default_context_can_be_extended(self):
     bundle = webpack(
         ConfigFiles.LIBRARY_CONFIG,
         context={
             'foo': 'bar'
         },
     )
     self.assertIn('default_context', bundle.data['buildOptions']['context'])
     self.assertEqual(bundle.data['buildOptions']['context']['default_context'], 'test')
     self.assertIn('foo', bundle.data['buildOptions']['context'])
     self.assertEqual(bundle.data['buildOptions']['context']['foo'], 'bar')
开发者ID:appelstroop,项目名称:python-webpack,代码行数:11,代码来源:test_bundles.py

示例15: test_bundle_can_expose_its_output_options

 def test_bundle_can_expose_its_output_options(self):
     bundle = webpack(ConfigFiles.BASIC_CONFIG)
     output_options = bundle.get_output_options()
     self.assertEqual(output_options['filename'], 'bundle-[hash].js')
     self.assertEqual(
         output_options['path'],
         os.path.join(
             settings.STATIC_ROOT,
             settings.OUTPUT_DIR,
             bundle.options['__python_webpack_hash__']
         )
     )
开发者ID:appelstroop,项目名称:python-webpack,代码行数:12,代码来源:test_bundles.py


注:本文中的webpack.compiler.webpack函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。