def configure_webpack(app): pkg_path = os.path.dirname(get_root_path('indico')) project = WebpackBundleProject(pkg_path) app.config['WEBPACKEXT_PROJECT'] = project app.config['WEBPACKEXT_MANIFEST_LOADER'] = IndicoManifestLoader app.config['WEBPACKEXT_MANIFEST_PATH'] = os.path.join( 'dist', 'manifest.json')
def test_bundleproject(builddir, bundledir, destdir): """Test bundle project.""" entry = {'app': './index.js'} bundle = WebpackBundle(bundledir, entry=entry, dependencies={ 'lodash': '~4', }) project = WebpackBundleProject( destdir, project_template=builddir, bundles=(x for x in [bundle]), # Test for iterator evaluation config={ 'test': True, 'entry': False }, ) assert project.bundles == [bundle] assert project.entry == entry assert project.config == {'entry': entry, 'test': True} assert project.dependencies == { 'dependencies': { 'lodash': '~4', }, 'devDependencies': {}, 'peerDependencies': {} } project.create() # Assert generated files. paths = ['config.json', 'index.js', 'package.json', 'webpack.config.js'] distpaths = [ 'dist/bundle.js', 'node_modules', ] for p in paths: assert exists(join(project.project_path, p)) for p in distpaths: assert not exists(join(project.project_path, p)) # Assert generated package.json package_json = json_from_file(project.npmpkg.package_json_path) # Coming from bundle assert package_json['dependencies'] == {'lodash': '~4'} # Coming from source package.json assert package_json['devDependencies'] == {'lodash': '~4'} assert package_json['peerDependencies'] == {} # Build project and see that it works. project.install() project.build() for p in distpaths: assert exists(join(project.project_path, p))
def test_bundle_duplicated_entries(builddir, bundledir, bundledir2, destdir): """Test bundles with duplicated entries.""" bundle1 = WebpackBundle(bundledir, entry={'app': './index.js'}, dependencies={ 'lodash': '~4', }) bundle2 = WebpackBundle(bundledir2, entry={'app': './main.js'}, dependencies={ 'lodash': '~3', }) project = WebpackBundleProject( working_dir=destdir, project_template_dir=builddir, bundles=(x for x in [bundle1, bundle2]), config={ 'test': True, 'entry': False }, ) project.create()